blob: 7167e44160649ef0b1e1138348cc8949f4c7173a [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");
Rambo Wang04d1ace2022-02-23 13:41:02 -08006746 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6747 }
6748
6749 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006750 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006751 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006752 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006753 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006754 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6755 Phone phone = PhoneFactory.getPhone(phoneId);
6756 if (phone == null) {
6757 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006758 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006759 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6760 if (cpt == null) {
6761 continue;
6762 }
6763 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006764 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6765 break;
6766 }
6767 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006768 return result;
Junda Liu29340342014-07-10 15:23:27 -07006769 }
Derek Tan89e89d42014-07-08 17:00:10 -07006770
6771 @Override
Junda Liue64de782015-04-16 17:19:16 -07006772 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006773 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006774 Phone phone = PhoneFactory.getPhone(phoneId);
6775 if (phone == null) {
6776 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006777 }
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006778 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6779 if (cpt == null) {
6780 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006781 }
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006782 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006783 }
6784
Amith Yamasani6e118872016-02-19 12:53:51 -08006785 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006786 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006787 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006788 Phone phone = PhoneFactory.getPhone(phoneId);
6789 if (phone == null) {
6790 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006791 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006792 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6793 if (cpt == null) {
6794 return Collections.emptyList();
6795 }
6796 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006797 }
6798
chen xuf7e9fe82019-05-09 19:31:02 -07006799 @Override
6800 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006801 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006802 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006803 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006804 try {
6805 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6806 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6807 }
6808 } finally {
6809 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006810 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006811 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006812 }
6813
Rambo Wang9b91ffd2022-03-15 16:54:17 -07006814 @Override
6815 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6816 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6817
6818 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6819 if (phone == null) {
6820 return null;
6821 }
6822 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6823 if (cpt == null) {
6824 return null;
6825 }
6826 return cpt.getCarrierServicePackageName();
6827 }
6828
Wink Savilleb564aae2014-10-23 10:18:09 -07006829 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006830 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006831 UiccPort port = phone == null ? null : phone.getUiccPort();
6832 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006833 return null;
6834 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006835 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006836 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006837 return null;
6838 }
6839 return iccId;
6840 }
6841
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006842 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006843 public void setCallComposerStatus(int subId, int status) {
6844 enforceModifyPermission();
6845
6846 final long identity = Binder.clearCallingIdentity();
6847 try {
6848 Phone phone = getPhone(subId);
6849 if (phone != null) {
6850 Phone defaultPhone = phone.getImsPhone();
6851 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6852 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6853 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006854 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6855 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006856 }
6857 }
Shuo Qian284ae752020-12-22 19:10:14 -08006858 } catch (ImsException e) {
6859 throw new ServiceSpecificException(e.getCode());
6860 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006861 Binder.restoreCallingIdentity(identity);
6862 }
6863 }
6864
6865 @Override
6866 public int getCallComposerStatus(int subId) {
6867 enforceReadPrivilegedPermission("getCallComposerStatus");
6868
6869 final long identity = Binder.clearCallingIdentity();
6870 try {
6871 Phone phone = getPhone(subId);
6872 if (phone != null) {
6873 Phone defaultPhone = phone.getImsPhone();
6874 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6875 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6876 return imsPhone.getCallComposerStatus();
6877 }
6878 }
6879 } finally {
6880 Binder.restoreCallingIdentity(identity);
6881 }
6882 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6883 }
6884
6885 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006886 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6887 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006888 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006889 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891 final long identity = Binder.clearCallingIdentity();
6892 try {
6893 final String iccId = getIccId(subId);
6894 final Phone phone = getPhone(subId);
6895 if (phone == null) {
6896 return false;
6897 }
6898 final String subscriberId = phone.getSubscriberId();
6899
6900 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006901 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902 + subscriberId + " to " + number);
6903 }
6904
6905 if (TextUtils.isEmpty(iccId)) {
6906 return false;
6907 }
6908
6909 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6910
6911 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6912 if (alphaTag == null) {
6913 editor.remove(alphaTagPrefKey);
6914 } else {
6915 editor.putString(alphaTagPrefKey, alphaTag);
6916 }
6917
6918 // Record both the line number and IMSI for this ICCID, since we need to
6919 // track all merged IMSIs based on line number
6920 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6921 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6922 if (number == null) {
6923 editor.remove(numberPrefKey);
6924 editor.remove(subscriberPrefKey);
6925 } else {
6926 editor.putString(numberPrefKey, number);
6927 editor.putString(subscriberPrefKey, subscriberId);
6928 }
6929
6930 editor.commit();
6931 return true;
6932 } finally {
6933 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006934 }
Derek Tan7226c842014-07-02 17:42:23 -07006935 }
6936
6937 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006938 public String getLine1NumberForDisplay(int subId, String callingPackage,
6939 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006940 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006941 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006942 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006943 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006944 return null;
6945 }
Derek Tan97ebb422014-09-05 16:55:38 -07006946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947 final long identity = Binder.clearCallingIdentity();
6948 try {
6949 String iccId = getIccId(subId);
6950 if (iccId != null) {
6951 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6952 if (DBG_MERGE) {
6953 log("getLine1NumberForDisplay returning "
6954 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6955 }
6956 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006958 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6959 return null;
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006962 }
Derek Tan7226c842014-07-02 17:42:23 -07006963 }
6964
6965 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006966 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6967 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006968 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006969 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006970 return null;
6971 }
Derek Tan97ebb422014-09-05 16:55:38 -07006972
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006973 final long identity = Binder.clearCallingIdentity();
6974 try {
6975 String iccId = getIccId(subId);
6976 if (iccId != null) {
6977 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6978 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6979 }
6980 return null;
6981 } finally {
6982 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006983 }
Derek Tan7226c842014-07-02 17:42:23 -07006984 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006985
6986 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006987 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6988 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006989 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6990 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006992 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006993 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006994 return null;
6995 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006996
Jordan Liub49b04b2019-05-06 14:45:15 -07006997 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6998 // the process, where TelephonyManager was instantiated.
6999 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007000 final long identity = Binder.clearCallingIdentity();
7001 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007002 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 final TelephonyManager tele = TelephonyManager.from(context);
7004 final SubscriptionManager sub = SubscriptionManager.from(context);
7005
7006 // Figure out what subscribers are currently active
7007 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008
Jordan Liub49b04b2019-05-06 14:45:15 -07007009 // Only consider subs which match the current subId
7010 // This logic can be simplified. See b/131189269 for progress.
7011 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007012 activeSubscriberIds.add(tele.getSubscriberId(subId));
7013 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014
7015 // First pass, find a number override for an active subscriber
7016 String mergeNumber = null;
7017 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7018 for (String key : prefs.keySet()) {
7019 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7020 final String subscriberId = (String) prefs.get(key);
7021 if (activeSubscriberIds.contains(subscriberId)) {
7022 final String iccId = key.substring(
7023 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7024 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7025 mergeNumber = (String) prefs.get(numberKey);
7026 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007027 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007028 + " for active subscriber " + subscriberId);
7029 }
7030 if (!TextUtils.isEmpty(mergeNumber)) {
7031 break;
7032 }
7033 }
7034 }
7035 }
7036
7037 // Shortcut when no active merged subscribers
7038 if (TextUtils.isEmpty(mergeNumber)) {
7039 return null;
7040 }
7041
7042 // Second pass, find all subscribers under that line override
7043 final ArraySet<String> result = new ArraySet<>();
7044 for (String key : prefs.keySet()) {
7045 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7046 final String number = (String) prefs.get(key);
7047 if (mergeNumber.equals(number)) {
7048 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7049 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7050 final String subscriberId = (String) prefs.get(subscriberKey);
7051 if (!TextUtils.isEmpty(subscriberId)) {
7052 result.add(subscriberId);
7053 }
7054 }
7055 }
7056 }
7057
7058 final String[] resultArray = result.toArray(new String[result.size()]);
7059 Arrays.sort(resultArray);
7060 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007061 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7063 }
7064 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007065 } finally {
7066 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007067 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007068 }
7069
7070 @Override
zoey chen38003472019-12-13 17:16:31 +08007071 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7072 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007073
7074 final long identity = Binder.clearCallingIdentity();
7075 try {
7076 final TelephonyManager telephonyManager = mApp.getSystemService(
7077 TelephonyManager.class);
7078 String subscriberId = telephonyManager.getSubscriberId(subId);
7079 if (subscriberId == null) {
7080 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007081 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007082 + subId);
7083 }
7084 return null;
7085 }
7086
7087 final SubscriptionInfo info = SubscriptionController.getInstance()
7088 .getSubscriptionInfo(subId);
7089 final ParcelUuid groupUuid = info.getGroupUuid();
7090 // If it doesn't belong to any group, return just subscriberId of itself.
7091 if (groupUuid == null) {
7092 return new String[]{subscriberId};
7093 }
7094
7095 // Get all subscriberIds from the group.
7096 final List<String> mergedSubscriberIds = new ArrayList<>();
7097 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007098 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007099 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007100 for (SubscriptionInfo subInfo : groupInfos) {
7101 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7102 if (subscriberId != null) {
7103 mergedSubscriberIds.add(subscriberId);
7104 }
7105 }
7106
7107 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7108 } finally {
7109 Binder.restoreCallingIdentity(identity);
7110
7111 }
7112 }
7113
7114 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007115 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007116 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007117 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118
7119 final long identity = Binder.clearCallingIdentity();
7120 try {
7121 final Phone phone = getPhone(subId);
7122 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7123 } finally {
7124 Binder.restoreCallingIdentity(identity);
7125 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007126 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007127
7128 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007129 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007130 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7131 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007132 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7133 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134
7135 final long identity = Binder.clearCallingIdentity();
7136 try {
7137 final Phone phone = getPhone(subId);
7138 if (phone == null) {
7139 return false;
7140 }
7141 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7142 cdmaNonRoamingList);
7143 } finally {
7144 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007145 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007146 }
7147
7148 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007149 @Deprecated
7150 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7151 enforceModifyPermission();
7152
7153 int returnValue = 0;
7154 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007155 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007156 if(result.exception == null) {
7157 if (result.result != null) {
7158 byte[] responseData = (byte[])(result.result);
7159 if(responseData.length > oemResp.length) {
7160 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7161 responseData.length + "bytes. Buffer Size is " +
7162 oemResp.length + "bytes.");
7163 }
7164 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7165 returnValue = responseData.length;
7166 }
7167 } else {
7168 CommandException ex = (CommandException) result.exception;
7169 returnValue = ex.getCommandError().ordinal();
7170 if(returnValue > 0) returnValue *= -1;
7171 }
7172 } catch (RuntimeException e) {
7173 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7174 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7175 if(returnValue > 0) returnValue *= -1;
7176 }
7177
7178 return returnValue;
7179 }
7180
7181 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007182 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007183 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007184 try {
7185 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007186 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007187 mApp, phone.getSubId(), "getRadioAccessFamily");
7188 } catch (SecurityException e) {
7189 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7190 throw e;
7191 }
chen xub97461a2018-10-26 14:17:57 -07007192 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007193 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007194 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007195 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196 final long identity = Binder.clearCallingIdentity();
7197 try {
chen xub97461a2018-10-26 14:17:57 -07007198 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007199 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007200 mApp, phone.getSubId(), "getRadioAccessFamily");
7201 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 } finally {
7203 Binder.restoreCallingIdentity(identity);
7204 }
chen xub97461a2018-10-26 14:17:57 -07007205 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007206 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007207
7208 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007209 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007210 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007211 try {
7212 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7213 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007214 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007215 }
7216 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007217 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007218 }
7219 RoleManager rm = mApp.getSystemService(RoleManager.class);
7220 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7221 if (!dialerRoleHolders.contains(callingPackage)) {
7222 throw new SecurityException("App must be the dialer role holder to"
7223 + " upload a call composer pic");
7224 }
7225
7226 Executors.newSingleThreadExecutor().execute(() -> {
7227 ByteArrayOutputStream output = new ByteArrayOutputStream(
7228 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7229 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7230 boolean readUntilEnd = false;
7231 int totalBytesRead = 0;
7232 byte[] buffer = new byte[16 * 1024];
7233 while (true) {
7234 int numRead;
7235 try {
7236 numRead = input.read(buffer);
7237 } catch (IOException e) {
7238 try {
7239 fd.checkError();
7240 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7241 null);
7242 } catch (IOException e1) {
7243 // This means that the other side closed explicitly with an error. If this
7244 // happens, log and ignore.
7245 loge("Remote end of call composer picture pipe closed: " + e1);
7246 }
7247 break;
7248 }
7249 if (numRead == -1) {
7250 readUntilEnd = true;
7251 break;
7252 }
7253 totalBytesRead += numRead;
7254 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7255 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7256 try {
7257 input.close();
7258 } catch (IOException e) {
7259 // ignore
7260 }
7261 break;
7262 }
7263 output.write(buffer, 0, numRead);
7264 }
7265 // Generally, the remote end will close the file descriptors. The only case where we
7266 // close is above, where the picture size is too big.
7267
7268 try {
7269 fd.checkError();
7270 } catch (IOException e) {
7271 loge("Remote end for call composer closed with an error: " + e);
7272 return;
7273 }
7274
Hall Liuaa4211e2021-01-20 15:43:39 -08007275 if (!readUntilEnd) {
7276 loge("Did not finish reading entire image; aborting");
7277 return;
7278 }
Hall Liu82694d52020-12-11 18:22:04 -08007279
Hall Liuaa4211e2021-01-20 15:43:39 -08007280 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7281 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7282 new CallComposerPictureTransfer.Factory() {},
7283 imageData,
7284 (result) -> {
7285 if (result.first != null) {
7286 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7287 Bundle outputResult = new Bundle();
7288 outputResult.putParcelable(
7289 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7290 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7291 outputResult);
7292 } else {
7293 callback.send(result.second, null);
7294 }
7295 }
7296 );
Hall Liu82694d52020-12-11 18:22:04 -08007297 });
7298 }
7299
7300 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007301 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007302 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007303 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007304
7305 final long identity = Binder.clearCallingIdentity();
7306 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007307 ImsManager.getInstance(defaultPhone.getContext(),
7308 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007309 } finally {
7310 Binder.restoreCallingIdentity(identity);
7311 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007312 }
7313
7314 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007315 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007316 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7318 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007319 return false;
7320 }
Svet Ganovb320e182015-04-16 12:30:10 -07007321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007322 final long identity = Binder.clearCallingIdentity();
7323 try {
7324 // Check the user preference and the system-level IMS setting. Even if the user has
7325 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7326 // In the long run, we may instead need to check if there exists a connection service
7327 // which can support video calling.
7328 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007329 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 return imsManager.isVtEnabledByPlatform()
7331 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7332 && imsManager.isVtEnabledByUser();
7333 } finally {
7334 Binder.restoreCallingIdentity(identity);
7335 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007336 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007337
Andrew Leea1239f22015-03-02 17:44:07 -08007338 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007339 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7340 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007342 mApp, subId, callingPackage, callingFeatureId,
7343 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344 return false;
7345 }
7346
7347 final long identity = Binder.clearCallingIdentity();
7348 try {
7349 CarrierConfigManager configManager =
7350 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007351 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007352 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7353 } finally {
7354 Binder.restoreCallingIdentity(identity);
7355 }
Andrew Leea1239f22015-03-02 17:44:07 -08007356 }
7357
7358 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007359 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007361 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007362 return false;
7363 }
7364
7365 final long identity = Binder.clearCallingIdentity();
7366 try {
7367 CarrierConfigManager configManager =
7368 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007369 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007370 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7371 } finally {
7372 Binder.restoreCallingIdentity(identity);
7373 }
Andrew Leea1239f22015-03-02 17:44:07 -08007374 }
7375
Andrew Lee9431b832015-03-09 18:46:45 -07007376 @Override
7377 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007378 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007379 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007380 }
7381
7382 @Override
7383 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384 final long identity = Binder.clearCallingIdentity();
7385 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007386 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 } finally {
7388 Binder.restoreCallingIdentity(identity);
7389 }
Andrew Lee9431b832015-03-09 18:46:45 -07007390 }
7391
Hall Liuf6668912018-10-31 17:05:23 -07007392 /**
7393 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7394 * support for the feature and device firmware support.
7395 *
7396 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7397 */
7398 @Override
7399 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007401 final Phone phone = getPhone(subscriptionId);
7402 if (phone == null) {
7403 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7404 return false;
7405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007407 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007408 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7409 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007410 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411 return isCarrierSupported && isDeviceSupported;
7412 } finally {
7413 Binder.restoreCallingIdentity(identity);
7414 }
Hall Liu98187582018-01-22 19:15:32 -08007415 }
7416
Hall Liuf6668912018-10-31 17:05:23 -07007417 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007418 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7419 * RTT setting, will return true if the device and carrier both support RTT.
7420 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007421 */
7422 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007423 final long identity = Binder.clearCallingIdentity();
7424 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007425 boolean isRttSupported = isRttSupported(subscriptionId);
7426 boolean isUserRttSettingOn = Settings.Secure.getInt(
7427 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7428 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7429 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7430 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431 } finally {
7432 Binder.restoreCallingIdentity(identity);
7433 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007434 }
7435
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007436 @Deprecated
7437 @Override
7438 public String getDeviceId(String callingPackage) {
7439 return getDeviceIdWithFeature(callingPackage, null);
7440 }
7441
Sanket Padawe7310cc72015-01-14 09:53:20 -08007442 /**
7443 * Returns the unique device ID of phone, for example, the IMEI for
7444 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7445 *
7446 * <p>Requires Permission:
7447 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7448 */
7449 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007450 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007451 try {
7452 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7453 } catch (SecurityException se) {
7454 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7455 throw new SecurityException("Package " + callingPackage + " does not belong to "
7456 + Binder.getCallingUid());
7457 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007458 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007459 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007460 return null;
7461 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007462 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007463 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007464 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007465 return null;
7466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467
7468 final long identity = Binder.clearCallingIdentity();
7469 try {
7470 return phone.getDeviceId();
7471 } finally {
7472 Binder.restoreCallingIdentity(identity);
7473 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007474 }
7475
Ping Sunc67b7c22016-03-02 19:16:45 +08007476 /**
7477 * {@hide}
7478 * Returns the IMS Registration Status on a particular subid
7479 *
7480 * @param subId
7481 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007482 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007483 Phone phone = getPhone(subId);
7484 if (phone != null) {
7485 return phone.isImsRegistered();
7486 } else {
7487 return false;
7488 }
7489 }
7490
Santos Cordon7a1885b2015-02-03 11:15:19 -08007491 @Override
7492 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 final long identity = Binder.clearCallingIdentity();
7494 try {
7495 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7496 } finally {
7497 Binder.restoreCallingIdentity(identity);
7498 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007499 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007500
Tyler Gunnf70ed162019-04-03 15:28:53 -07007501 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007502 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007503 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007504 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007505 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007506 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7507 }
7508 final long identity = Binder.clearCallingIdentity();
7509 try {
7510 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7511 } finally {
7512 Binder.restoreCallingIdentity(identity);
7513 }
7514 }
7515
7516 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007517 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007518 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007519 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007520 mApp,
7521 subscriptionId,
7522 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007523 final long identity = Binder.clearCallingIdentity();
7524 try {
7525 Phone phone = getPhone(subscriptionId);
7526 if (phone == null) {
7527 return null;
7528 }
7529 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7530 } finally {
7531 Binder.restoreCallingIdentity(identity);
7532 }
7533 }
7534
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007535 /**
7536 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007537 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007538 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 final long identity = Binder.clearCallingIdentity();
7540 try {
7541 Phone phone = getPhone(subId);
7542 if (phone != null) {
7543 return phone.isWifiCallingEnabled();
7544 } else {
7545 return false;
7546 }
7547 } finally {
7548 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007549 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007550 }
7551
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007552 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007553 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007554 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007555 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 final long identity = Binder.clearCallingIdentity();
7557 try {
7558 Phone phone = getPhone(subId);
7559 if (phone != null) {
7560 return phone.isVideoEnabled();
7561 } else {
7562 return false;
7563 }
7564 } finally {
7565 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007566 }
7567 }
7568
7569 /**
7570 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7571 * defined in {@link ImsRegistrationImplBase}.
7572 */
7573 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007574 final long identity = Binder.clearCallingIdentity();
7575 try {
7576 Phone phone = getPhone(subId);
7577 if (phone != null) {
7578 return phone.getImsRegistrationTech();
7579 } else {
7580 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7581 }
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007584 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007585 }
7586
Stuart Scott8eef64f2015-04-08 15:13:54 -07007587 @Override
7588 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007589 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007590 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7591 return;
7592 }
Kai Shif70f46f2021-03-03 13:59:46 -08007593 Phone defaultPhone = getDefaultPhone();
7594 if (defaultPhone != null) {
7595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7596 mApp, getDefaultPhone().getSubId(), "factoryReset");
7597 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007598 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007599
Svet Ganovcc087f82015-05-12 20:35:54 -07007600 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007601 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7602 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007603 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007604 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007605 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007606 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007607 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007608 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007609 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007610 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007611 // There has been issues when Sms raw table somehow stores orphan
7612 // fragments. They lead to garbled message when new fragments come
7613 // in and combined with those stale ones. In case this happens again,
7614 // user can reset all network settings which will clean up this table.
7615 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007616 // Clean up IMS settings as well here.
7617 int slotId = getSlotIndex(subId);
7618 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7619 ImsManager.getInstance(mApp, slotId).factoryReset();
7620 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007621
Kai Shif70f46f2021-03-03 13:59:46 -08007622 if (defaultPhone == null) {
7623 return;
7624 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007625 // Erase modem config if erase modem on network setting is enabled.
7626 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7627 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7628 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007629 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007630 }
Kai Shif70f46f2021-03-03 13:59:46 -08007631
7632 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007633 } finally {
7634 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007635 }
7636 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007637
SongFerngWangfd89b102021-05-27 22:44:54 +08007638 @VisibleForTesting
7639 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7640 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7641 return;
7642 }
7643 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7644 RILConstants.PREFERRED_NETWORK_MODE);
7645 SubscriptionManager.setSubscriptionProperty(subId,
7646 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7647 "user=" + defaultNetworkType);
7648 phone.loadAllowedNetworksFromSubscriptionDatabase();
7649 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7650 defaultNetworkType, null);
7651 }
7652
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007653 private void cleanUpSmsRawTable(Context context) {
7654 ContentResolver resolver = context.getContentResolver();
7655 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7656 resolver.delete(uri, null, null);
7657 }
7658
Narayan Kamath1c496c22015-04-16 14:40:19 +01007659 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007660 public String getSimLocaleForSubscriber(int subId) {
7661 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7662 final Phone phone = getPhone(subId);
7663 if (phone == null) {
7664 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007665 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007666 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667 final long identity = Binder.clearCallingIdentity();
7668 try {
chen xu5d3637b2019-01-21 23:31:38 -08007669 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007670 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007671 if (info == null) {
7672 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7673 return null;
7674 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 // Try and fetch the locale from the carrier properties or from the SIM language
7676 // preferences (EF-PL and EF-LI)...
7677 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007679 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7680 if (localeFromDefaultSim != null) {
7681 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7682 if (DBG) log("Using locale from subId: " + subId + " locale: "
7683 + localeFromDefaultSim);
7684 return localeFromDefaultSim.toLanguageTag();
7685 } else {
7686 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007687 }
7688 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 // The SIM language preferences only store a language (e.g. fr = French), not an
7691 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7692 // the SIM and carrier preferences does not include a country we add the country
7693 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007694 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007696 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007697 return mccLocale.toLanguageTag();
7698 }
7699
7700 if (DBG) log("No locale found - returning null");
7701 return null;
7702 } finally {
7703 Binder.restoreCallingIdentity(identity);
7704 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007705 }
7706
7707 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007708 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007709 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007710 }
7711
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007712 /**
7713 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7714 */
7715 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007716 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007717 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007718 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007719
Chenjie Yu1ba97252018-01-11 18:16:20 -08007720 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007721 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007722
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007723 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007724 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7725 * representing the state of the modem.
7726 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007727 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7728 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007729 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007730 */
7731 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007732 public void requestModemActivityInfo(ResultReceiver result) {
7733 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007734 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735
7736 final long identity = Binder.clearCallingIdentity();
7737 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007738 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007739 } finally {
7740 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007741 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007742 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007743
Siddharth Rayb8114062018-06-17 15:02:38 -07007744 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7745 // less than total activity duration.
7746 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7747 if (info == null) {
7748 return false;
7749 }
7750 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007751 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7752 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7753
Siddharth Rayb8114062018-06-17 15:02:38 -07007754 return (info.isValid()
7755 && (info.getSleepTimeMillis() <= activityDurationMs)
7756 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007757 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007758 && (totalTxTimeMs <= activityDurationMs));
7759 }
7760
Jack Yu85bd38a2015-11-09 11:34:32 -08007761 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007762 * Returns the service state information on specified subscription.
7763 */
7764 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007765 public ServiceState getServiceStateForSubscriber(int subId,
7766 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7767 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007769 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007770 return null;
7771 }
7772
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007773 boolean hasFinePermission = false;
7774 boolean hasCoarsePermission = false;
7775 if (!renounceFineLocationAccess) {
7776 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7777 LocationAccessPolicy.checkLocationPermission(mApp,
7778 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7779 .setCallingPackage(callingPackage)
7780 .setCallingFeatureId(callingFeatureId)
7781 .setCallingPid(Binder.getCallingPid())
7782 .setCallingUid(Binder.getCallingUid())
7783 .setMethod("getServiceStateForSubscriber")
7784 .setLogAsInfo(true)
7785 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7786 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7787 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7788 .build());
7789 hasFinePermission =
7790 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7791 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007792
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007793 if (!renounceCoarseLocationAccess) {
7794 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7795 LocationAccessPolicy.checkLocationPermission(mApp,
7796 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7797 .setCallingPackage(callingPackage)
7798 .setCallingFeatureId(callingFeatureId)
7799 .setCallingPid(Binder.getCallingPid())
7800 .setCallingUid(Binder.getCallingUid())
7801 .setMethod("getServiceStateForSubscriber")
7802 .setLogAsInfo(true)
7803 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7804 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7805 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7806 .build());
7807 hasCoarsePermission =
7808 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7809 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007810
Jack Yu479f40e2020-10-27 21:29:25 -07007811 final Phone phone = getPhone(subId);
7812 if (phone == null) {
7813 return null;
7814 }
7815
Jordan Liu0f2bc442020-11-18 16:47:37 -08007816 final long identity = Binder.clearCallingIdentity();
7817
Jack Yu479f40e2020-10-27 21:29:25 -07007818 boolean isCallingPackageDataService = phone.getDataServicePackages()
7819 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007821 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7822 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7823 Rlog.d(LOG_TAG,
7824 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7825 return null;
7826 }
7827
Hall Liuf19c44f2018-11-27 14:38:17 -08007828 ServiceState ss = phone.getServiceState();
7829
7830 // Scrub out the location info in ServiceState depending on what level of access
7831 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007832 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007833 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7834 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007835 } finally {
7836 Binder.restoreCallingIdentity(identity);
7837 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007838 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007839
7840 /**
7841 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7842 *
7843 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7844 * voicemail ringtone.
7845 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7846 * PhoneAccount.
7847 */
7848 @Override
7849 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 final long identity = Binder.clearCallingIdentity();
7851 try {
7852 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7853 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007854 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007855 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7858 } finally {
7859 Binder.restoreCallingIdentity(identity);
7860 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007861 }
7862
7863 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007864 * Sets the per-account voicemail ringtone.
7865 *
7866 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7867 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7868 *
7869 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7870 * voicemail ringtone.
7871 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7872 * PhoneAccount.
7873 */
7874 @Override
7875 public void setVoicemailRingtoneUri(String callingPackage,
7876 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007877 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007878 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007879 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7880 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7882 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7883 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885
7886 final long identity = Binder.clearCallingIdentity();
7887 try {
7888 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7889 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007890 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891 }
7892 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7893 } finally {
7894 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007895 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007896 }
7897
7898 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007899 * Returns whether vibration is set for voicemail notification in Phone settings.
7900 *
7901 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7902 * voicemail vibration setting.
7903 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7904 */
7905 @Override
7906 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907 final long identity = Binder.clearCallingIdentity();
7908 try {
7909 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7910 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007911 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007918 }
7919
Youhan Wange64578a2016-05-02 15:32:42 -07007920 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007921 * Sets the per-account voicemail vibration.
7922 *
7923 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7924 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7925 *
7926 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7927 * voicemail vibration setting.
7928 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7929 * specific PhoneAccount.
7930 */
7931 @Override
7932 public void setVoicemailVibrationEnabled(String callingPackage,
7933 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007934 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007935 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007936 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7937 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7939 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7940 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007941 }
7942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007943 final long identity = Binder.clearCallingIdentity();
7944 try {
7945 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7946 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007947 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948 }
7949 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7950 } finally {
7951 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007952 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007953 }
7954
7955 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007956 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7957 *
7958 * @throws SecurityException if the caller does not have the required permission
7959 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007960 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007961 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007962 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007963 }
7964
7965 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007966 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7967 * permission.
7968 *
7969 * @throws SecurityException if the caller does not have the required permission
7970 */
7971 private void enforceSendSmsPermission() {
7972 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7973 }
7974
7975 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007976 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007977 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007978 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007979 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007980 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007981 final long identity = Binder.clearCallingIdentity();
7982 try {
7983 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007984 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985 if (componentName == null) {
7986 throw new SecurityException(
7987 "Caller not current active visual voicemail package[null]");
7988 }
7989 String vvmPackage = componentName.getPackageName();
7990 if (!callingPackage.equals(vvmPackage)) {
7991 throw new SecurityException("Caller not current active visual voicemail package["
7992 + vvmPackage + "]");
7993 }
7994 } finally {
7995 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007996 }
7997 }
7998
7999 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008000 * Return the application ID for the app type.
8001 *
8002 * @param subId the subscription ID that this request applies to.
8003 * @param appType the uicc app type.
8004 * @return Application ID for specificied app type, or null if no uicc.
8005 */
8006 @Override
8007 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008008 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008009 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010
8011 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008012 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 if (phone == null) {
8014 return null;
8015 }
8016 String aid = null;
8017 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008018 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008019 .getApplicationByType(appType).getAid();
8020 } catch (Exception e) {
8021 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8022 }
8023 return aid;
8024 } finally {
8025 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008026 }
Youhan Wange64578a2016-05-02 15:32:42 -07008027 }
8028
Youhan Wang4001d252016-05-11 10:29:41 -07008029 /**
8030 * Return the Electronic Serial Number.
8031 *
8032 * @param subId the subscription ID that this request applies to.
8033 * @return ESN or null if error.
8034 */
8035 @Override
8036 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008037 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008038 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008039
8040 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008041 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008042 if (phone == null) {
8043 return null;
8044 }
8045 String esn = null;
8046 try {
8047 esn = phone.getEsn();
8048 } catch (Exception e) {
8049 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8050 }
8051 return esn;
8052 } finally {
8053 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008054 }
Youhan Wang4001d252016-05-11 10:29:41 -07008055 }
8056
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008057 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008058 * Return the Preferred Roaming List Version.
8059 *
8060 * @param subId the subscription ID that this request applies to.
8061 * @return PRLVersion or null if error.
8062 */
8063 @Override
8064 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008065 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008066 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008067
8068 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008069 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 if (phone == null) {
8071 return null;
8072 }
8073 String cdmaPrlVersion = null;
8074 try {
8075 cdmaPrlVersion = phone.getCdmaPrlVersion();
8076 } catch (Exception e) {
8077 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8078 }
8079 return cdmaPrlVersion;
8080 } finally {
8081 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008082 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008083 }
8084
8085 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008086 * Get snapshot of Telephony histograms
8087 * @return List of Telephony histograms
8088 * @hide
8089 */
8090 @Override
8091 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8093 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008094
8095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 return RIL.getTelephonyRILTimingHistograms();
8098 } finally {
8099 Binder.restoreCallingIdentity(identity);
8100 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008101 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008102
8103 /**
8104 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008105 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8106 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008107 * Require system privileges. In the future we may add this to carrier APIs.
8108 *
Michele Berionne482f8202018-11-27 18:57:59 -08008109 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008110 */
8111 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008112 @TelephonyManager.SetCarrierRestrictionResult
8113 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008114 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008115 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008116
Michele Berionne482f8202018-11-27 18:57:59 -08008117 if (carrierRestrictionRules == null) {
8118 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008119 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121 final long identity = Binder.clearCallingIdentity();
8122 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008123 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008124 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125 } finally {
8126 Binder.restoreCallingIdentity(identity);
8127 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008128 }
8129
8130 /**
8131 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008132 * Get the allowed carrier list and the excluded carrier list, including the priority between
8133 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008134 * Require system privileges. In the future we may add this to carrier APIs.
8135 *
Michele Berionne482f8202018-11-27 18:57:59 -08008136 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008137 */
8138 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008139 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008140 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008141 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008142
8143 final long identity = Binder.clearCallingIdentity();
8144 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008145 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8146 if (response instanceof CarrierRestrictionRules) {
8147 return (CarrierRestrictionRules) response;
8148 }
8149 // Response is an Exception of some kind,
8150 // which is signalled to the user as a NULL retval
8151 return null;
8152 } catch (Exception e) {
8153 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8154 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155 } finally {
8156 Binder.restoreCallingIdentity(identity);
8157 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008158 }
8159
fionaxu59545b42016-05-25 15:53:37 -07008160 /**
fionaxu59545b42016-05-25 15:53:37 -07008161 * Action set from carrier signalling broadcast receivers to enable/disable radio
8162 * @param subId the subscription ID that this action applies to.
8163 * @param enabled control enable or disable radio.
8164 * {@hide}
8165 */
8166 @Override
8167 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8168 enforceModifyPermission();
8169 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170
8171 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008172 if (phone == null) {
8173 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8174 return;
8175 }
8176 try {
8177 phone.carrierActionSetRadioEnabled(enabled);
8178 } catch (Exception e) {
8179 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180 } finally {
8181 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008182 }
8183 }
8184
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008185 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008186 * Enable or disable Voice over NR (VoNR)
8187 * @param subId the subscription ID that this action applies to.
8188 * @param enabled enable or disable VoNR.
8189 * @return operation result.
8190 */
8191 @Override
8192 public int setVoNrEnabled(int subId, boolean enabled) {
8193 enforceModifyPermission();
8194 final Phone phone = getPhone(subId);
8195
8196 final long identity = Binder.clearCallingIdentity();
8197 if (phone == null) {
8198 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8199 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8200 }
8201
8202 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8203 try {
8204 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8205 workSource);
8206 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008207
8208 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8209 if (DBG) {
8210 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8211 }
8212 SubscriptionManager.setSubscriptionProperty(
8213 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8214 (enabled ? "1" : "0"));
8215 }
8216
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008217 return result;
8218 } finally {
8219 Binder.restoreCallingIdentity(identity);
8220 }
8221 }
8222
8223 /**
8224 * Is voice over NR enabled
8225 * @return true if VoNR is enabled else false
8226 */
8227 @Override
8228 public boolean isVoNrEnabled(int subId) {
8229 enforceReadPrivilegedPermission("isVoNrEnabled");
8230 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8231 final long identity = Binder.clearCallingIdentity();
8232 try {
8233 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8234 null, subId, workSource);
8235 if (DBG) log("isVoNrEnabled: " + isEnabled);
8236 return isEnabled;
8237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
8240 }
8241
8242 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008243 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8244 * network status based on which carrier apps could apply actions accordingly,
8245 * enable/disable default url handler for example.
8246 *
8247 * @param subId the subscription ID that this action applies to.
8248 * @param report control start/stop reporting the default network status.
8249 * {@hide}
8250 */
8251 @Override
8252 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8253 enforceModifyPermission();
8254 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255
8256 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008257 if (phone == null) {
8258 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8259 return;
8260 }
8261 try {
8262 phone.carrierActionReportDefaultNetworkStatus(report);
8263 } catch (Exception e) {
8264 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265 } finally {
8266 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008267 }
8268 }
8269
8270 /**
fionaxud9622282017-07-17 17:51:30 -07008271 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8272 * @param subId the subscription ID that this action applies to.
8273 * {@hide}
8274 */
8275 @Override
8276 public void carrierActionResetAll(int subId) {
8277 enforceModifyPermission();
8278 final Phone phone = getPhone(subId);
8279 if (phone == null) {
8280 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8281 return;
8282 }
8283 try {
8284 phone.carrierActionResetAll();
8285 } catch (Exception e) {
8286 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8287 }
8288 }
8289
8290 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008291 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8292 * bug report is being generated.
8293 */
8294 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008295 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008296 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8297 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008298 writer.println("Permission Denial: can't dump Phone from pid="
8299 + Binder.getCallingPid()
8300 + ", uid=" + Binder.getCallingUid()
8301 + "without permission "
8302 + android.Manifest.permission.DUMP);
8303 return;
8304 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008305 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008306 }
Jack Yueb89b242016-06-22 13:27:47 -07008307
Brad Ebingerdac2f002018-04-03 15:17:52 -07008308 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008309 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8310 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8311 @NonNull String[] args) {
8312 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8313 this, in.getFileDescriptor(), out.getFileDescriptor(),
8314 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008315 }
8316
Jack Yueb89b242016-06-22 13:27:47 -07008317 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008318 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008319 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008320 * @param reason the reason the data enable change is taking place
8321 * @param enabled True if enabling the data, otherwise disabling.
8322 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008323 */
8324 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008325 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008326 boolean enabled) {
8327 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8328 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8329 try {
8330 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008331 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008332 } catch (SecurityException se) {
8333 enforceModifyPermission();
8334 }
8335 } else {
8336 enforceModifyPermission();
8337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338
8339 final long identity = Binder.clearCallingIdentity();
8340 try {
8341 Phone phone = getPhone(subId);
8342 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008343 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8344 phone.carrierActionSetMeteredApnsEnabled(enabled);
8345 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08008346 if (phone.isUsingNewDataStack()) {
8347 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8348 } else {
8349 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8350 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008351 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008352 }
8353 } finally {
8354 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008355 }
8356 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008357
8358 /**
8359 * Get Client request stats
8360 * @return List of Client Request Stats
8361 * @hide
8362 */
8363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008364 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8365 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008367 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008368 return null;
8369 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008370 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008372 final long identity = Binder.clearCallingIdentity();
8373 try {
8374 if (phone != null) {
8375 return phone.getClientRequestStats();
8376 }
8377
8378 return null;
8379 } finally {
8380 Binder.restoreCallingIdentity(identity);
8381 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008382 }
8383
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008384 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008385 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008386 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008387 }
Jack Yueb4124c2017-02-16 15:32:43 -08008388
8389 /**
Grace Chen70990072017-03-24 17:21:30 -07008390 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008391 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008392 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008393 * @param state State of SIM (power down, power up, pass through)
8394 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8395 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8396 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008397 *
8398 **/
8399 @Override
Grace Chen70990072017-03-24 17:21:30 -07008400 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008401 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008402 Phone phone = PhoneFactory.getPhone(slotIndex);
8403
vagdeviaf9a5b92018-08-15 16:01:53 -07008404 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8405
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008406 final long identity = Binder.clearCallingIdentity();
8407 try {
8408 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008409 phone.setSimPowerState(state, null, workSource);
8410 }
8411 } finally {
8412 Binder.restoreCallingIdentity(identity);
8413 }
8414 }
8415
8416 /**
8417 * Set SIM card power state.
8418 *
8419 * @param slotIndex SIM slot id.
8420 * @param state State of SIM (power down, power up, pass through)
8421 * @param callback callback to trigger after success or failure
8422 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8423 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8424 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8425 *
8426 **/
8427 @Override
8428 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8429 IIntegerConsumer callback) {
8430 enforceModifyPermission();
8431 Phone phone = PhoneFactory.getPhone(slotIndex);
8432
8433 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8434
8435 final long identity = Binder.clearCallingIdentity();
8436 try {
8437 if (phone != null) {
8438 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8439 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008440 }
8441 } finally {
8442 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008443 }
8444 }
Shuo Qiandd210312017-04-12 22:11:33 +00008445
Tyler Gunn65d45c22017-06-05 11:22:26 -07008446 private boolean isUssdApiAllowed(int subId) {
8447 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008448 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008449 if (configManager == null) {
8450 return false;
8451 }
8452 PersistableBundle pb = configManager.getConfigForSubId(subId);
8453 if (pb == null) {
8454 return false;
8455 }
8456 return pb.getBoolean(
8457 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8458 }
8459
Shuo Qiandd210312017-04-12 22:11:33 +00008460 /**
8461 * Check if phone is in emergency callback mode
8462 * @return true if phone is in emergency callback mode
8463 * @param subId sub id
8464 */
goneil9c5f4872017-12-05 14:07:56 -08008465 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008466 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008467 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008468 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008469
8470 final long identity = Binder.clearCallingIdentity();
8471 try {
8472 if (phone != null) {
8473 return phone.isInEcm();
8474 } else {
8475 return false;
8476 }
8477 } finally {
8478 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008479 }
8480 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008481
8482 /**
8483 * Get the current signal strength information for the given subscription.
8484 * Because this information is not updated when the device is in a low power state
8485 * it should not be relied-upon to be current.
8486 * @param subId Subscription index
8487 * @return the most recent cached signal strength info from the modem
8488 */
8489 @Override
8490 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008491 final long identity = Binder.clearCallingIdentity();
8492 try {
8493 Phone p = getPhone(subId);
8494 if (p == null) {
8495 return null;
8496 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008498 return p.getSignalStrength();
8499 } finally {
8500 Binder.restoreCallingIdentity(identity);
8501 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008502 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008503
Pengquan Meng77b7f132018-08-22 14:49:57 -07008504 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008505 * Get the current modem radio state for the given slot.
8506 * @param slotIndex slot index.
8507 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008508 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008509 * @return the current radio power state from the modem
8510 */
8511 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008512 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008513 Phone phone = PhoneFactory.getPhone(slotIndex);
8514 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008515 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8516 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008517 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8518 }
8519
8520 final long identity = Binder.clearCallingIdentity();
8521 try {
8522 return phone.getRadioPowerState();
8523 } finally {
8524 Binder.restoreCallingIdentity(identity);
8525 }
8526 }
8527 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8528 }
8529
8530 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008531 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8532 *
8533 * <p>Requires one of the following permissions:
8534 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008535 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008536 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8537 * privileges.
8538 *
8539 * @param subId subscription id
8540 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8541 * {@code false}.
8542 */
8543 @Override
8544 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008545 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008546 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008547 try {
8548 mApp.enforceCallingOrSelfPermission(
8549 android.Manifest.permission.ACCESS_NETWORK_STATE,
8550 functionName);
8551 } catch (Exception e) {
8552 mApp.enforceCallingOrSelfPermission(
8553 permission.READ_BASIC_PHONE_STATE, functionName);
8554 }
Shuo Qian093013d2020-08-13 15:42:55 -07008555 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008556 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008557 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008558 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008559
Pengquan Menga1bb6272018-09-06 09:59:22 -07008560 boolean isEnabled = false;
8561 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008562 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008563 Phone phone = getPhone(subId);
8564 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008565 } finally {
8566 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008567 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008568 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008569 }
8570
8571
8572 /**
8573 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8574 *
8575 * <p> Requires permission:
8576 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8577 * privileges.
8578 *
8579 * @param subId subscription id
8580 * @param isEnabled {@code true} means enable, {@code false} means disable.
8581 */
8582 @Override
8583 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8585 mApp, subId, "setDataRoamingEnabled");
8586
Pengquan Menga1bb6272018-09-06 09:59:22 -07008587 final long identity = Binder.clearCallingIdentity();
8588 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008589 Phone phone = getPhone(subId);
8590 if (phone != null) {
8591 phone.setDataRoamingEnabled(isEnabled);
8592 }
8593 } finally {
8594 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008595 }
8596 }
8597
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008598 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008599 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008600 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008601 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008602 mApp, subId, "isManualNetworkSelectionAllowed");
8603
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008604 boolean isAllowed = true;
8605 final long identity = Binder.clearCallingIdentity();
8606 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008607 Phone phone = getPhone(subId);
8608 if (phone != null) {
8609 isAllowed = phone.isCspPlmnEnabled();
8610 }
8611 } finally {
8612 Binder.restoreCallingIdentity(identity);
8613 }
8614 return isAllowed;
8615 }
8616
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008617 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8618 UiccProfile profile = port.getUiccProfile();
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08008619 if (profile == null) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008620 return false;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008621 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08008622 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8623 if (phone == null) {
8624 return false;
8625 }
8626 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8627 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8628 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008629 }
8630
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008631 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008632 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008633 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008634 mApp.getSystemService(AppOpsManager.class)
8635 .checkPackage(Binder.getCallingUid(), callingPackage);
8636
Jordan Liu1e142fc2019-04-22 15:10:43 -07008637 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008638 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008639 try {
8640 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008641 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008642 } catch (SecurityException e) {
8643 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8644 // has carrier privileges on an active UICC
Rambo Wang04d1ace2022-02-23 13:41:02 -08008645 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008646 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008647 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008648 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008649 }
sandeepjs0a502c42021-09-27 15:34:44 +00008650 // checking compatibility, if calling app's target SDK is T and beyond.
8651 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8652 Binder.getCallingUid())) {
8653 isIccIdAccessRestricted = true;
8654 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008655 final long identity = Binder.clearCallingIdentity();
8656 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008657 UiccController uiccController = UiccController.getInstance();
8658 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008659 if (hasReadPermission) {
8660 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008661 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008662
8663 // Remove private info if the caller doesn't have access
8664 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8665 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008666 //setting the value after compatibility check
8667 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008668 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8669 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008670 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008671 if (card == null) {
8672 // assume no access if the card is unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008673 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008674 continue;
8675 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008676 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8677 if (portInfos.isEmpty()) {
sandeepjs0a502c42021-09-27 15:34:44 +00008678 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008679 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008680 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008681 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8682 for (UiccPortInfo portInfo : portInfos) {
8683 UiccPort port = uiccController.getUiccPortForSlot(
8684 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8685 if (port == null) {
8686 // assume no access if port is null
8687 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8688 continue;
8689 }
8690 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8691 uiccPortInfos.add(portInfo);
8692 } else {
8693 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8694 }
8695 }
8696 filteredInfos.add(new UiccCardInfo(
8697 cardInfo.isEuicc(),
8698 cardInfo.getCardId(),
8699 null,
8700 cardInfo.getPhysicalSlotIndex(),
8701 cardInfo.isRemovable(),
8702 cardInfo.isMultipleEnabledProfilesSupported(),
8703 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008704 }
8705 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008706 } finally {
8707 Binder.restoreCallingIdentity(identity);
8708 }
8709 }
8710
sandeepjs0a502c42021-09-27 15:34:44 +00008711 /**
8712 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8713 * generally private and require carrier privileges to view.
8714 *
8715 * @hide
8716 */
8717 @NonNull
8718 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8719 List<UiccPortInfo> portinfo = new ArrayList<>();
8720 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8721 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8722 }
8723 return new UiccCardInfo(
8724 cardInfo.isEuicc(),
8725 cardInfo.getCardId(),
8726 null,
8727 cardInfo.getPhysicalSlotIndex(),
8728 cardInfo.isRemovable(),
8729 cardInfo.isMultipleEnabledProfilesSupported(),
8730 portinfo
8731 );
8732 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008733
sandeepjs0a502c42021-09-27 15:34:44 +00008734 /**
8735 * @hide
8736 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8737 * These values are generally private and require carrier privileges to view.
8738 */
8739 @NonNull
8740 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8741 return new UiccPortInfo(
8742 UiccPortInfo.ICCID_REDACTED,
8743 portInfo.getPortIndex(),
8744 portInfo.getLogicalSlotIndex(),
8745 portInfo.isActive()
8746 );
8747 }
8748 @Override
8749 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008750 // Verify that the callingPackage belongs to the calling UID
sandeepjs0a502c42021-09-27 15:34:44 +00008751 mApp.getSystemService(AppOpsManager.class)
8752 .checkPackage(Binder.getCallingUid(), callingPackage);
8753
8754 boolean hasReadPermission = false;
8755 boolean isLogicalSlotAccessRestricted = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008756
8757 try {
8758 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8759 hasReadPermission = true;
8760 } catch (SecurityException e) {
8761 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8762 // has carrier privileges on an active UICC
Rambo Wang04d1ace2022-02-23 13:41:02 -08008763 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
sandeepjs0a502c42021-09-27 15:34:44 +00008764 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8765 hasReadPermission = true;
8766 }
8767 }
8768
8769 // checking compatibility, if calling app's target SDK is T and beyond.
8770 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8771 Binder.getCallingUid())) {
8772 isLogicalSlotAccessRestricted = true;
8773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008774 final long identity = Binder.clearCallingIdentity();
8775 try {
8776 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8777 if (slots == null) {
8778 Rlog.i(LOG_TAG, "slots is null.");
8779 return null;
8780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008781 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8782 for (int i = 0; i < slots.length; i++) {
8783 UiccSlot slot = slots[i];
8784 if (slot == null) {
8785 continue;
8786 }
8787
Jordan Liu7be7e652019-05-06 18:55:02 +00008788 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008789 UiccCard card = slot.getUiccCard();
8790 if (card != null) {
8791 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008792 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008793 cardId = slot.getEid();
8794 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008795 // If cardId is null, use iccId of default port as cardId. Check if has
8796 // read permission otherwise set to null.(card is null which means no
8797 // carrier permission)
8798 cardId = hasReadPermission ? slot.getIccId(
8799 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008801 }
8802
Jordan Liu857451f2019-05-09 16:35:35 -07008803 if (cardId != null) {
8804 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8805 // if cardId is an EID, it's all digits so this is fine
8806 cardId = IccUtils.stripTrailingFs(cardId);
8807 }
8808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008809 int cardState = 0;
8810 switch (slot.getCardState()) {
8811 case CARDSTATE_ABSENT:
8812 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8813 break;
8814 case CARDSTATE_PRESENT:
8815 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8816 break;
8817 case CARDSTATE_ERROR:
8818 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8819 break;
8820 case CARDSTATE_RESTRICTED:
8821 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8822 break;
8823 default:
8824 break;
8825
8826 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008827 List<UiccPortInfo> portInfos = new ArrayList<>();
8828 int[] portIndexes = slot.getPortList();
8829 for (int portIdx : portIndexes) {
8830 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8831 callingPackage, hasReadPermission));
8832 if (slot.isPortActive(portIdx)) {
8833 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8834 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8835 port.getPhoneId(), true));
8836 } else {
8837 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8838 }
8839 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008840 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008841 slot.isEuicc(),
8842 cardId,
8843 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008844 slot.isExtendedApduSupported(),
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008845 slot.isRemovable(), portInfos);
sandeepjs0a502c42021-09-27 15:34:44 +00008846 //setting the value after compatibility check
8847 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008848 }
8849 return infos;
8850 } finally {
8851 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008852 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008853 }
8854
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008855 /* Returns null if doesn't have read permission or carrier privilege access. */
8856 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8857 boolean hasReadPermission) {
8858 String iccId = slot.getIccId(portIndex);
8859 if (hasReadPermission) { // if has read permission
8860 return iccId;
8861 } else {
8862 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8863 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8864 // if no read permission, checking carrier privilege access
8865 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8866 return iccId;
8867 }
8868 }
8869 }
8870 // No read permission or carrier privilege access.
8871 return UiccPortInfo.ICCID_REDACTED;
8872 }
8873
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008874 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008875 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008876 public boolean switchSlots(int[] physicalSlots) {
8877 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008878
8879 final long identity = Binder.clearCallingIdentity();
8880 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008881 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8882 for (int i = 0; i < physicalSlots.length; i++) {
8883 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8884 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8885 physicalSlots[i], i));
8886 }
8887 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008888 } finally {
8889 Binder.restoreCallingIdentity(identity);
8890 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008891 }
Jack Yu4c988042018-02-27 15:30:01 -08008892
8893 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008894 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8895 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8896 enforceModifyPermission();
8897
8898 final long identity = Binder.clearCallingIdentity();
8899 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008900 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjs0a502c42021-09-27 15:34:44 +00008901 } finally {
8902 Binder.restoreCallingIdentity(identity);
8903 }
8904 }
8905
8906 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008907 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008908 final long identity = Binder.clearCallingIdentity();
8909 try {
8910 return UiccController.getInstance().getCardIdForDefaultEuicc();
8911 } finally {
8912 Binder.restoreCallingIdentity(identity);
8913 }
8914 }
8915
Pengquan Meng85728fb2018-03-12 16:31:21 -07008916 /**
goneil47ffb6e2018-04-06 15:40:58 -07008917 * A test API to reload the UICC profile.
8918 *
8919 * <p>Requires that the calling app has permission
8920 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8921 * @hide
8922 */
8923 @Override
8924 public void refreshUiccProfile(int subId) {
8925 enforceModifyPermission();
8926
8927 final long identity = Binder.clearCallingIdentity();
8928 try {
8929 Phone phone = getPhone(subId);
8930 if (phone == null) {
8931 return;
8932 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008933 UiccPort uiccPort = phone.getUiccPort();
8934 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008935 return;
8936 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008937 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008938 if (uiccProfile == null) {
8939 return;
8940 }
8941 uiccProfile.refresh();
8942 } finally {
8943 Binder.restoreCallingIdentity(identity);
8944 }
8945 }
8946
8947 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008948 * Returns false if the mobile data is disabled by default, otherwise return true.
8949 */
8950 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008951 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008952 }
8953
8954 /**
8955 * Returns true if the data roaming is enabled by default, i.e the system property
8956 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8957 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8958 */
8959 private boolean getDefaultDataRoamingEnabled(int subId) {
8960 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008961 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008962 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008963 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8964 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8965 return isDataRoamingEnabled;
8966 }
8967
8968 /**
8969 * Returns the default network type for the given {@code subId}, if the default network type is
8970 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8971 */
8972 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008973 List<Integer> list = TelephonyProperties.default_network();
8974 int phoneId = mSubscriptionController.getPhoneId(subId);
8975 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8976 return list.get(phoneId);
8977 }
8978 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008979 }
fionaxua13278b2018-03-21 00:08:13 -07008980
8981 @Override
8982 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008983 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008985
8986 final long identity = Binder.clearCallingIdentity();
8987 try {
8988 final Phone phone = getPhone(subId);
8989 if (phone == null) {
8990 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8991 return;
8992 }
Rambo Wanga7436882022-01-13 21:51:44 -08008993 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8994 if (cpt != null) {
8995 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
8996 }
8997 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07008998 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8999 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009000 if (carrierPrivilegeRules == null) {
9001 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9002 } else {
9003 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009005 } finally {
9006 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009007 }
fionaxua13278b2018-03-21 00:08:13 -07009008 }
9009
9010 @Override
9011 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009012 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009013
9014 final long identity = Binder.clearCallingIdentity();
9015 try {
9016 final Phone phone = getPhone(subId);
9017 if (phone == null) {
9018 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9019 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9020 }
9021 return phone.getCarrierIdListVersion();
9022 } finally {
9023 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009024 }
fionaxua13278b2018-03-21 00:08:13 -07009025 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009026
9027 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009028 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9029 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009030 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009031 mApp, subId, callingPackage, callingFeatureId,
9032 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009033 return -1;
9034 }
9035
9036 final long identity = Binder.clearCallingIdentity();
9037 try {
9038 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9039 } finally {
9040 Binder.restoreCallingIdentity(identity);
9041 }
9042 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009043
9044 @Override
9045 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009046 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009047 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009048 mApp, subId, "getCdmaRoamingMode");
9049
9050 final long identity = Binder.clearCallingIdentity();
9051 try {
9052 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9053 } finally {
9054 Binder.restoreCallingIdentity(identity);
9055 }
9056 }
9057
9058 @Override
9059 public boolean setCdmaRoamingMode(int subId, int mode) {
9060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9061 mApp, subId, "setCdmaRoamingMode");
9062
9063 final long identity = Binder.clearCallingIdentity();
9064 try {
9065 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9066 } finally {
9067 Binder.restoreCallingIdentity(identity);
9068 }
9069 }
9070
9071 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009072 public int getCdmaSubscriptionMode(int subId) {
9073 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009074 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009075 mApp, subId, "getCdmaSubscriptionMode");
9076
9077 final long identity = Binder.clearCallingIdentity();
9078 try {
9079 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9080 } finally {
9081 Binder.restoreCallingIdentity(identity);
9082 }
9083 }
9084
9085 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009086 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9088 mApp, subId, "setCdmaSubscriptionMode");
9089
9090 final long identity = Binder.clearCallingIdentity();
9091 try {
9092 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9093 } finally {
9094 Binder.restoreCallingIdentity(identity);
9095 }
9096 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009097
sqianc5eccab2018-10-19 18:46:41 -07009098 @Override
sqian8c685422019-02-22 15:55:18 -08009099 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009100 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009102 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9103 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009104 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9105 }
9106 final long identity = Binder.clearCallingIdentity();
9107 try {
sqian854d44b2018-12-12 16:48:18 -08009108 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9109 for (Phone phone: PhoneFactory.getPhones()) {
9110 if (phone.getEmergencyNumberTracker() != null
9111 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9112 emergencyNumberListInternal.put(
9113 phone.getSubId(),
9114 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9115 }
sqian11b7a0e2018-12-05 18:48:28 -08009116 }
sqian854d44b2018-12-12 16:48:18 -08009117 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009118 } finally {
9119 Binder.restoreCallingIdentity(identity);
9120 }
sqianc5eccab2018-10-19 18:46:41 -07009121 }
9122
9123 @Override
sqian8c685422019-02-22 15:55:18 -08009124 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009125 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009126 if (!exactMatch) {
9127 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009128 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009129 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009130 }
9131 final long identity = Binder.clearCallingIdentity();
9132 try {
sqian854d44b2018-12-12 16:48:18 -08009133 for (Phone phone: PhoneFactory.getPhones()) {
9134 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009135 && phone.getEmergencyNumberTracker()
9136 .isEmergencyNumber(number, exactMatch)) {
9137 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009138 }
sqian11b7a0e2018-12-05 18:48:28 -08009139 }
9140 return false;
9141 } finally {
9142 Binder.restoreCallingIdentity(identity);
9143 }
9144 }
9145
sqianf4ca7ed2019-01-15 18:32:07 -08009146 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009147 * Start emergency callback mode for GsmCdmaPhone for testing.
9148 */
9149 @Override
9150 public void startEmergencyCallbackMode() {
9151 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9152 "startEmergencyCallbackMode");
9153 enforceModifyPermission();
9154 final long identity = Binder.clearCallingIdentity();
9155 try {
9156 for (Phone phone : PhoneFactory.getPhones()) {
9157 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9158 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9159 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9160 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9161 gsmCdmaPhone.obtainMessage(
9162 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9163 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9164 }
9165 }
9166 } finally {
9167 Binder.restoreCallingIdentity(identity);
9168 }
9169 }
9170
9171 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009172 * Update emergency number list for test mode.
9173 */
9174 @Override
9175 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9176 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9177 "updateEmergencyNumberListTestMode");
9178
9179 final long identity = Binder.clearCallingIdentity();
9180 try {
9181 for (Phone phone: PhoneFactory.getPhones()) {
9182 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9183 if (tracker != null) {
9184 tracker.executeEmergencyNumberTestModeCommand(action, num);
9185 }
9186 }
9187 } finally {
9188 Binder.restoreCallingIdentity(identity);
9189 }
9190 }
9191
9192 /**
9193 * Get the full emergency number list for test mode.
9194 */
9195 @Override
9196 public List<String> getEmergencyNumberListTestMode() {
9197 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9198 "getEmergencyNumberListTestMode");
9199
9200 final long identity = Binder.clearCallingIdentity();
9201 try {
9202 Set<String> emergencyNumbers = new HashSet<>();
9203 for (Phone phone: PhoneFactory.getPhones()) {
9204 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9205 if (tracker != null) {
9206 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9207 emergencyNumbers.add(num.getNumber());
9208 }
9209 }
9210 }
9211 return new ArrayList<>(emergencyNumbers);
9212 } finally {
9213 Binder.restoreCallingIdentity(identity);
9214 }
9215 }
9216
chen xud6b45bd2018-10-30 22:27:10 -07009217 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009218 public int getEmergencyNumberDbVersion(int subId) {
9219 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9220
9221 final long identity = Binder.clearCallingIdentity();
9222 try {
9223 final Phone phone = getPhone(subId);
9224 if (phone == null) {
9225 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9226 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9227 }
9228 return phone.getEmergencyNumberDbVersion();
9229 } finally {
9230 Binder.restoreCallingIdentity(identity);
9231 }
9232 }
9233
9234 @Override
9235 public void notifyOtaEmergencyNumberDbInstalled() {
9236 enforceModifyPermission();
9237
9238 final long identity = Binder.clearCallingIdentity();
9239 try {
9240 for (Phone phone: PhoneFactory.getPhones()) {
9241 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9242 if (tracker != null) {
9243 tracker.updateOtaEmergencyNumberDatabase();
9244 }
9245 }
9246 } finally {
9247 Binder.restoreCallingIdentity(identity);
9248 }
9249 }
9250
9251 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009252 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009253 enforceActiveEmergencySessionPermission();
9254
9255 final long identity = Binder.clearCallingIdentity();
9256 try {
9257 for (Phone phone: PhoneFactory.getPhones()) {
9258 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9259 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009260 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9261 }
9262 }
9263 } finally {
9264 Binder.restoreCallingIdentity(identity);
9265 }
9266 }
9267
9268 @Override
9269 public void resetOtaEmergencyNumberDbFilePath() {
9270 enforceActiveEmergencySessionPermission();
9271
9272 final long identity = Binder.clearCallingIdentity();
9273 try {
9274 for (Phone phone: PhoneFactory.getPhones()) {
9275 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9276 if (tracker != null) {
9277 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009278 }
9279 }
9280 } finally {
9281 Binder.restoreCallingIdentity(identity);
9282 }
9283 }
9284
9285 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009286 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9287 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9288 Phone phone = getPhone(subId);
9289 if (phone == null) {
9290 return null;
9291 }
9292 final long identity = Binder.clearCallingIdentity();
9293 try {
9294 UiccProfile profile = UiccController.getInstance()
9295 .getUiccProfileForPhone(phone.getPhoneId());
9296 if (profile != null) {
9297 return profile.getCertsFromCarrierPrivilegeAccessRules();
9298 }
9299 } finally {
9300 Binder.restoreCallingIdentity(identity);
9301 }
9302 return null;
9303 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009304
9305 /**
9306 * Enable or disable a modem stack.
9307 */
9308 @Override
9309 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9310 enforceModifyPermission();
9311
9312 final long identity = Binder.clearCallingIdentity();
9313 try {
9314 Phone phone = PhoneFactory.getPhone(slotIndex);
9315 if (phone == null) {
9316 return false;
9317 } else {
9318 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9319 }
9320 } finally {
9321 Binder.restoreCallingIdentity(identity);
9322 }
9323 }
Michelecea4cf22018-12-21 15:00:11 -08009324
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009325 /**
9326 * Whether a modem stack is enabled or not.
9327 */
9328 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009329 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9330 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009331 Phone phone = PhoneFactory.getPhone(slotIndex);
9332 if (phone == null) return false;
9333
9334 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009335 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9336 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009337 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9338 }
9339
9340 final long identity = Binder.clearCallingIdentity();
9341 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009342 try {
9343 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9344 } catch (NoSuchElementException ex) {
9345 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9346 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009347 } finally {
9348 Binder.restoreCallingIdentity(identity);
9349 }
9350 }
9351
Michelecea4cf22018-12-21 15:00:11 -08009352 @Override
Michele0ea7d782019-03-19 14:58:42 -07009353 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009354 enforceModifyPermission();
9355
9356 final long identity = Binder.clearCallingIdentity();
9357 try {
9358 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009359 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009360 .commit();
9361 } finally {
9362 Binder.restoreCallingIdentity(identity);
9363 }
9364 }
9365
9366 @Override
Michele0ea7d782019-03-19 14:58:42 -07009367 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009368 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009370 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9371 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009372 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009373 }
Michelecea4cf22018-12-21 15:00:11 -08009374
9375 final long identity = Binder.clearCallingIdentity();
9376 try {
Michele0ea7d782019-03-19 14:58:42 -07009377 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009378 } finally {
9379 Binder.restoreCallingIdentity(identity);
9380 }
9381 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009382
Michele0ea7d782019-03-19 14:58:42 -07009383 @TelephonyManager.IsMultiSimSupportedResult
9384 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009385 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9386 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9387 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009388 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9389 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009390 }
9391 // Check if the hardware supports multisim functionality. If usage of multisim is not
9392 // supported by the modem, indicate that it is restricted.
9393 PhoneCapability staticCapability =
9394 mPhoneConfigurationManager.getStaticPhoneCapability();
9395 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009396 loge("isMultiSimSupportedInternal: no static configuration available");
9397 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009398 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009399 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009400 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9401 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009402 }
9403 // Check if support of multiple SIMs is restricted by carrier
9404 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009405 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009406 }
9407
Michele0ea7d782019-03-19 14:58:42 -07009408 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009409 }
9410
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009411 /**
9412 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009413 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9414 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9415 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009416 * @param numOfSims number of active sims we want to switch to
9417 */
9418 @Override
9419 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009420 if (numOfSims == 1) {
9421 enforceModifyPermission();
9422 } else {
9423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9424 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9425 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009426 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009427
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009428 try {
Michele30b57b22019-03-01 12:01:14 -08009429 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009430 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009431 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9432 return;
9433 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009434 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9435 } finally {
9436 Binder.restoreCallingIdentity(identity);
9437 }
9438 }
9439
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009440 @Override
9441 public boolean isApplicationOnUicc(int subId, int appType) {
9442 enforceReadPrivilegedPermission("isApplicationOnUicc");
9443 Phone phone = getPhone(subId);
9444 if (phone == null) {
9445 return false;
9446 }
9447 final long identity = Binder.clearCallingIdentity();
9448 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009449 UiccPort uiccPort = phone.getUiccPort();
9450 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009451 return false;
9452 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009453 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009454 if (uiccProfile == null) {
9455 return false;
9456 }
9457 if (TelephonyManager.APPTYPE_SIM <= appType
9458 && appType <= TelephonyManager.APPTYPE_ISIM) {
9459 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9460 }
9461 return false;
9462 } finally {
9463 Binder.restoreCallingIdentity(identity);
9464 }
9465 }
9466
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009467 /**
chen xub4baa772019-04-03 10:23:41 -07009468 * Get whether making changes to modem configurations will trigger reboot.
9469 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009470 */
9471 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009472 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9473 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009475 mApp, subId, callingPackage, callingFeatureId,
9476 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009477 return false;
9478 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009479 final long identity = Binder.clearCallingIdentity();
9480 try {
9481 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9482 } finally {
9483 Binder.restoreCallingIdentity(identity);
9484 }
9485 }
9486
Nathan Harold29f5f052019-02-15 13:41:57 -08009487 private void updateModemStateMetrics() {
9488 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9489 // TODO: check the state for each modem if the api is ready.
9490 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9491 }
9492
Pengquan Meng3889a572019-01-23 11:16:29 -08009493 @Override
sandeepjs29b7e8e2021-11-17 04:05:58 +00009494 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009495 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjs29b7e8e2021-11-17 04:05:58 +00009496 // Verify that the callingPackage belongs to the calling UID
9497 mApp.getSystemService(AppOpsManager.class)
9498 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009499 final long identity = Binder.clearCallingIdentity();
sandeepjs29b7e8e2021-11-17 04:05:58 +00009500 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009501 try {
sandeepjs29b7e8e2021-11-17 04:05:58 +00009502 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9503 if (slotInfos != null) {
9504 for (int i = 0; i < slotInfos.length; i++) {
9505 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9506 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9507 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9508 portInfo.getLogicalSlotIndex()));
9509 }
9510 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009511 }
9512 }
sandeepjs29b7e8e2021-11-17 04:05:58 +00009513 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009514 } finally {
9515 Binder.restoreCallingIdentity(identity);
9516 }
9517 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009518
9519 /**
9520 * Get the IRadio HAL Version
9521 */
9522 @Override
9523 public int getRadioHalVersion() {
9524 Phone phone = getDefaultPhone();
9525 if (phone == null) return -1;
9526 HalVersion hv = phone.getHalVersion();
9527 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9528 return hv.major * 100 + hv.minor;
9529 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009530
9531 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009532 * Get the current calling package name.
9533 * @return the current calling package name
9534 */
9535 @Override
9536 public String getCurrentPackageName() {
9537 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9538 }
9539
9540 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009541 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9542 * corresponding network requests on a subId.
9543 *
9544 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009545 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009546 * 2) APN is un-metered for this subscription, or
9547 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009548 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009549 *
9550 * @return whether data is allowed for a apn type.
9551 *
9552 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009553 */
9554 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009555 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009556 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9557 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009558
9559 // Now that all security checks passes, perform the operation as ourselves.
9560 final long identity = Binder.clearCallingIdentity();
9561 try {
9562 Phone phone = getPhone(subId);
9563 if (phone == null) return false;
9564
Jack Yu41407ee2019-05-13 16:54:09 -07009565 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009566 boolean isDataEnabled;
9567 if (phone.isUsingNewDataStack()) {
9568 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9569 } else {
9570 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9571 }
9572 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009573 } finally {
9574 Binder.restoreCallingIdentity(identity);
9575 }
9576 }
9577
9578 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009579 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009580 enforceReadPrivilegedPermission("isApnMetered");
9581
9582 // Now that all security checks passes, perform the operation as ourselves.
9583 final long identity = Binder.clearCallingIdentity();
9584 try {
9585 Phone phone = getPhone(subId);
9586 if (phone == null) return true; // By default return true.
9587
Jack Yu41407ee2019-05-13 16:54:09 -07009588 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009589 } finally {
9590 Binder.restoreCallingIdentity(identity);
9591 }
9592 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009593
9594 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009595 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9596 int subscriptionId, IBooleanConsumer resultCallback) {
9597 enforceModifyPermission();
9598 long token = Binder.clearCallingIdentity();
9599 try {
9600 Phone phone = getPhone(subscriptionId);
9601 if (phone == null) {
9602 try {
9603 if (resultCallback != null) {
9604 resultCallback.accept(false);
9605 }
9606 } catch (RemoteException e) {
9607 // ignore
9608 }
9609 return;
9610 }
9611 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9612 Pair.create(specifiers, (x) -> {
9613 try {
9614 if (resultCallback != null) {
9615 resultCallback.accept(x);
9616 }
9617 } catch (RemoteException e) {
9618 // ignore
9619 }
9620 });
9621 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9622 } finally {
9623 Binder.restoreCallingIdentity(token);
9624 }
9625 }
9626
9627 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009628 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9629 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009630 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009631 mApp, subId, "getSystemSelectionChannels");
9632 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9633 final long identity = Binder.clearCallingIdentity();
9634 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009635 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9636 if (result instanceof IllegalStateException) {
9637 throw (IllegalStateException) result;
9638 }
9639 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009640 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9641 return specifiers;
9642 } finally {
9643 Binder.restoreCallingIdentity(identity);
9644 }
9645 }
9646
9647 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009648 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009649 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009650 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9651 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9652 if (iccRecords == null) {
9653 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9654 return false;
9655 }
9656 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9657 }
9658
9659 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009660 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9661 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009662 if (callingPackage == null) {
9663 callingPackage = getCurrentPackageName();
9664 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009665 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9666 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009667 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9668 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009669 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9670 }
9671 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9672 Intent intent = new Intent();
9673 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9674 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9675 // Bring up choose default SMS subscription dialog right now
9676 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9677 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9678 mApp.startActivity(intent);
9679 }
chen xud5ca2d52019-05-28 15:20:57 -07009680
9681 @Override
9682 public String getMmsUAProfUrl(int subId) {
9683 //TODO investigate if this API should require proper permission check in R b/133791609
9684 final long identity = Binder.clearCallingIdentity();
9685 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009686 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9687 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9688 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9689 return carrierUAProfUrl;
9690 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009691 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9692 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009693 } finally {
9694 Binder.restoreCallingIdentity(identity);
9695 }
9696 }
9697
9698 @Override
9699 public String getMmsUserAgent(int subId) {
9700 //TODO investigate if this API should require proper permission check in R b/133791609
9701 final long identity = Binder.clearCallingIdentity();
9702 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009703 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9704 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9705 if (!TextUtils.isEmpty(carrierUserAgent)) {
9706 return carrierUserAgent;
9707 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009708 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9709 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009710 } finally {
9711 Binder.restoreCallingIdentity(identity);
9712 }
9713 }
Jack Yub07d4972019-05-28 16:12:25 -07009714
9715 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009716 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9717 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009718
Jack Yub07d4972019-05-28 16:12:25 -07009719 final long identity = Binder.clearCallingIdentity();
9720 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009721 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009722 if (phone == null) return false;
9723
Hall Liua62f5da2020-09-25 10:42:19 -07009724 switch (policy) {
9725 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009726 if (phone.isUsingNewDataStack()) {
9727 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9728 } else {
9729 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9730 }
Hall Liua62f5da2020-09-25 10:42:19 -07009731 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009732 if (phone.isUsingNewDataStack()) {
9733 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9734 } else {
9735 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9736 }
Hall Liua62f5da2020-09-25 10:42:19 -07009737 default:
9738 throw new IllegalArgumentException(policy + " is not a valid policy");
9739 }
Jack Yub07d4972019-05-28 16:12:25 -07009740 } finally {
9741 Binder.restoreCallingIdentity(identity);
9742 }
9743 }
9744
9745 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009746 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009747 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009748 enforceModifyPermission();
9749
changbettyd5c246e2019-12-24 15:40:37 +08009750 final long identity = Binder.clearCallingIdentity();
9751 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009752 Phone phone = getPhone(subscriptionId);
9753 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009754
Hall Liua62f5da2020-09-25 10:42:19 -07009755 switch (policy) {
9756 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009757 if (phone.isUsingNewDataStack()) {
9758 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9759 } else {
9760 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9761 }
Hall Liua62f5da2020-09-25 10:42:19 -07009762 break;
9763 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009764 if (phone.isUsingNewDataStack()) {
9765 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9766 } else {
9767 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9768 }
Hall Liua62f5da2020-09-25 10:42:19 -07009769 break;
9770 default:
9771 throw new IllegalArgumentException(policy + " is not a valid policy");
9772 }
changbettyd5c246e2019-12-24 15:40:37 +08009773 } finally {
9774 Binder.restoreCallingIdentity(identity);
9775 }
9776 }
9777
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009778 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009779 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009780 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9781 * otherwise.
9782 */
9783 @Override
9784 public void setCepEnabled(boolean isCepEnabled) {
9785 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9786
9787 final long identity = Binder.clearCallingIdentity();
9788 try {
9789 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9790 for (Phone phone : PhoneFactory.getPhones()) {
9791 Phone defaultPhone = phone.getImsPhone();
9792 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9793 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9794 ImsPhoneCallTracker imsPhoneCallTracker =
9795 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9796 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9797 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9798 + imsPhone.getMsisdn());
9799 }
9800 }
9801 } finally {
9802 Binder.restoreCallingIdentity(identity);
9803 }
9804 }
allenwtsu46dcc572020-01-08 18:24:03 +08009805
9806 /**
9807 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9808 *
9809 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9810 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9811 * before being read.
9812 */
9813 @Override
9814 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9815 isCompressed) {
9816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9817 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009818 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9819 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9820 }
9821 if (!isImsAvailableOnDevice()) {
9822 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9823 "IMS not available on device.");
9824 }
9825
9826 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009827 try {
Hui Wang761a6682020-10-31 05:12:53 +00009828 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9829 } finally {
9830 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009831 }
9832 }
zoey chene02881a2019-12-30 16:11:23 +08009833
9834 @Override
9835 public boolean isIccLockEnabled(int subId) {
9836 enforceReadPrivilegedPermission("isIccLockEnabled");
9837
9838 // Now that all security checks passes, perform the operation as ourselves.
9839 final long identity = Binder.clearCallingIdentity();
9840 try {
9841 Phone phone = getPhone(subId);
9842 if (phone != null && phone.getIccCard() != null) {
9843 return phone.getIccCard().getIccLockEnabled();
9844 } else {
9845 return false;
9846 }
9847 } finally {
9848 Binder.restoreCallingIdentity(identity);
9849 }
9850 }
9851
9852 /**
9853 * Set the ICC pin lock enabled or disabled.
9854 *
9855 * @return an integer representing the status of IccLock enabled or disabled in the following
9856 * three cases:
9857 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9858 * successfully.
9859 * - Positive number and zero for remaining password attempts.
9860 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9861 *
9862 */
9863 @Override
9864 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9865 enforceModifyPermission();
9866
9867 Phone phone = getPhone(subId);
9868 if (phone == null) {
9869 return 0;
9870 }
9871 // Now that all security checks passes, perform the operation as ourselves.
9872 final long identity = Binder.clearCallingIdentity();
9873 try {
9874 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9875 new Pair<Boolean, String>(enabled, password), phone, null);
9876 return attemptsRemaining;
9877
9878 } catch (Exception e) {
9879 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9880 } finally {
9881 Binder.restoreCallingIdentity(identity);
9882 }
9883 return 0;
9884 }
9885
9886 /**
9887 * Change the ICC password used in ICC pin lock.
9888 *
9889 * @return an integer representing the status of IccLock changed in the following three cases:
9890 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9891 * - Positive number and zero for remaining password attempts.
9892 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9893 *
9894 */
9895 @Override
9896 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9897 enforceModifyPermission();
9898
9899 Phone phone = getPhone(subId);
9900 if (phone == null) {
9901 return 0;
9902 }
9903 // Now that all security checks passes, perform the operation as ourselves.
9904 final long identity = Binder.clearCallingIdentity();
9905 try {
9906 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9907 new Pair<String, String>(oldPassword, newPassword), phone, null);
9908 return attemptsRemaining;
9909
9910 } catch (Exception e) {
9911 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9912 } finally {
9913 Binder.restoreCallingIdentity(identity);
9914 }
9915 return 0;
9916 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009917
9918 /**
9919 * Request for receiving user activity notification
9920 */
9921 @Override
9922 public void requestUserActivityNotification() {
9923 if (!mNotifyUserActivity.get()
9924 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9925 mNotifyUserActivity.set(true);
9926 }
9927 }
9928
9929 /**
9930 * Called when userActivity is signalled in the power manager.
9931 * This is safe to call from any thread, with any window manager locks held or not.
9932 */
9933 @Override
9934 public void userActivity() {
9935 // ***************************************
9936 // * Inherited from PhoneWindowManager *
9937 // ***************************************
9938 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9939 // WITH ITS LOCKS HELD.
9940 //
9941 // This code must be VERY careful about the locks
9942 // it acquires.
9943 // In fact, the current code acquires way too many,
9944 // and probably has lurking deadlocks.
9945
9946 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9947 throw new SecurityException("Only the OS may call notifyUserActivity()");
9948 }
9949
9950 if (mNotifyUserActivity.getAndSet(false)) {
9951 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9952 USER_ACTIVITY_NOTIFICATION_DELAY);
9953 }
9954 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009955
9956 @Override
9957 public boolean canConnectTo5GInDsdsMode() {
9958 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9959 }
Jack Yud10cdd42020-09-28 20:28:01 -07009960
9961 @Override
9962 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9963 String callingFeatureId) {
9964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9965 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9966 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9967 }
9968
9969 Phone phone = getPhone(subId);
9970 if (phone == null) {
9971 throw new RuntimeException("phone is not available");
9972 }
9973 // Now that all security checks passes, perform the operation as ourselves.
9974 final long identity = Binder.clearCallingIdentity();
9975 try {
9976 return phone.getEquivalentHomePlmns();
9977 } finally {
9978 Binder.restoreCallingIdentity(identity);
9979 }
9980 }
Daniel Bright59e67312020-11-13 11:49:37 -08009981
9982 @Override
9983 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009984 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9985 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009986 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009987 if (radioInterfaceCapabilities == null) {
9988 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009989 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009990 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009991 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009992
Hui Wang641e81c2020-10-12 12:14:23 -07009993 @Override
9994 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9995 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009996 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9997 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9998 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9999 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10000 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010001 if (DBG) {
10002 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10003 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10004 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10005 }
10006
10007 if (!SubscriptionManager.isValidSubscriptionId(subId)
10008 || appType < TelephonyManager.APPTYPE_UNKNOWN
10009 || appType > TelephonyManager.APPTYPE_ISIM
10010 || nafUrl == null || securityProtocol == null || callback == null) {
10011 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10012 if (callback != null) {
10013 try {
10014 callback.onAuthenticationFailure(
10015 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10016 } catch (RemoteException exception) {
10017 log("Fail to notify onAuthenticationFailure due to " + exception);
10018 }
10019 return;
10020 }
10021 }
10022
10023 final long token = Binder.clearCallingIdentity();
10024 try {
10025 getGbaManager(subId).bootstrapAuthenticationRequest(
10026 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10027 forceBootStrapping, callback));
10028 } finally {
10029 Binder.restoreCallingIdentity(token);
10030 }
10031 }
10032
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010033 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010034 * Attempts to set the radio power state for all phones for thermal reason.
10035 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010036 * requested radio power state will actually be set. See {@link
10037 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10038 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010039 * @param enable {@code true} if trying to turn radio on.
10040 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10041 * false}.
10042 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010043 private boolean setRadioPowerForThermal(boolean enable) {
10044 boolean isPhoneAvailable = false;
10045 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10046 Phone phone = PhoneFactory.getPhone(i);
10047 if (phone != null) {
10048 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10049 isPhoneAvailable = true;
10050 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010051 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010052
10053 // return true if successfully informed the phone object about the thermal radio power
10054 // request.
10055 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010056 }
10057
10058 private int handleDataThrottlingRequest(int subId,
10059 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010060 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10061 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10062 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10063 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10064 throw new IllegalArgumentException("modem does not support data throttling");
10065 }
10066
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010067 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10068 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010069 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010070 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10071 }
10072
10073 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10074
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010075 if (isDataThrottlingSupported) {
10076 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010077 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010078 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10079 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10080 } else if (thermalMitigationResult
10081 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010082 log("Modem likely does not support data throttling on secondary carrier. Data " +
10083 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10084 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010085 }
10086 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010087 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010088
10089 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010090 }
10091
Jack Nudelman644b91a2021-03-12 14:09:48 -080010092 private static List<String> getThermalMitigationAllowlist(Context context) {
10093 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10094 for (String pckg : context.getResources()
10095 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10096 sThermalMitigationAllowlistedPackages.add(pckg);
10097 }
10098 }
10099
10100 return sThermalMitigationAllowlistedPackages;
10101 }
10102
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010103 private boolean isAnyPhoneInEmergencyState() {
10104 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10105 if (tm.isInEmergencyCall()) {
10106 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10107 return true;
10108 }
10109 for (Phone phone : PhoneFactory.getPhones()) {
10110 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10111 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10112 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10113 + phone.isInEcm());
10114 return true;
10115 }
10116 }
10117
10118 return false;
10119 }
10120
Jack Nudelman644b91a2021-03-12 14:09:48 -080010121 /**
10122 * Used by shell commands to add an authorized package name for thermal mitigation.
10123 * @param packageName name of package to be allowlisted
10124 * @param context
10125 */
10126 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10127 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10128 sThermalMitigationAllowlistedPackages.add(packageName);
10129 }
10130
10131 /**
10132 * Used by shell commands to remove an authorized package name for thermal mitigation.
10133 * @param packageName name of package to remove from allowlist
10134 * @param context
10135 */
10136 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10137 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10138 sThermalMitigationAllowlistedPackages.remove(packageName);
10139 }
10140
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010141 /**
10142 * Thermal mitigation request to control functionalities at modem.
10143 *
10144 * @param subId the id of the subscription.
10145 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010146 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010147 *
10148 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10149 */
10150 @Override
10151 @ThermalMitigationResult
10152 public int sendThermalMitigationRequest(
10153 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010154 ThermalMitigationRequest thermalMitigationRequest,
10155 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010156 enforceModifyPermission();
10157
Jack Nudelman644b91a2021-03-12 14:09:48 -080010158 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10159 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10160 .contains(callingPackage)) {
10161 throw new SecurityException("Calling package must be configured in the device config. "
10162 + "calling package: " + callingPackage);
10163 }
10164
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010165 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10166 final long identity = Binder.clearCallingIdentity();
10167
10168 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10169 try {
10170 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10171 switch (thermalMitigationAction) {
10172 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10173 thermalMitigationResult =
10174 handleDataThrottlingRequest(subId,
10175 thermalMitigationRequest.getDataThrottlingRequest());
10176 break;
10177 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10178 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10179 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10180 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10181 }
10182
10183 // Ensure that radio is on. If not able to power on due to phone being
10184 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010185 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010186 thermalMitigationResult =
10187 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10188 break;
10189 }
10190
10191 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10192 false);
10193 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10194 break;
10195 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10196 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10197 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10198 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10199 }
10200
10201 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10202 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010203 Phone phone = getPhone(subId);
10204 if (phone == null) {
10205 thermalMitigationResult =
10206 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10207 break;
10208 }
10209
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010210 TelephonyConnectionService service =
10211 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010212 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010213 Log.e(LOG_TAG, "An emergency call is pending");
10214 thermalMitigationResult =
10215 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10216 break;
10217 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010218 thermalMitigationResult =
10219 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10220 break;
10221 }
10222 } else {
10223 thermalMitigationResult =
10224 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10225 break;
10226 }
10227
10228 // Turn radio off. If not able to power off due to phone being unavailable,
10229 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010230 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010231 thermalMitigationResult =
10232 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10233 break;
10234 }
10235 thermalMitigationResult =
10236 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10237 break;
10238 default:
10239 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10240 + "not exist. Requested action: " + thermalMitigationAction);
10241 }
10242 } catch (IllegalArgumentException e) {
10243 throw e;
10244 } catch (Exception e) {
10245 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10246 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10247 } finally {
10248 Binder.restoreCallingIdentity(identity);
10249 }
10250
10251 if (DBG) {
10252 log("thermalMitigationRequest returning with thermalMitigationResult: "
10253 + thermalMitigationResult);
10254 }
10255
10256 return thermalMitigationResult;
10257 }
Hui Wang641e81c2020-10-12 12:14:23 -070010258
10259 /**
10260 * Set the GbaService Package Name that Telephony will bind to.
10261 *
10262 * @param subId The sim that the GbaService is associated with.
10263 * @param packageName The name of the package to be replaced with.
10264 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10265 */
10266 @Override
10267 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10268 enforceModifyPermission();
10269
10270 final long identity = Binder.clearCallingIdentity();
10271 try {
10272 return getGbaManager(subId).overrideServicePackage(packageName);
10273 } finally {
10274 Binder.restoreCallingIdentity(identity);
10275 }
10276 }
10277
10278 /**
10279 * Return the package name of the currently bound GbaService.
10280 *
10281 * @param subId The sim that the GbaService is associated with.
10282 * @return the package name of the GbaService configuration, null if GBA is not supported.
10283 */
10284 @Override
10285 public String getBoundGbaService(int subId) {
10286 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10287
10288 final long identity = Binder.clearCallingIdentity();
10289 try {
10290 return getGbaManager(subId).getServicePackage();
10291 } finally {
10292 Binder.restoreCallingIdentity(identity);
10293 }
10294 }
10295
10296 /**
10297 * Set the release time for telephony to unbind GbaService.
10298 *
10299 * @param subId The sim that the GbaService is associated with.
10300 * @param interval The release time to unbind GbaService by millisecond.
10301 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10302 */
10303 @Override
10304 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10305 enforceModifyPermission();
10306
10307 final long identity = Binder.clearCallingIdentity();
10308 try {
10309 return getGbaManager(subId).overrideReleaseTime(interval);
10310 } finally {
10311 Binder.restoreCallingIdentity(identity);
10312 }
10313 }
10314
10315 /**
10316 * Return the release time for telephony to unbind GbaService.
10317 *
10318 * @param subId The sim that the GbaService is associated with.
10319 * @return The release time to unbind GbaService by millisecond.
10320 */
10321 @Override
10322 public int getGbaReleaseTime(int subId) {
10323 enforceReadPrivilegedPermission("getGbaReleaseTime");
10324
10325 final long identity = Binder.clearCallingIdentity();
10326 try {
10327 return getGbaManager(subId).getReleaseTime();
10328 } finally {
10329 Binder.restoreCallingIdentity(identity);
10330 }
10331 }
10332
10333 private GbaManager getGbaManager(int subId) {
10334 GbaManager instance = GbaManager.getInstance(subId);
10335 if (instance == null) {
10336 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10337 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10338 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10339 }
10340 return instance;
10341 }
Hui Wang761a6682020-10-31 05:12:53 +000010342
10343 /**
10344 * indicate whether the device and the carrier can support
10345 * RCS VoLTE single registration.
10346 */
10347 @Override
10348 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010349 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10350 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10351 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10352 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010353
10354 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10355 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10356 }
10357
10358 final long identity = Binder.clearCallingIdentity();
10359 try {
10360 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10361 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010362 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10363 if (isCapable != null) {
10364 return isCapable;
10365 }
Hui Wang761a6682020-10-31 05:12:53 +000010366 }
Hui Wang67af90e2021-06-04 16:57:15 -070010367 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10368 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010369 } finally {
10370 Binder.restoreCallingIdentity(identity);
10371 }
10372 }
10373
10374 /**
10375 * Register RCS provisioning callback.
10376 */
10377 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010378 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010379 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010380 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010381 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010382 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10383 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010384
10385 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10386 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10387 }
10388 if (!isImsAvailableOnDevice()) {
10389 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10390 "IMS not available on device.");
10391 }
10392
10393 final long identity = Binder.clearCallingIdentity();
10394 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010395 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010396 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010397 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10398 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010399 }
Hui Wang761a6682020-10-31 05:12:53 +000010400 } finally {
10401 Binder.restoreCallingIdentity(identity);
10402 }
10403 }
10404
10405 /**
10406 * Unregister RCS provisioning callback.
10407 */
10408 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010409 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010410 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010411 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010412 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010413 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10414 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010415
10416 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10417 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10418 }
10419 if (!isImsAvailableOnDevice()) {
10420 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10421 "IMS not available on device.");
10422 }
10423
10424 final long identity = Binder.clearCallingIdentity();
10425 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010426 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010427 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010428 } finally {
10429 Binder.restoreCallingIdentity(identity);
10430 }
10431 }
10432
10433 /**
10434 * trigger RCS reconfiguration.
10435 */
10436 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010437 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10438 "triggerRcsReconfiguration",
10439 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010440
10441 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10442 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10443 }
10444 if (!isImsAvailableOnDevice()) {
10445 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10446 "IMS not available on device.");
10447 }
10448
10449 final long identity = Binder.clearCallingIdentity();
10450 try {
10451 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10452 } finally {
10453 Binder.restoreCallingIdentity(identity);
10454 }
10455 }
10456
10457 /**
10458 * Provide the client configuration parameters of the RCS application.
10459 */
10460 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010461 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10462 "setRcsClientConfiguration",
10463 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010464
10465 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10466 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10467 }
10468 if (!isImsAvailableOnDevice()) {
10469 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10470 "IMS not available on device.");
10471 }
10472
10473 final long identity = Binder.clearCallingIdentity();
10474
10475 try {
10476 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10477 if (configBinder == null) {
10478 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010479 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10480 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010481 } else {
10482 configBinder.setRcsClientConfiguration(rcc);
10483 }
joonhunshinfa314642021-09-17 06:33:39 +000010484
10485 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10486 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010487 } catch (RemoteException e) {
10488 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010489 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10490 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010491 } finally {
10492 Binder.restoreCallingIdentity(identity);
10493 }
10494 }
10495
10496 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010497 * Enables or disables the test mode for RCS VoLTE single registration.
10498 */
10499 @Override
10500 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10501 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10502 "setRcsSingleRegistrationTestModeEnabled");
10503
10504 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10505 }
10506
10507 /**
10508 * Gets the test mode for RCS VoLTE single registration.
10509 */
10510 @Override
10511 public boolean getRcsSingleRegistrationTestModeEnabled() {
10512 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10513 "getRcsSingleRegistrationTestModeEnabled");
10514
10515 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10516 }
10517
10518 /**
Hui Wang761a6682020-10-31 05:12:53 +000010519 * Overrides the config of RCS VoLTE single registration enabled for the device.
10520 */
10521 @Override
10522 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10523 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10524 "setDeviceSingleRegistrationEnabledOverride");
10525 enforceModifyPermission();
10526
10527 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10528 : Boolean.parseBoolean(enabledStr);
10529 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010530 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010531 }
10532
10533 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010534 * Sends a device to device communication message. Only usable via shell.
10535 * @param message message to send.
10536 * @param value message value.
10537 */
10538 @Override
10539 public void sendDeviceToDeviceMessage(int message, int value) {
10540 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010541 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010542 enforceModifyPermission();
10543
10544 final long identity = Binder.clearCallingIdentity();
10545 try {
10546 TelephonyConnectionService service =
10547 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10548 if (service == null) {
10549 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10550 return;
10551 }
10552 service.sendTestDeviceToDeviceMessage(message, value);
10553 } finally {
10554 Binder.restoreCallingIdentity(identity);
10555 }
10556 }
10557
Tyler Gunnbabbda02021-02-10 11:05:02 -080010558 /**
10559 * Sets the specified device to device transport active.
10560 * @param transport The transport to set active.
10561 */
10562 @Override
10563 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10564 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10565 "setActiveDeviceToDeviceTransport");
10566 enforceModifyPermission();
10567
10568 final long identity = Binder.clearCallingIdentity();
10569 try {
10570 TelephonyConnectionService service =
10571 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10572 if (service == null) {
10573 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10574 return;
10575 }
10576 service.setActiveDeviceToDeviceTransport(transport);
10577 } finally {
10578 Binder.restoreCallingIdentity(identity);
10579 }
10580 }
Tyler Gunn92479152021-01-20 16:30:10 -080010581
Tyler Gunnd4575212021-05-03 14:46:49 -070010582 @Override
10583 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10584 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10585 "setDeviceToDeviceForceEnabled");
10586
10587 final long identity = Binder.clearCallingIdentity();
10588 try {
10589 Arrays.stream(PhoneFactory.getPhones()).forEach(
10590 p -> {
10591 Phone thePhone = p.getImsPhone();
10592 if (thePhone != null && thePhone instanceof ImsPhone) {
10593 ImsPhone imsPhone = (ImsPhone) thePhone;
10594 CallTracker tracker = imsPhone.getCallTracker();
10595 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10596 ImsPhoneCallTracker imsPhoneCallTracker =
10597 (ImsPhoneCallTracker) tracker;
10598 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10599 }
10600 }
10601 }
10602 );
10603 } finally {
10604 Binder.restoreCallingIdentity(identity);
10605 }
10606 }
10607
Tyler Gunn92479152021-01-20 16:30:10 -080010608 /**
Hui Wang761a6682020-10-31 05:12:53 +000010609 * Gets the config of RCS VoLTE single registration enabled for the device.
10610 */
10611 @Override
10612 public boolean getDeviceSingleRegistrationEnabled() {
10613 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10614 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10615 }
10616
10617 /**
10618 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10619 */
10620 @Override
10621 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10622 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10623 "setCarrierSingleRegistrationEnabledOverride");
10624 enforceModifyPermission();
10625
10626 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10627 : Boolean.parseBoolean(enabledStr);
10628 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10629 subId, enabled);
10630 }
10631
10632 /**
10633 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10634 */
10635 @Override
10636 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10637 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10638 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10639 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010640
10641 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010642 * Overrides the ims feature validation result
10643 */
10644 @Override
10645 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10646 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10647 "setImsFeatureValidationOverride");
10648
10649 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10650 : Boolean.parseBoolean(enabledStr);
10651 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10652 subId, enabled);
10653 }
10654
10655 /**
10656 * Gets the ims feature validation override value
10657 */
10658 @Override
10659 public boolean getImsFeatureValidationOverride(int subId) {
10660 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10661 "getImsFeatureValidationOverride");
10662 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10663 }
10664
10665 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010666 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10667 * their mobile plan.
10668 */
10669 @Override
10670 public String getMobileProvisioningUrl() {
10671 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10672 final long identity = Binder.clearCallingIdentity();
10673 try {
10674 return getDefaultPhone().getMobileProvisioningUrl();
10675 } finally {
10676 Binder.restoreCallingIdentity(identity);
10677 }
10678 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010679
James.cf Linbcdf8b32021-01-14 16:44:13 +080010680 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010681 * Get the EAB contact from the EAB database.
10682 */
10683 @Override
10684 public String getContactFromEab(String contact) {
10685 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10686 enforceModifyPermission();
10687 final long identity = Binder.clearCallingIdentity();
10688 try {
10689 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10690 } finally {
10691 Binder.restoreCallingIdentity(identity);
10692 }
10693 }
10694
10695 /**
Calvin Pana1434322021-07-01 19:27:01 +080010696 * Get the EAB capability from the EAB database.
10697 */
10698 @Override
10699 public String getCapabilityFromEab(String contact) {
10700 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10701 enforceModifyPermission();
10702 final long identity = Binder.clearCallingIdentity();
10703 try {
10704 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10705 } finally {
10706 Binder.restoreCallingIdentity(identity);
10707 }
10708 }
10709
10710 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010711 * Remove the EAB contacts from the EAB database.
10712 */
10713 @Override
10714 public int removeContactFromEab(int subId, String contacts) {
10715 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10716 enforceModifyPermission();
10717 final long identity = Binder.clearCallingIdentity();
10718 try {
10719 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10720 } finally {
10721 Binder.restoreCallingIdentity(identity);
10722 }
10723 }
10724
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010725 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010726 public boolean getDeviceUceEnabled() {
10727 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10728 final long identity = Binder.clearCallingIdentity();
10729 try {
10730 return mApp.getDeviceUceEnabled();
10731 } finally {
10732 Binder.restoreCallingIdentity(identity);
10733 }
10734 }
10735
10736 @Override
10737 public void setDeviceUceEnabled(boolean isEnabled) {
10738 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10739 final long identity = Binder.clearCallingIdentity();
10740 try {
10741 mApp.setDeviceUceEnabled(isEnabled);
10742 } finally {
10743 Binder.restoreCallingIdentity(identity);
10744 }
10745 }
10746
Brad Ebinger14d467f2021-02-12 06:18:28 +000010747 /**
10748 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10749 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10750 */
10751 // Used for SHELL command only right now.
10752 @Override
10753 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10754 List<String> featureTags) {
10755 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10756 "addUceRegistrationOverrideShell");
10757 final long identity = Binder.clearCallingIdentity();
10758 try {
10759 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10760 new ArraySet<>(featureTags));
10761 } catch (ImsException e) {
10762 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10763 } finally {
10764 Binder.restoreCallingIdentity(identity);
10765 }
10766 }
10767
10768 /**
10769 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10770 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10771 */
10772 // Used for SHELL command only right now.
10773 @Override
10774 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10775 List<String> featureTags) {
10776 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10777 "removeUceRegistrationOverrideShell");
10778 final long identity = Binder.clearCallingIdentity();
10779 try {
10780 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10781 new ArraySet<>(featureTags));
10782 } catch (ImsException e) {
10783 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10784 } finally {
10785 Binder.restoreCallingIdentity(identity);
10786 }
10787 }
10788
10789 /**
10790 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10791 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10792 */
10793 // Used for SHELL command only right now.
10794 @Override
10795 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10796 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10797 "clearUceRegistrationOverrideShell");
10798 final long identity = Binder.clearCallingIdentity();
10799 try {
10800 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10801 } catch (ImsException e) {
10802 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10803 } finally {
10804 Binder.restoreCallingIdentity(identity);
10805 }
10806 }
10807
10808 /**
10809 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10810 */
10811 // Used for SHELL command only right now.
10812 @Override
10813 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10814 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10815 "getLatestRcsContactUceCapabilityShell");
10816 final long identity = Binder.clearCallingIdentity();
10817 try {
10818 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10819 } catch (ImsException e) {
10820 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10821 } finally {
10822 Binder.restoreCallingIdentity(identity);
10823 }
10824 }
10825
10826 /**
10827 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10828 * device does not have an active PUBLISH.
10829 */
10830 // Used for SHELL command only right now.
10831 @Override
10832 public String getLastUcePidfXmlShell(int subId) {
10833 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10834 final long identity = Binder.clearCallingIdentity();
10835 try {
10836 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10837 } catch (ImsException e) {
10838 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10839 } finally {
10840 Binder.restoreCallingIdentity(identity);
10841 }
10842 }
10843
James.cf Line8713a42021-04-29 16:04:26 +080010844 /**
10845 * Remove UCE requests cannot be sent to the network status.
10846 */
10847 // Used for SHELL command only right now.
10848 @Override
10849 public boolean removeUceRequestDisallowedStatus(int subId) {
10850 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10851 final long identity = Binder.clearCallingIdentity();
10852 try {
10853 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10854 } catch (ImsException e) {
10855 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10856 } finally {
10857 Binder.restoreCallingIdentity(identity);
10858 }
10859 }
10860
James.cf Lin0fc71b02021-05-25 01:37:38 +080010861 /**
10862 * Remove UCE requests cannot be sent to the network status.
10863 */
10864 // Used for SHELL command only.
10865 @Override
10866 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10868 final long identity = Binder.clearCallingIdentity();
10869 try {
10870 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10871 } catch (ImsException e) {
10872 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10873 } finally {
10874 Binder.restoreCallingIdentity(identity);
10875 }
10876 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010877
James.cf Lin4b784aa2021-01-31 03:25:15 +080010878 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010879 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10880 String callingPackage) {
10881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10882 mApp, subId, "setSignalStrengthUpdateRequest");
10883
10884 final int callingUid = Binder.getCallingUid();
10885 // Verify that tha callingPackage belongs to the calling UID
10886 mApp.getSystemService(AppOpsManager.class)
10887 .checkPackage(callingUid, callingPackage);
10888
Rambo Wang3607f502021-02-01 21:51:40 -080010889 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010890
10891 final long identity = Binder.clearCallingIdentity();
10892 try {
10893 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10894 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10895
10896 if (result instanceof IllegalStateException) {
10897 throw (IllegalStateException) result;
10898 }
10899 } finally {
10900 Binder.restoreCallingIdentity(identity);
10901 }
10902 }
10903
10904 @Override
10905 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10906 String callingPackage) {
10907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10908 mApp, subId, "clearSignalStrengthUpdateRequest");
10909
10910 final int callingUid = Binder.getCallingUid();
10911 // Verify that tha callingPackage belongs to the calling UID
10912 mApp.getSystemService(AppOpsManager.class)
10913 .checkPackage(callingUid, callingPackage);
10914
10915 final long identity = Binder.clearCallingIdentity();
10916 try {
10917 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10918 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10919
10920 if (result instanceof IllegalStateException) {
10921 throw (IllegalStateException) result;
10922 }
10923 } finally {
10924 Binder.restoreCallingIdentity(identity);
10925 }
10926 }
10927
Rambo Wang3607f502021-02-01 21:51:40 -080010928 private static void validateSignalStrengthUpdateRequest(Context context,
10929 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010930 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10931 // phone/system process do not have further restriction on request
10932 return;
10933 }
10934
10935 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010936 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010937 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010938 context.enforceCallingOrSelfPermission(
10939 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10940 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010941 }
10942
10943 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10944 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10945 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10946 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10947 || info.isEnabled()) {
10948 throw new IllegalArgumentException(
10949 "Only system can set hide fields in SignalThresholdInfo");
10950 }
10951
10952 // Thresholds length for each RAN need in range. This has been validated in
10953 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10954 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10955 final int[] thresholds = info.getThresholds();
10956 Objects.requireNonNull(thresholds);
10957 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10958 || thresholds.length
10959 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10960 throw new IllegalArgumentException(
10961 "thresholds length is out of range: " + thresholds.length);
10962 }
10963 }
10964 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010965
10966 /**
10967 * Gets the current phone capability.
10968 *
10969 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10970 * @return the PhoneCapability which describes the data connection capability of modem.
10971 * It's used to evaluate possible phone config change, for example from single
10972 * SIM device to multi-SIM device.
10973 */
10974 @Override
10975 public PhoneCapability getPhoneCapability() {
10976 enforceReadPrivilegedPermission("getPhoneCapability");
10977 final long identity = Binder.clearCallingIdentity();
10978 try {
10979 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10980 } finally {
10981 Binder.restoreCallingIdentity(identity);
10982 }
10983 }
Michele Berionne5e411512020-11-13 02:36:59 +000010984
10985 /**
10986 * Prepare TelephonyManager for an unattended reboot. The reboot is
10987 * required to be done shortly after the API is invoked.
10988 */
10989 @Override
10990 @TelephonyManager.PrepareUnattendedRebootResult
10991 public int prepareForUnattendedReboot() {
10992 enforceRebootPermission();
10993
10994 final long identity = Binder.clearCallingIdentity();
10995 try {
10996 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10997 } finally {
10998 Binder.restoreCallingIdentity(identity);
10999 }
11000 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011001
11002 /**
11003 * Request to get the current slicing configuration including URSP rules and
11004 * NSSAIs (configured, allowed and rejected).
11005 *
11006 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11007 */
11008 @Override
11009 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011010 TelephonyPermissions
11011 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11012 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011013
11014 final long identity = Binder.clearCallingIdentity();
11015 try {
11016 Phone phone = getDefaultPhone();
11017 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11018 } finally {
11019 Binder.restoreCallingIdentity(identity);
11020 }
11021 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000011022
11023 /**
11024 * Register an IMS connection state callback
11025 */
11026 @Override
11027 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11028 String callingPackage) {
11029 if (feature == ImsFeature.FEATURE_MMTEL) {
11030 // ImsMmTelManager
11031 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11032 TelephonyPermissions
11033 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11034 mApp, subId, "registerImsStateCallback");
11035 } else if (feature == ImsFeature.FEATURE_RCS) {
11036 // ImsRcsManager or SipDelegateManager
11037 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11038 Binder.getCallingUid(), "registerImsStateCallback",
11039 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11040 Manifest.permission.READ_PRECISE_PHONE_STATE,
11041 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11042 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11043 }
11044
11045 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11046 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11047 "IMS not available on device.");
11048 }
11049
11050 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11051 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11052 }
11053
11054 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11055 if (controller == null) {
11056 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11057 "IMS not available on device.");
11058 }
11059
11060 if (callingPackage == null) {
11061 callingPackage = getCurrentPackageName();
11062 }
11063
11064 final long token = Binder.clearCallingIdentity();
11065 try {
11066 int slotId = getSlotIndexOrException(subId);
11067 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11068 } catch (ImsException e) {
11069 throw new ServiceSpecificException(e.getCode());
11070 } finally {
11071 Binder.restoreCallingIdentity(token);
11072 }
11073 }
11074
11075 /**
11076 * Unregister an IMS connection state callback
11077 */
11078 @Override
11079 public void unregisterImsStateCallback(IImsStateCallback cb) {
11080 final long token = Binder.clearCallingIdentity();
11081 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11082 if (controller == null) {
11083 return;
11084 }
11085 try {
11086 controller.unregisterImsStateCallback(cb);
11087 } finally {
11088 Binder.restoreCallingIdentity(token);
11089 }
11090 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011091
11092 /**
11093 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11094 *
11095 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11096 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11097 * SecurityException.
11098 * If there is current registered network this value will be same as the registered cell
11099 * identity. If the device goes out of service the previous cell identity is cached and
11100 * will be returned. If the cache age of the Cell identity is more than 24 hours
11101 * it will be cleared and null will be returned.
11102 *
11103 */
11104 @Override
11105 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11106 String callingFeatureId) {
11107 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11108 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11109 LocationAccessPolicy.checkLocationPermission(mApp,
11110 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11111 .setCallingPackage(callingPackage)
11112 .setCallingFeatureId(callingFeatureId)
11113 .setCallingPid(Binder.getCallingPid())
11114 .setCallingUid(Binder.getCallingUid())
11115 .setMethod("getLastKnownCellIdentity")
11116 .setLogAsInfo(true)
11117 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11118 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11119 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11120 .build());
11121
11122 boolean hasFinePermission =
11123 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11124 if (!hasFinePermission
11125 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11126 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11127 + "and BIND_CONNECTION_SERVICE permission.");
11128 }
11129
11130 final long identity = Binder.clearCallingIdentity();
11131 try {
11132 Phone phone = getPhone(subId);
11133 if (phone == null) return null;
11134 ServiceStateTracker sst = phone.getServiceStateTracker();
11135 if (sst == null) return null;
11136 return sst.getLastKnownCellIdentity();
11137 } finally {
11138 Binder.restoreCallingIdentity(identity);
11139 }
11140 }
jimsun38340bf2021-10-26 15:01:23 +080011141
11142 /**
11143 * Sets the modem service class Name that Telephony will bind to.
11144 *
11145 * @param serviceName The class name of the modem service.
11146 * @return true if the operation is succeed, otherwise false.
11147 */
11148 public boolean setModemService(String serviceName) {
11149 Log.d(LOG_TAG, "setModemService - " + serviceName);
11150 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11152 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11153 "setModemService");
11154 return mPhoneConfigurationManager.setModemService(serviceName);
11155 }
11156
11157 /**
11158 * Return the class name of the currently bounded modem service.
11159 *
11160 * @return the class name of the modem service.
11161 */
11162 public String getModemService() {
11163 String result;
11164 Log.d(LOG_TAG, "getModemService");
11165 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11166 TelephonyPermissions
11167 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11168 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11169 "getModemService");
11170 result = mPhoneConfigurationManager.getModemService();
11171 Log.d(LOG_TAG, "result = " + result);
11172 return result;
11173 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011174}