blob: d8848648b8e477c8ea703ac0f2db1677bb435028 [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
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006698 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006699 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006700 if (uid == Process.PHONE_UID) {
6701 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6702 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006703 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6704 }
6705
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006706 //load access rules from carrier configs, and check those as well: b/139133814
6707 SubscriptionController subController = SubscriptionController.getInstance();
6708 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6709 || subController == null) return privilegeFromSim;
6710
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006711 PackageManager pkgMgr = phone.getContext().getPackageManager();
6712 String[] packages = pkgMgr.getPackagesForUid(uid);
6713
6714 final long identity = Binder.clearCallingIdentity();
6715 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006716 int subId = phone.getSubId();
6717 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6718 // A test override is in place for the privileges for this subId, so don't try to
6719 // read the subscription privileges.
6720 return privilegeFromSim;
6721 }
6722 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006723 SubscriptionManager subManager = (SubscriptionManager)
6724 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6725 for (String pkg : packages) {
6726 if (subManager.canManageSubscription(subInfo, pkg)) {
6727 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6728 }
6729 }
6730 return privilegeFromSim;
6731 } finally {
6732 Binder.restoreCallingIdentity(identity);
6733 }
6734 }
6735
6736 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6737 String pkgName) {
6738 //load access rules from carrier configs, and check those as well: b/139133814
6739 SubscriptionController subController = SubscriptionController.getInstance();
6740 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6741 || subController == null) return privilegeFromSim;
6742
6743 final long identity = Binder.clearCallingIdentity();
6744 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006745 int subId = phone.getSubId();
6746 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6747 // A test override is in place for the privileges for this subId, so don't try to
6748 // read the subscription privileges.
6749 return privilegeFromSim;
6750 }
6751 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006752 SubscriptionManager subManager = (SubscriptionManager)
6753 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6754 return subManager.canManageSubscription(subInfo, pkgName)
6755 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6756 } finally {
6757 Binder.restoreCallingIdentity(identity);
6758 }
6759 }
6760
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006761 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006762 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006763 // No permission needed; this only lets the caller inspect their own status.
6764 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006765 }
Junda Liu29340342014-07-10 15:23:27 -07006766
6767 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006768 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006769 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006770 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6771 }
6772
6773 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6774 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006775 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006776 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006777 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6778 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006779 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6780 if (cpt == null) {
6781 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006782 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6783 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006784 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006785 }
6786
6787 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006788 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006789 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006790 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006791 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006792 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006793 Phone phone = getPhone(subId);
6794 if (phone == null) {
6795 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6796 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6797 }
6798 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6799 if (cpt == null) {
6800 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006801 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6802 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006803 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006804 }
6805
6806 @Override
6807 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006808 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
6809 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006810 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006811 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006812 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006813 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6814 Phone phone = PhoneFactory.getPhone(phoneId);
6815 if (phone == null) {
6816 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006817 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006818 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6819 if (cpt == null) {
6820 continue;
6821 }
6822 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006823 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6824 break;
6825 }
6826 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006827 return result;
Junda Liu29340342014-07-10 15:23:27 -07006828 }
Derek Tan89e89d42014-07-08 17:00:10 -07006829
6830 @Override
Junda Liue64de782015-04-16 17:19:16 -07006831 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006832 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006833 Phone phone = PhoneFactory.getPhone(phoneId);
6834 if (phone == null) {
6835 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006836 }
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006837 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6838 if (cpt == null) {
6839 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006840 }
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006841 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006842 }
6843
Amith Yamasani6e118872016-02-19 12:53:51 -08006844 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006845 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006846 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006847 Phone phone = PhoneFactory.getPhone(phoneId);
6848 if (phone == null) {
6849 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006850 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006851 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6852 if (cpt == null) {
6853 return Collections.emptyList();
6854 }
6855 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006856 }
6857
chen xuf7e9fe82019-05-09 19:31:02 -07006858 @Override
6859 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006860 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006861 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006862 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006863 try {
6864 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6865 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6866 }
6867 } finally {
6868 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006869 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006870 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006871 }
6872
Wink Savilleb564aae2014-10-23 10:18:09 -07006873 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006874 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006875 UiccPort port = phone == null ? null : phone.getUiccPort();
6876 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006877 return null;
6878 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006879 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006880 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006881 return null;
6882 }
6883 return iccId;
6884 }
6885
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006886 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006887 public void setCallComposerStatus(int subId, int status) {
6888 enforceModifyPermission();
6889
6890 final long identity = Binder.clearCallingIdentity();
6891 try {
6892 Phone phone = getPhone(subId);
6893 if (phone != null) {
6894 Phone defaultPhone = phone.getImsPhone();
6895 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6896 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6897 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006898 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6899 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006900 }
6901 }
Shuo Qian284ae752020-12-22 19:10:14 -08006902 } catch (ImsException e) {
6903 throw new ServiceSpecificException(e.getCode());
6904 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006905 Binder.restoreCallingIdentity(identity);
6906 }
6907 }
6908
6909 @Override
6910 public int getCallComposerStatus(int subId) {
6911 enforceReadPrivilegedPermission("getCallComposerStatus");
6912
6913 final long identity = Binder.clearCallingIdentity();
6914 try {
6915 Phone phone = getPhone(subId);
6916 if (phone != null) {
6917 Phone defaultPhone = phone.getImsPhone();
6918 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6919 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6920 return imsPhone.getCallComposerStatus();
6921 }
6922 }
6923 } finally {
6924 Binder.restoreCallingIdentity(identity);
6925 }
6926 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6927 }
6928
6929 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006930 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6931 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006932 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006933 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006935 final long identity = Binder.clearCallingIdentity();
6936 try {
6937 final String iccId = getIccId(subId);
6938 final Phone phone = getPhone(subId);
6939 if (phone == null) {
6940 return false;
6941 }
6942 final String subscriberId = phone.getSubscriberId();
6943
6944 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006945 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006946 + subscriberId + " to " + number);
6947 }
6948
6949 if (TextUtils.isEmpty(iccId)) {
6950 return false;
6951 }
6952
6953 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6954
6955 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6956 if (alphaTag == null) {
6957 editor.remove(alphaTagPrefKey);
6958 } else {
6959 editor.putString(alphaTagPrefKey, alphaTag);
6960 }
6961
6962 // Record both the line number and IMSI for this ICCID, since we need to
6963 // track all merged IMSIs based on line number
6964 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6965 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6966 if (number == null) {
6967 editor.remove(numberPrefKey);
6968 editor.remove(subscriberPrefKey);
6969 } else {
6970 editor.putString(numberPrefKey, number);
6971 editor.putString(subscriberPrefKey, subscriberId);
6972 }
6973
6974 editor.commit();
6975 return true;
6976 } finally {
6977 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006978 }
Derek Tan7226c842014-07-02 17:42:23 -07006979 }
6980
6981 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006982 public String getLine1NumberForDisplay(int subId, String callingPackage,
6983 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006984 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006986 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006987 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006988 return null;
6989 }
Derek Tan97ebb422014-09-05 16:55:38 -07006990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006991 final long identity = Binder.clearCallingIdentity();
6992 try {
6993 String iccId = getIccId(subId);
6994 if (iccId != null) {
6995 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6996 if (DBG_MERGE) {
6997 log("getLine1NumberForDisplay returning "
6998 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6999 }
7000 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7003 return null;
7004 } finally {
7005 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007006 }
Derek Tan7226c842014-07-02 17:42:23 -07007007 }
7008
7009 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007010 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7011 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007013 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007014 return null;
7015 }
Derek Tan97ebb422014-09-05 16:55:38 -07007016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007017 final long identity = Binder.clearCallingIdentity();
7018 try {
7019 String iccId = getIccId(subId);
7020 if (iccId != null) {
7021 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7022 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7023 }
7024 return null;
7025 } finally {
7026 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007027 }
Derek Tan7226c842014-07-02 17:42:23 -07007028 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007029
7030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007031 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7032 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007033 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7034 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007036 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007037 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007038 return null;
7039 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007040
Jordan Liub49b04b2019-05-06 14:45:15 -07007041 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7042 // the process, where TelephonyManager was instantiated.
7043 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007044 final long identity = Binder.clearCallingIdentity();
7045 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007046 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007047 final TelephonyManager tele = TelephonyManager.from(context);
7048 final SubscriptionManager sub = SubscriptionManager.from(context);
7049
7050 // Figure out what subscribers are currently active
7051 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052
Jordan Liub49b04b2019-05-06 14:45:15 -07007053 // Only consider subs which match the current subId
7054 // This logic can be simplified. See b/131189269 for progress.
7055 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007056 activeSubscriberIds.add(tele.getSubscriberId(subId));
7057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058
7059 // First pass, find a number override for an active subscriber
7060 String mergeNumber = null;
7061 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7062 for (String key : prefs.keySet()) {
7063 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7064 final String subscriberId = (String) prefs.get(key);
7065 if (activeSubscriberIds.contains(subscriberId)) {
7066 final String iccId = key.substring(
7067 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7068 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7069 mergeNumber = (String) prefs.get(numberKey);
7070 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007071 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 + " for active subscriber " + subscriberId);
7073 }
7074 if (!TextUtils.isEmpty(mergeNumber)) {
7075 break;
7076 }
7077 }
7078 }
7079 }
7080
7081 // Shortcut when no active merged subscribers
7082 if (TextUtils.isEmpty(mergeNumber)) {
7083 return null;
7084 }
7085
7086 // Second pass, find all subscribers under that line override
7087 final ArraySet<String> result = new ArraySet<>();
7088 for (String key : prefs.keySet()) {
7089 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7090 final String number = (String) prefs.get(key);
7091 if (mergeNumber.equals(number)) {
7092 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7093 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7094 final String subscriberId = (String) prefs.get(subscriberKey);
7095 if (!TextUtils.isEmpty(subscriberId)) {
7096 result.add(subscriberId);
7097 }
7098 }
7099 }
7100 }
7101
7102 final String[] resultArray = result.toArray(new String[result.size()]);
7103 Arrays.sort(resultArray);
7104 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007105 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7107 }
7108 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007109 } finally {
7110 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007111 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007112 }
7113
7114 @Override
zoey chen38003472019-12-13 17:16:31 +08007115 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7116 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007117
7118 final long identity = Binder.clearCallingIdentity();
7119 try {
7120 final TelephonyManager telephonyManager = mApp.getSystemService(
7121 TelephonyManager.class);
7122 String subscriberId = telephonyManager.getSubscriberId(subId);
7123 if (subscriberId == null) {
7124 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007125 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007126 + subId);
7127 }
7128 return null;
7129 }
7130
7131 final SubscriptionInfo info = SubscriptionController.getInstance()
7132 .getSubscriptionInfo(subId);
7133 final ParcelUuid groupUuid = info.getGroupUuid();
7134 // If it doesn't belong to any group, return just subscriberId of itself.
7135 if (groupUuid == null) {
7136 return new String[]{subscriberId};
7137 }
7138
7139 // Get all subscriberIds from the group.
7140 final List<String> mergedSubscriberIds = new ArrayList<>();
7141 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007142 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007143 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007144 for (SubscriptionInfo subInfo : groupInfos) {
7145 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7146 if (subscriberId != null) {
7147 mergedSubscriberIds.add(subscriberId);
7148 }
7149 }
7150
7151 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7152 } finally {
7153 Binder.restoreCallingIdentity(identity);
7154
7155 }
7156 }
7157
7158 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007159 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007160 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007161 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162
7163 final long identity = Binder.clearCallingIdentity();
7164 try {
7165 final Phone phone = getPhone(subId);
7166 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7167 } finally {
7168 Binder.restoreCallingIdentity(identity);
7169 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007170 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007171
7172 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007173 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007174 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7175 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007176 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7177 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178
7179 final long identity = Binder.clearCallingIdentity();
7180 try {
7181 final Phone phone = getPhone(subId);
7182 if (phone == null) {
7183 return false;
7184 }
7185 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7186 cdmaNonRoamingList);
7187 } finally {
7188 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007189 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007190 }
7191
7192 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007193 @Deprecated
7194 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7195 enforceModifyPermission();
7196
7197 int returnValue = 0;
7198 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007199 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007200 if(result.exception == null) {
7201 if (result.result != null) {
7202 byte[] responseData = (byte[])(result.result);
7203 if(responseData.length > oemResp.length) {
7204 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7205 responseData.length + "bytes. Buffer Size is " +
7206 oemResp.length + "bytes.");
7207 }
7208 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7209 returnValue = responseData.length;
7210 }
7211 } else {
7212 CommandException ex = (CommandException) result.exception;
7213 returnValue = ex.getCommandError().ordinal();
7214 if(returnValue > 0) returnValue *= -1;
7215 }
7216 } catch (RuntimeException e) {
7217 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7218 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7219 if(returnValue > 0) returnValue *= -1;
7220 }
7221
7222 return returnValue;
7223 }
7224
7225 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007226 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007227 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007228 try {
7229 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007230 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007231 mApp, phone.getSubId(), "getRadioAccessFamily");
7232 } catch (SecurityException e) {
7233 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7234 throw e;
7235 }
chen xub97461a2018-10-26 14:17:57 -07007236 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007237 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007238 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240 final long identity = Binder.clearCallingIdentity();
7241 try {
chen xub97461a2018-10-26 14:17:57 -07007242 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007243 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007244 mApp, phone.getSubId(), "getRadioAccessFamily");
7245 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246 } finally {
7247 Binder.restoreCallingIdentity(identity);
7248 }
chen xub97461a2018-10-26 14:17:57 -07007249 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007250 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007251
7252 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007253 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007254 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007255 try {
7256 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7257 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007258 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007259 }
7260 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007261 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007262 }
7263 RoleManager rm = mApp.getSystemService(RoleManager.class);
7264 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7265 if (!dialerRoleHolders.contains(callingPackage)) {
7266 throw new SecurityException("App must be the dialer role holder to"
7267 + " upload a call composer pic");
7268 }
7269
7270 Executors.newSingleThreadExecutor().execute(() -> {
7271 ByteArrayOutputStream output = new ByteArrayOutputStream(
7272 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7273 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7274 boolean readUntilEnd = false;
7275 int totalBytesRead = 0;
7276 byte[] buffer = new byte[16 * 1024];
7277 while (true) {
7278 int numRead;
7279 try {
7280 numRead = input.read(buffer);
7281 } catch (IOException e) {
7282 try {
7283 fd.checkError();
7284 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7285 null);
7286 } catch (IOException e1) {
7287 // This means that the other side closed explicitly with an error. If this
7288 // happens, log and ignore.
7289 loge("Remote end of call composer picture pipe closed: " + e1);
7290 }
7291 break;
7292 }
7293 if (numRead == -1) {
7294 readUntilEnd = true;
7295 break;
7296 }
7297 totalBytesRead += numRead;
7298 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7299 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7300 try {
7301 input.close();
7302 } catch (IOException e) {
7303 // ignore
7304 }
7305 break;
7306 }
7307 output.write(buffer, 0, numRead);
7308 }
7309 // Generally, the remote end will close the file descriptors. The only case where we
7310 // close is above, where the picture size is too big.
7311
7312 try {
7313 fd.checkError();
7314 } catch (IOException e) {
7315 loge("Remote end for call composer closed with an error: " + e);
7316 return;
7317 }
7318
Hall Liuaa4211e2021-01-20 15:43:39 -08007319 if (!readUntilEnd) {
7320 loge("Did not finish reading entire image; aborting");
7321 return;
7322 }
Hall Liu82694d52020-12-11 18:22:04 -08007323
Hall Liuaa4211e2021-01-20 15:43:39 -08007324 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7325 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7326 new CallComposerPictureTransfer.Factory() {},
7327 imageData,
7328 (result) -> {
7329 if (result.first != null) {
7330 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7331 Bundle outputResult = new Bundle();
7332 outputResult.putParcelable(
7333 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7334 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7335 outputResult);
7336 } else {
7337 callback.send(result.second, null);
7338 }
7339 }
7340 );
Hall Liu82694d52020-12-11 18:22:04 -08007341 });
7342 }
7343
7344 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007345 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007346 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007347 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007348
7349 final long identity = Binder.clearCallingIdentity();
7350 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007351 ImsManager.getInstance(defaultPhone.getContext(),
7352 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007353 } finally {
7354 Binder.restoreCallingIdentity(identity);
7355 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007356 }
7357
7358 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007359 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007360 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007361 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7362 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007363 return false;
7364 }
Svet Ganovb320e182015-04-16 12:30:10 -07007365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 final long identity = Binder.clearCallingIdentity();
7367 try {
7368 // Check the user preference and the system-level IMS setting. Even if the user has
7369 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7370 // In the long run, we may instead need to check if there exists a connection service
7371 // which can support video calling.
7372 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007373 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 return imsManager.isVtEnabledByPlatform()
7375 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7376 && imsManager.isVtEnabledByUser();
7377 } finally {
7378 Binder.restoreCallingIdentity(identity);
7379 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007380 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007381
Andrew Leea1239f22015-03-02 17:44:07 -08007382 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007383 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7384 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007386 mApp, subId, callingPackage, callingFeatureId,
7387 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 return false;
7389 }
7390
7391 final long identity = Binder.clearCallingIdentity();
7392 try {
7393 CarrierConfigManager configManager =
7394 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007395 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7397 } finally {
7398 Binder.restoreCallingIdentity(identity);
7399 }
Andrew Leea1239f22015-03-02 17:44:07 -08007400 }
7401
7402 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007403 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007405 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 return false;
7407 }
7408
7409 final long identity = Binder.clearCallingIdentity();
7410 try {
7411 CarrierConfigManager configManager =
7412 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007413 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007414 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
Andrew Leea1239f22015-03-02 17:44:07 -08007418 }
7419
Andrew Lee9431b832015-03-09 18:46:45 -07007420 @Override
7421 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007422 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007423 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007424 }
7425
7426 @Override
7427 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 final long identity = Binder.clearCallingIdentity();
7429 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007430 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431 } finally {
7432 Binder.restoreCallingIdentity(identity);
7433 }
Andrew Lee9431b832015-03-09 18:46:45 -07007434 }
7435
Hall Liuf6668912018-10-31 17:05:23 -07007436 /**
7437 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7438 * support for the feature and device firmware support.
7439 *
7440 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7441 */
7442 @Override
7443 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007445 final Phone phone = getPhone(subscriptionId);
7446 if (phone == null) {
7447 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7448 return false;
7449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007451 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7453 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007454 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007455 return isCarrierSupported && isDeviceSupported;
7456 } finally {
7457 Binder.restoreCallingIdentity(identity);
7458 }
Hall Liu98187582018-01-22 19:15:32 -08007459 }
7460
Hall Liuf6668912018-10-31 17:05:23 -07007461 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007462 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7463 * RTT setting, will return true if the device and carrier both support RTT.
7464 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007465 */
7466 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 final long identity = Binder.clearCallingIdentity();
7468 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007469 boolean isRttSupported = isRttSupported(subscriptionId);
7470 boolean isUserRttSettingOn = Settings.Secure.getInt(
7471 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7472 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7473 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7474 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475 } finally {
7476 Binder.restoreCallingIdentity(identity);
7477 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007478 }
7479
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007480 @Deprecated
7481 @Override
7482 public String getDeviceId(String callingPackage) {
7483 return getDeviceIdWithFeature(callingPackage, null);
7484 }
7485
Sanket Padawe7310cc72015-01-14 09:53:20 -08007486 /**
7487 * Returns the unique device ID of phone, for example, the IMEI for
7488 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7489 *
7490 * <p>Requires Permission:
7491 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7492 */
7493 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007494 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007495 try {
7496 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7497 } catch (SecurityException se) {
7498 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7499 throw new SecurityException("Package " + callingPackage + " does not belong to "
7500 + Binder.getCallingUid());
7501 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007502 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007503 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007504 return null;
7505 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007506 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007507 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007508 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007509 return null;
7510 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511
7512 final long identity = Binder.clearCallingIdentity();
7513 try {
7514 return phone.getDeviceId();
7515 } finally {
7516 Binder.restoreCallingIdentity(identity);
7517 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007518 }
7519
Ping Sunc67b7c22016-03-02 19:16:45 +08007520 /**
7521 * {@hide}
7522 * Returns the IMS Registration Status on a particular subid
7523 *
7524 * @param subId
7525 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007526 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007527 Phone phone = getPhone(subId);
7528 if (phone != null) {
7529 return phone.isImsRegistered();
7530 } else {
7531 return false;
7532 }
7533 }
7534
Santos Cordon7a1885b2015-02-03 11:15:19 -08007535 @Override
7536 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 final long identity = Binder.clearCallingIdentity();
7538 try {
7539 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7540 } finally {
7541 Binder.restoreCallingIdentity(identity);
7542 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007543 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007544
Tyler Gunnf70ed162019-04-03 15:28:53 -07007545 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007546 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007547 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007549 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007550 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7551 }
7552 final long identity = Binder.clearCallingIdentity();
7553 try {
7554 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7555 } finally {
7556 Binder.restoreCallingIdentity(identity);
7557 }
7558 }
7559
7560 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007561 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007562 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007563 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007564 mApp,
7565 subscriptionId,
7566 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007567 final long identity = Binder.clearCallingIdentity();
7568 try {
7569 Phone phone = getPhone(subscriptionId);
7570 if (phone == null) {
7571 return null;
7572 }
7573 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7574 } finally {
7575 Binder.restoreCallingIdentity(identity);
7576 }
7577 }
7578
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007579 /**
7580 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007581 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007582 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 final long identity = Binder.clearCallingIdentity();
7584 try {
7585 Phone phone = getPhone(subId);
7586 if (phone != null) {
7587 return phone.isWifiCallingEnabled();
7588 } else {
7589 return false;
7590 }
7591 } finally {
7592 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007593 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007594 }
7595
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007596 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007597 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007598 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007599 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 final long identity = Binder.clearCallingIdentity();
7601 try {
7602 Phone phone = getPhone(subId);
7603 if (phone != null) {
7604 return phone.isVideoEnabled();
7605 } else {
7606 return false;
7607 }
7608 } finally {
7609 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007610 }
7611 }
7612
7613 /**
7614 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7615 * defined in {@link ImsRegistrationImplBase}.
7616 */
7617 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007618 final long identity = Binder.clearCallingIdentity();
7619 try {
7620 Phone phone = getPhone(subId);
7621 if (phone != null) {
7622 return phone.getImsRegistrationTech();
7623 } else {
7624 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7625 }
7626 } finally {
7627 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007628 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007629 }
7630
Stuart Scott8eef64f2015-04-08 15:13:54 -07007631 @Override
7632 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007633 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007634 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7635 return;
7636 }
Kai Shif70f46f2021-03-03 13:59:46 -08007637 Phone defaultPhone = getDefaultPhone();
7638 if (defaultPhone != null) {
7639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7640 mApp, getDefaultPhone().getSubId(), "factoryReset");
7641 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007642 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007643
Svet Ganovcc087f82015-05-12 20:35:54 -07007644 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007645 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7646 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007647 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007648 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007649 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007650 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007651 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007652 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007653 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007654 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007655 // There has been issues when Sms raw table somehow stores orphan
7656 // fragments. They lead to garbled message when new fragments come
7657 // in and combined with those stale ones. In case this happens again,
7658 // user can reset all network settings which will clean up this table.
7659 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007660 // Clean up IMS settings as well here.
7661 int slotId = getSlotIndex(subId);
7662 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7663 ImsManager.getInstance(mApp, slotId).factoryReset();
7664 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007665
Kai Shif70f46f2021-03-03 13:59:46 -08007666 if (defaultPhone == null) {
7667 return;
7668 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007669 // Erase modem config if erase modem on network setting is enabled.
7670 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7671 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7672 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007673 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007674 }
Kai Shif70f46f2021-03-03 13:59:46 -08007675
7676 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007677 } finally {
7678 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007679 }
7680 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007681
SongFerngWangfd89b102021-05-27 22:44:54 +08007682 @VisibleForTesting
7683 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7684 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7685 return;
7686 }
7687 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7688 RILConstants.PREFERRED_NETWORK_MODE);
7689 SubscriptionManager.setSubscriptionProperty(subId,
7690 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7691 "user=" + defaultNetworkType);
7692 phone.loadAllowedNetworksFromSubscriptionDatabase();
7693 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7694 defaultNetworkType, null);
7695 }
7696
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007697 private void cleanUpSmsRawTable(Context context) {
7698 ContentResolver resolver = context.getContentResolver();
7699 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7700 resolver.delete(uri, null, null);
7701 }
7702
Narayan Kamath1c496c22015-04-16 14:40:19 +01007703 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007704 public String getSimLocaleForSubscriber(int subId) {
7705 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7706 final Phone phone = getPhone(subId);
7707 if (phone == null) {
7708 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007709 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007710 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007711 final long identity = Binder.clearCallingIdentity();
7712 try {
chen xu5d3637b2019-01-21 23:31:38 -08007713 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007714 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007715 if (info == null) {
7716 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7717 return null;
7718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719 // Try and fetch the locale from the carrier properties or from the SIM language
7720 // preferences (EF-PL and EF-LI)...
7721 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007723 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7724 if (localeFromDefaultSim != null) {
7725 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7726 if (DBG) log("Using locale from subId: " + subId + " locale: "
7727 + localeFromDefaultSim);
7728 return localeFromDefaultSim.toLanguageTag();
7729 } else {
7730 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 }
7732 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 // The SIM language preferences only store a language (e.g. fr = French), not an
7735 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7736 // the SIM and carrier preferences does not include a country we add the country
7737 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007738 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007739 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007740 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007741 return mccLocale.toLanguageTag();
7742 }
7743
7744 if (DBG) log("No locale found - returning null");
7745 return null;
7746 } finally {
7747 Binder.restoreCallingIdentity(identity);
7748 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007749 }
7750
7751 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007752 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007753 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007754 }
7755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756 /**
7757 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7758 */
7759 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007760 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007761 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007762 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007763
Chenjie Yu1ba97252018-01-11 18:16:20 -08007764 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007765 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007766
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007767 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007768 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7769 * representing the state of the modem.
7770 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007771 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7772 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007773 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007774 */
7775 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007776 public void requestModemActivityInfo(ResultReceiver result) {
7777 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007778 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779
7780 final long identity = Binder.clearCallingIdentity();
7781 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007782 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007783 } finally {
7784 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007785 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007786 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007787
Siddharth Rayb8114062018-06-17 15:02:38 -07007788 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7789 // less than total activity duration.
7790 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7791 if (info == null) {
7792 return false;
7793 }
7794 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007795 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7796 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7797
Siddharth Rayb8114062018-06-17 15:02:38 -07007798 return (info.isValid()
7799 && (info.getSleepTimeMillis() <= activityDurationMs)
7800 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007801 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007802 && (totalTxTimeMs <= activityDurationMs));
7803 }
7804
Jack Yu85bd38a2015-11-09 11:34:32 -08007805 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007806 * Returns the service state information on specified subscription.
7807 */
7808 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007809 public ServiceState getServiceStateForSubscriber(int subId,
7810 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7811 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007812 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007813 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007814 return null;
7815 }
7816
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007817 boolean hasFinePermission = false;
7818 boolean hasCoarsePermission = false;
7819 if (!renounceFineLocationAccess) {
7820 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7821 LocationAccessPolicy.checkLocationPermission(mApp,
7822 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7823 .setCallingPackage(callingPackage)
7824 .setCallingFeatureId(callingFeatureId)
7825 .setCallingPid(Binder.getCallingPid())
7826 .setCallingUid(Binder.getCallingUid())
7827 .setMethod("getServiceStateForSubscriber")
7828 .setLogAsInfo(true)
7829 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7830 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7831 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7832 .build());
7833 hasFinePermission =
7834 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7835 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007836
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007837 if (!renounceCoarseLocationAccess) {
7838 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7839 LocationAccessPolicy.checkLocationPermission(mApp,
7840 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7841 .setCallingPackage(callingPackage)
7842 .setCallingFeatureId(callingFeatureId)
7843 .setCallingPid(Binder.getCallingPid())
7844 .setCallingUid(Binder.getCallingUid())
7845 .setMethod("getServiceStateForSubscriber")
7846 .setLogAsInfo(true)
7847 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7848 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7849 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7850 .build());
7851 hasCoarsePermission =
7852 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7853 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007854
Jack Yu479f40e2020-10-27 21:29:25 -07007855 final Phone phone = getPhone(subId);
7856 if (phone == null) {
7857 return null;
7858 }
7859
Jordan Liu0f2bc442020-11-18 16:47:37 -08007860 final long identity = Binder.clearCallingIdentity();
7861
Jack Yu479f40e2020-10-27 21:29:25 -07007862 boolean isCallingPackageDataService = phone.getDataServicePackages()
7863 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007865 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7866 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7867 Rlog.d(LOG_TAG,
7868 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7869 return null;
7870 }
7871
Hall Liuf19c44f2018-11-27 14:38:17 -08007872 ServiceState ss = phone.getServiceState();
7873
7874 // Scrub out the location info in ServiceState depending on what level of access
7875 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007876 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007877 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7878 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007879 } finally {
7880 Binder.restoreCallingIdentity(identity);
7881 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007882 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007883
7884 /**
7885 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7886 *
7887 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7888 * voicemail ringtone.
7889 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7890 * PhoneAccount.
7891 */
7892 @Override
7893 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007894 final long identity = Binder.clearCallingIdentity();
7895 try {
7896 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7897 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007898 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007899 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7902 } finally {
7903 Binder.restoreCallingIdentity(identity);
7904 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007905 }
7906
7907 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007908 * Sets the per-account voicemail ringtone.
7909 *
7910 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7911 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7912 *
7913 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7914 * voicemail ringtone.
7915 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7916 * PhoneAccount.
7917 */
7918 @Override
7919 public void setVoicemailRingtoneUri(String callingPackage,
7920 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007921 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007922 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007923 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7924 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7926 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7927 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007928 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007929
7930 final long identity = Binder.clearCallingIdentity();
7931 try {
7932 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7933 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007934 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 }
7936 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7937 } finally {
7938 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007939 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007940 }
7941
7942 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007943 * Returns whether vibration is set for voicemail notification in Phone settings.
7944 *
7945 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7946 * voicemail vibration setting.
7947 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7948 */
7949 @Override
7950 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951 final long identity = Binder.clearCallingIdentity();
7952 try {
7953 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7954 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007955 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007956 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7959 } finally {
7960 Binder.restoreCallingIdentity(identity);
7961 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007962 }
7963
Youhan Wange64578a2016-05-02 15:32:42 -07007964 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007965 * Sets the per-account voicemail vibration.
7966 *
7967 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7968 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7969 *
7970 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7971 * voicemail vibration setting.
7972 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7973 * specific PhoneAccount.
7974 */
7975 @Override
7976 public void setVoicemailVibrationEnabled(String callingPackage,
7977 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007978 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007979 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007980 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7981 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7983 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7984 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007985 }
7986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987 final long identity = Binder.clearCallingIdentity();
7988 try {
7989 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7990 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007991 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992 }
7993 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7994 } finally {
7995 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007996 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007997 }
7998
7999 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008000 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8001 *
8002 * @throws SecurityException if the caller does not have the required permission
8003 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008004 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008005 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008006 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008007 }
8008
8009 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008010 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8011 * permission.
8012 *
8013 * @throws SecurityException if the caller does not have the required permission
8014 */
8015 private void enforceSendSmsPermission() {
8016 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8017 }
8018
8019 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008020 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008021 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008022 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008023 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008024 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008025 final long identity = Binder.clearCallingIdentity();
8026 try {
8027 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008028 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008029 if (componentName == null) {
8030 throw new SecurityException(
8031 "Caller not current active visual voicemail package[null]");
8032 }
8033 String vvmPackage = componentName.getPackageName();
8034 if (!callingPackage.equals(vvmPackage)) {
8035 throw new SecurityException("Caller not current active visual voicemail package["
8036 + vvmPackage + "]");
8037 }
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008040 }
8041 }
8042
8043 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008044 * Return the application ID for the app type.
8045 *
8046 * @param subId the subscription ID that this request applies to.
8047 * @param appType the uicc app type.
8048 * @return Application ID for specificied app type, or null if no uicc.
8049 */
8050 @Override
8051 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008052 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008053 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054
8055 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008056 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008057 if (phone == null) {
8058 return null;
8059 }
8060 String aid = null;
8061 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008062 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063 .getApplicationByType(appType).getAid();
8064 } catch (Exception e) {
8065 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8066 }
8067 return aid;
8068 } finally {
8069 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008070 }
Youhan Wange64578a2016-05-02 15:32:42 -07008071 }
8072
Youhan Wang4001d252016-05-11 10:29:41 -07008073 /**
8074 * Return the Electronic Serial Number.
8075 *
8076 * @param subId the subscription ID that this request applies to.
8077 * @return ESN or null if error.
8078 */
8079 @Override
8080 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008081 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008082 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083
8084 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008085 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086 if (phone == null) {
8087 return null;
8088 }
8089 String esn = null;
8090 try {
8091 esn = phone.getEsn();
8092 } catch (Exception e) {
8093 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8094 }
8095 return esn;
8096 } finally {
8097 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008098 }
Youhan Wang4001d252016-05-11 10:29:41 -07008099 }
8100
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008101 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008102 * Return the Preferred Roaming List Version.
8103 *
8104 * @param subId the subscription ID that this request applies to.
8105 * @return PRLVersion or null if error.
8106 */
8107 @Override
8108 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008109 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008110 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111
8112 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008113 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008114 if (phone == null) {
8115 return null;
8116 }
8117 String cdmaPrlVersion = null;
8118 try {
8119 cdmaPrlVersion = phone.getCdmaPrlVersion();
8120 } catch (Exception e) {
8121 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8122 }
8123 return cdmaPrlVersion;
8124 } finally {
8125 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008126 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008127 }
8128
8129 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008130 * Get snapshot of Telephony histograms
8131 * @return List of Telephony histograms
8132 * @hide
8133 */
8134 @Override
8135 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8137 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008138
8139 final long identity = Binder.clearCallingIdentity();
8140 try {
8141 return RIL.getTelephonyRILTimingHistograms();
8142 } finally {
8143 Binder.restoreCallingIdentity(identity);
8144 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008145 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008146
8147 /**
8148 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008149 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8150 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008151 * Require system privileges. In the future we may add this to carrier APIs.
8152 *
Michele Berionne482f8202018-11-27 18:57:59 -08008153 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008154 */
8155 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008156 @TelephonyManager.SetCarrierRestrictionResult
8157 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008158 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008159 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008160
Michele Berionne482f8202018-11-27 18:57:59 -08008161 if (carrierRestrictionRules == null) {
8162 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008163 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008165 final long identity = Binder.clearCallingIdentity();
8166 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008167 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008168 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008169 } finally {
8170 Binder.restoreCallingIdentity(identity);
8171 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008172 }
8173
8174 /**
8175 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008176 * Get the allowed carrier list and the excluded carrier list, including the priority between
8177 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008178 * Require system privileges. In the future we may add this to carrier APIs.
8179 *
Michele Berionne482f8202018-11-27 18:57:59 -08008180 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008181 */
8182 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008183 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008184 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008185 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008186
8187 final long identity = Binder.clearCallingIdentity();
8188 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008189 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8190 if (response instanceof CarrierRestrictionRules) {
8191 return (CarrierRestrictionRules) response;
8192 }
8193 // Response is an Exception of some kind,
8194 // which is signalled to the user as a NULL retval
8195 return null;
8196 } catch (Exception e) {
8197 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8198 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008199 } finally {
8200 Binder.restoreCallingIdentity(identity);
8201 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008202 }
8203
fionaxu59545b42016-05-25 15:53:37 -07008204 /**
fionaxu59545b42016-05-25 15:53:37 -07008205 * Action set from carrier signalling broadcast receivers to enable/disable radio
8206 * @param subId the subscription ID that this action applies to.
8207 * @param enabled control enable or disable radio.
8208 * {@hide}
8209 */
8210 @Override
8211 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8212 enforceModifyPermission();
8213 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214
8215 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008216 if (phone == null) {
8217 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8218 return;
8219 }
8220 try {
8221 phone.carrierActionSetRadioEnabled(enabled);
8222 } catch (Exception e) {
8223 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 } finally {
8225 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008226 }
8227 }
8228
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008229 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008230 * Enable or disable Voice over NR (VoNR)
8231 * @param subId the subscription ID that this action applies to.
8232 * @param enabled enable or disable VoNR.
8233 * @return operation result.
8234 */
8235 @Override
8236 public int setVoNrEnabled(int subId, boolean enabled) {
8237 enforceModifyPermission();
8238 final Phone phone = getPhone(subId);
8239
8240 final long identity = Binder.clearCallingIdentity();
8241 if (phone == null) {
8242 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8243 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8244 }
8245
8246 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8247 try {
8248 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8249 workSource);
8250 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008251
8252 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8253 if (DBG) {
8254 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8255 }
8256 SubscriptionManager.setSubscriptionProperty(
8257 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8258 (enabled ? "1" : "0"));
8259 }
8260
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008261 return result;
8262 } finally {
8263 Binder.restoreCallingIdentity(identity);
8264 }
8265 }
8266
8267 /**
8268 * Is voice over NR enabled
8269 * @return true if VoNR is enabled else false
8270 */
8271 @Override
8272 public boolean isVoNrEnabled(int subId) {
8273 enforceReadPrivilegedPermission("isVoNrEnabled");
8274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8275 final long identity = Binder.clearCallingIdentity();
8276 try {
8277 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8278 null, subId, workSource);
8279 if (DBG) log("isVoNrEnabled: " + isEnabled);
8280 return isEnabled;
8281 } finally {
8282 Binder.restoreCallingIdentity(identity);
8283 }
8284 }
8285
8286 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008287 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8288 * network status based on which carrier apps could apply actions accordingly,
8289 * enable/disable default url handler for example.
8290 *
8291 * @param subId the subscription ID that this action applies to.
8292 * @param report control start/stop reporting the default network status.
8293 * {@hide}
8294 */
8295 @Override
8296 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8297 enforceModifyPermission();
8298 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299
8300 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008301 if (phone == null) {
8302 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8303 return;
8304 }
8305 try {
8306 phone.carrierActionReportDefaultNetworkStatus(report);
8307 } catch (Exception e) {
8308 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309 } finally {
8310 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008311 }
8312 }
8313
8314 /**
fionaxud9622282017-07-17 17:51:30 -07008315 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8316 * @param subId the subscription ID that this action applies to.
8317 * {@hide}
8318 */
8319 @Override
8320 public void carrierActionResetAll(int subId) {
8321 enforceModifyPermission();
8322 final Phone phone = getPhone(subId);
8323 if (phone == null) {
8324 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8325 return;
8326 }
8327 try {
8328 phone.carrierActionResetAll();
8329 } catch (Exception e) {
8330 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8331 }
8332 }
8333
8334 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008335 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8336 * bug report is being generated.
8337 */
8338 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008339 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008340 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8341 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008342 writer.println("Permission Denial: can't dump Phone from pid="
8343 + Binder.getCallingPid()
8344 + ", uid=" + Binder.getCallingUid()
8345 + "without permission "
8346 + android.Manifest.permission.DUMP);
8347 return;
8348 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008349 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008350 }
Jack Yueb89b242016-06-22 13:27:47 -07008351
Brad Ebingerdac2f002018-04-03 15:17:52 -07008352 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008353 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8354 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8355 @NonNull String[] args) {
8356 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8357 this, in.getFileDescriptor(), out.getFileDescriptor(),
8358 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008359 }
8360
Jack Yueb89b242016-06-22 13:27:47 -07008361 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008362 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008363 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008364 * @param reason the reason the data enable change is taking place
8365 * @param enabled True if enabling the data, otherwise disabling.
8366 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008367 */
8368 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008369 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008370 boolean enabled) {
8371 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8372 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8373 try {
8374 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008375 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008376 } catch (SecurityException se) {
8377 enforceModifyPermission();
8378 }
8379 } else {
8380 enforceModifyPermission();
8381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008382
8383 final long identity = Binder.clearCallingIdentity();
8384 try {
8385 Phone phone = getPhone(subId);
8386 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008387 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8388 phone.carrierActionSetMeteredApnsEnabled(enabled);
8389 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08008390 if (phone.isUsingNewDataStack()) {
8391 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8392 } else {
8393 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8394 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396 }
8397 } finally {
8398 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008399 }
8400 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008401
8402 /**
8403 * Get Client request stats
8404 * @return List of Client Request Stats
8405 * @hide
8406 */
8407 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008408 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8409 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008411 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008412 return null;
8413 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008414 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008416 final long identity = Binder.clearCallingIdentity();
8417 try {
8418 if (phone != null) {
8419 return phone.getClientRequestStats();
8420 }
8421
8422 return null;
8423 } finally {
8424 Binder.restoreCallingIdentity(identity);
8425 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008426 }
8427
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008428 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008429 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008430 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008431 }
Jack Yueb4124c2017-02-16 15:32:43 -08008432
8433 /**
Grace Chen70990072017-03-24 17:21:30 -07008434 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008435 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008436 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008437 * @param state State of SIM (power down, power up, pass through)
8438 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8439 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8440 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008441 *
8442 **/
8443 @Override
Grace Chen70990072017-03-24 17:21:30 -07008444 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008445 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008446 Phone phone = PhoneFactory.getPhone(slotIndex);
8447
vagdeviaf9a5b92018-08-15 16:01:53 -07008448 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450 final long identity = Binder.clearCallingIdentity();
8451 try {
8452 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008453 phone.setSimPowerState(state, null, workSource);
8454 }
8455 } finally {
8456 Binder.restoreCallingIdentity(identity);
8457 }
8458 }
8459
8460 /**
8461 * Set SIM card power state.
8462 *
8463 * @param slotIndex SIM slot id.
8464 * @param state State of SIM (power down, power up, pass through)
8465 * @param callback callback to trigger after success or failure
8466 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8467 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8468 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8469 *
8470 **/
8471 @Override
8472 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8473 IIntegerConsumer callback) {
8474 enforceModifyPermission();
8475 Phone phone = PhoneFactory.getPhone(slotIndex);
8476
8477 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8478
8479 final long identity = Binder.clearCallingIdentity();
8480 try {
8481 if (phone != null) {
8482 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8483 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008484 }
8485 } finally {
8486 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008487 }
8488 }
Shuo Qiandd210312017-04-12 22:11:33 +00008489
Tyler Gunn65d45c22017-06-05 11:22:26 -07008490 private boolean isUssdApiAllowed(int subId) {
8491 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008492 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008493 if (configManager == null) {
8494 return false;
8495 }
8496 PersistableBundle pb = configManager.getConfigForSubId(subId);
8497 if (pb == null) {
8498 return false;
8499 }
8500 return pb.getBoolean(
8501 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8502 }
8503
Shuo Qiandd210312017-04-12 22:11:33 +00008504 /**
8505 * Check if phone is in emergency callback mode
8506 * @return true if phone is in emergency callback mode
8507 * @param subId sub id
8508 */
goneil9c5f4872017-12-05 14:07:56 -08008509 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008510 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008511 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008512 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008513
8514 final long identity = Binder.clearCallingIdentity();
8515 try {
8516 if (phone != null) {
8517 return phone.isInEcm();
8518 } else {
8519 return false;
8520 }
8521 } finally {
8522 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008523 }
8524 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008525
8526 /**
8527 * Get the current signal strength information for the given subscription.
8528 * Because this information is not updated when the device is in a low power state
8529 * it should not be relied-upon to be current.
8530 * @param subId Subscription index
8531 * @return the most recent cached signal strength info from the modem
8532 */
8533 @Override
8534 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008535 final long identity = Binder.clearCallingIdentity();
8536 try {
8537 Phone p = getPhone(subId);
8538 if (p == null) {
8539 return null;
8540 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008541
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008542 return p.getSignalStrength();
8543 } finally {
8544 Binder.restoreCallingIdentity(identity);
8545 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008546 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008547
Pengquan Meng77b7f132018-08-22 14:49:57 -07008548 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008549 * Get the current modem radio state for the given slot.
8550 * @param slotIndex slot index.
8551 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008552 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008553 * @return the current radio power state from the modem
8554 */
8555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008556 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008557 Phone phone = PhoneFactory.getPhone(slotIndex);
8558 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8560 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008561 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8562 }
8563
8564 final long identity = Binder.clearCallingIdentity();
8565 try {
8566 return phone.getRadioPowerState();
8567 } finally {
8568 Binder.restoreCallingIdentity(identity);
8569 }
8570 }
8571 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8572 }
8573
8574 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008575 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8576 *
8577 * <p>Requires one of the following permissions:
8578 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008579 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008580 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8581 * privileges.
8582 *
8583 * @param subId subscription id
8584 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8585 * {@code false}.
8586 */
8587 @Override
8588 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008589 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008590 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008591 try {
8592 mApp.enforceCallingOrSelfPermission(
8593 android.Manifest.permission.ACCESS_NETWORK_STATE,
8594 functionName);
8595 } catch (Exception e) {
8596 mApp.enforceCallingOrSelfPermission(
8597 permission.READ_BASIC_PHONE_STATE, functionName);
8598 }
Shuo Qian093013d2020-08-13 15:42:55 -07008599 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008600 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008601 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008602 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008603
Pengquan Menga1bb6272018-09-06 09:59:22 -07008604 boolean isEnabled = false;
8605 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008606 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008607 Phone phone = getPhone(subId);
8608 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008609 } finally {
8610 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008611 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008612 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008613 }
8614
8615
8616 /**
8617 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8618 *
8619 * <p> Requires permission:
8620 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8621 * privileges.
8622 *
8623 * @param subId subscription id
8624 * @param isEnabled {@code true} means enable, {@code false} means disable.
8625 */
8626 @Override
8627 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8629 mApp, subId, "setDataRoamingEnabled");
8630
Pengquan Menga1bb6272018-09-06 09:59:22 -07008631 final long identity = Binder.clearCallingIdentity();
8632 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008633 Phone phone = getPhone(subId);
8634 if (phone != null) {
8635 phone.setDataRoamingEnabled(isEnabled);
8636 }
8637 } finally {
8638 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008639 }
8640 }
8641
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008642 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008643 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008644 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008645 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008646 mApp, subId, "isManualNetworkSelectionAllowed");
8647
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008648 boolean isAllowed = true;
8649 final long identity = Binder.clearCallingIdentity();
8650 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008651 Phone phone = getPhone(subId);
8652 if (phone != null) {
8653 isAllowed = phone.isCspPlmnEnabled();
8654 }
8655 } finally {
8656 Binder.restoreCallingIdentity(identity);
8657 }
8658 return isAllowed;
8659 }
8660
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008661 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8662 UiccProfile profile = port.getUiccProfile();
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08008663 if (profile == null) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008664 return false;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008665 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08008666 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8667 if (phone == null) {
8668 return false;
8669 }
8670 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8671 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8672 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008673 }
8674
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008675 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008676 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008677 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008678 mApp.getSystemService(AppOpsManager.class)
8679 .checkPackage(Binder.getCallingUid(), callingPackage);
8680
Jordan Liu1e142fc2019-04-22 15:10:43 -07008681 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008682 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008683 try {
8684 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008685 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008686 } catch (SecurityException e) {
8687 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8688 // has carrier privileges on an active UICC
8689 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8690 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008691 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008692 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008693 }
sandeepjs0a502c42021-09-27 15:34:44 +00008694 // checking compatibility, if calling app's target SDK is T and beyond.
8695 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8696 Binder.getCallingUid())) {
8697 isIccIdAccessRestricted = true;
8698 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008699 final long identity = Binder.clearCallingIdentity();
8700 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008701 UiccController uiccController = UiccController.getInstance();
8702 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008703 if (hasReadPermission) {
8704 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008705 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008706
8707 // Remove private info if the caller doesn't have access
8708 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8709 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008710 //setting the value after compatibility check
8711 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008712 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8713 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008714 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008715 if (card == null) {
8716 // assume no access if the card is unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008717 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008718 continue;
8719 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008720 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8721 if (portInfos.isEmpty()) {
sandeepjs0a502c42021-09-27 15:34:44 +00008722 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008723 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008724 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008725 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8726 for (UiccPortInfo portInfo : portInfos) {
8727 UiccPort port = uiccController.getUiccPortForSlot(
8728 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8729 if (port == null) {
8730 // assume no access if port is null
8731 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8732 continue;
8733 }
8734 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8735 uiccPortInfos.add(portInfo);
8736 } else {
8737 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8738 }
8739 }
8740 filteredInfos.add(new UiccCardInfo(
8741 cardInfo.isEuicc(),
8742 cardInfo.getCardId(),
8743 null,
8744 cardInfo.getPhysicalSlotIndex(),
8745 cardInfo.isRemovable(),
8746 cardInfo.isMultipleEnabledProfilesSupported(),
8747 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008748 }
8749 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008750 } finally {
8751 Binder.restoreCallingIdentity(identity);
8752 }
8753 }
8754
sandeepjs0a502c42021-09-27 15:34:44 +00008755 /**
8756 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8757 * generally private and require carrier privileges to view.
8758 *
8759 * @hide
8760 */
8761 @NonNull
8762 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8763 List<UiccPortInfo> portinfo = new ArrayList<>();
8764 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8765 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8766 }
8767 return new UiccCardInfo(
8768 cardInfo.isEuicc(),
8769 cardInfo.getCardId(),
8770 null,
8771 cardInfo.getPhysicalSlotIndex(),
8772 cardInfo.isRemovable(),
8773 cardInfo.isMultipleEnabledProfilesSupported(),
8774 portinfo
8775 );
8776 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008777
sandeepjs0a502c42021-09-27 15:34:44 +00008778 /**
8779 * @hide
8780 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8781 * These values are generally private and require carrier privileges to view.
8782 */
8783 @NonNull
8784 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8785 return new UiccPortInfo(
8786 UiccPortInfo.ICCID_REDACTED,
8787 portInfo.getPortIndex(),
8788 portInfo.getLogicalSlotIndex(),
8789 portInfo.isActive()
8790 );
8791 }
8792 @Override
8793 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008794 // Verify that the callingPackage belongs to the calling UID
sandeepjs0a502c42021-09-27 15:34:44 +00008795 mApp.getSystemService(AppOpsManager.class)
8796 .checkPackage(Binder.getCallingUid(), callingPackage);
8797
8798 boolean hasReadPermission = false;
8799 boolean isLogicalSlotAccessRestricted = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008800
8801 try {
8802 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8803 hasReadPermission = true;
8804 } catch (SecurityException e) {
8805 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8806 // has carrier privileges on an active UICC
8807 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8808 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8809 hasReadPermission = true;
8810 }
8811 }
8812
8813 // checking compatibility, if calling app's target SDK is T and beyond.
8814 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8815 Binder.getCallingUid())) {
8816 isLogicalSlotAccessRestricted = true;
8817 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008818 final long identity = Binder.clearCallingIdentity();
8819 try {
8820 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8821 if (slots == null) {
8822 Rlog.i(LOG_TAG, "slots is null.");
8823 return null;
8824 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008825 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8826 for (int i = 0; i < slots.length; i++) {
8827 UiccSlot slot = slots[i];
8828 if (slot == null) {
8829 continue;
8830 }
8831
Jordan Liu7be7e652019-05-06 18:55:02 +00008832 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008833 UiccCard card = slot.getUiccCard();
8834 if (card != null) {
8835 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008836 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008837 cardId = slot.getEid();
8838 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008839 // If cardId is null, use iccId of default port as cardId. Check if has
8840 // read permission otherwise set to null.(card is null which means no
8841 // carrier permission)
8842 cardId = hasReadPermission ? slot.getIccId(
8843 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008844 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008845 }
8846
Jordan Liu857451f2019-05-09 16:35:35 -07008847 if (cardId != null) {
8848 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8849 // if cardId is an EID, it's all digits so this is fine
8850 cardId = IccUtils.stripTrailingFs(cardId);
8851 }
8852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008853 int cardState = 0;
8854 switch (slot.getCardState()) {
8855 case CARDSTATE_ABSENT:
8856 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8857 break;
8858 case CARDSTATE_PRESENT:
8859 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8860 break;
8861 case CARDSTATE_ERROR:
8862 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8863 break;
8864 case CARDSTATE_RESTRICTED:
8865 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8866 break;
8867 default:
8868 break;
8869
8870 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008871 List<UiccPortInfo> portInfos = new ArrayList<>();
8872 int[] portIndexes = slot.getPortList();
8873 for (int portIdx : portIndexes) {
8874 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8875 callingPackage, hasReadPermission));
8876 if (slot.isPortActive(portIdx)) {
8877 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8878 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8879 port.getPhoneId(), true));
8880 } else {
8881 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8882 }
8883 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008884 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008885 slot.isEuicc(),
8886 cardId,
8887 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008888 slot.isExtendedApduSupported(),
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008889 slot.isRemovable(), portInfos);
sandeepjs0a502c42021-09-27 15:34:44 +00008890 //setting the value after compatibility check
8891 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008892 }
8893 return infos;
8894 } finally {
8895 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008896 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008897 }
8898
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008899 /* Returns null if doesn't have read permission or carrier privilege access. */
8900 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8901 boolean hasReadPermission) {
8902 String iccId = slot.getIccId(portIndex);
8903 if (hasReadPermission) { // if has read permission
8904 return iccId;
8905 } else {
8906 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8907 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8908 // if no read permission, checking carrier privilege access
8909 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8910 return iccId;
8911 }
8912 }
8913 }
8914 // No read permission or carrier privilege access.
8915 return UiccPortInfo.ICCID_REDACTED;
8916 }
8917
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008918 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008919 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008920 public boolean switchSlots(int[] physicalSlots) {
8921 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008922
8923 final long identity = Binder.clearCallingIdentity();
8924 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008925 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8926 for (int i = 0; i < physicalSlots.length; i++) {
8927 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8928 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8929 physicalSlots[i], i));
8930 }
8931 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008932 } finally {
8933 Binder.restoreCallingIdentity(identity);
8934 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008935 }
Jack Yu4c988042018-02-27 15:30:01 -08008936
8937 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008938 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8939 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8940 enforceModifyPermission();
8941
8942 final long identity = Binder.clearCallingIdentity();
8943 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008944 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjs0a502c42021-09-27 15:34:44 +00008945 } finally {
8946 Binder.restoreCallingIdentity(identity);
8947 }
8948 }
8949
8950 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008951 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008952 final long identity = Binder.clearCallingIdentity();
8953 try {
8954 return UiccController.getInstance().getCardIdForDefaultEuicc();
8955 } finally {
8956 Binder.restoreCallingIdentity(identity);
8957 }
8958 }
8959
Pengquan Meng85728fb2018-03-12 16:31:21 -07008960 /**
goneil47ffb6e2018-04-06 15:40:58 -07008961 * A test API to reload the UICC profile.
8962 *
8963 * <p>Requires that the calling app has permission
8964 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8965 * @hide
8966 */
8967 @Override
8968 public void refreshUiccProfile(int subId) {
8969 enforceModifyPermission();
8970
8971 final long identity = Binder.clearCallingIdentity();
8972 try {
8973 Phone phone = getPhone(subId);
8974 if (phone == null) {
8975 return;
8976 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008977 UiccPort uiccPort = phone.getUiccPort();
8978 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008979 return;
8980 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008981 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008982 if (uiccProfile == null) {
8983 return;
8984 }
8985 uiccProfile.refresh();
8986 } finally {
8987 Binder.restoreCallingIdentity(identity);
8988 }
8989 }
8990
8991 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008992 * Returns false if the mobile data is disabled by default, otherwise return true.
8993 */
8994 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008995 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008996 }
8997
8998 /**
8999 * Returns true if the data roaming is enabled by default, i.e the system property
9000 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9001 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9002 */
9003 private boolean getDefaultDataRoamingEnabled(int subId) {
9004 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009005 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009006 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009007 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9008 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9009 return isDataRoamingEnabled;
9010 }
9011
9012 /**
9013 * Returns the default network type for the given {@code subId}, if the default network type is
9014 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9015 */
9016 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009017 List<Integer> list = TelephonyProperties.default_network();
9018 int phoneId = mSubscriptionController.getPhoneId(subId);
9019 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9020 return list.get(phoneId);
9021 }
9022 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009023 }
fionaxua13278b2018-03-21 00:08:13 -07009024
9025 @Override
9026 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009027 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009028 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009029
9030 final long identity = Binder.clearCallingIdentity();
9031 try {
9032 final Phone phone = getPhone(subId);
9033 if (phone == null) {
9034 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9035 return;
9036 }
Rambo Wanga7436882022-01-13 21:51:44 -08009037 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9038 if (cpt != null) {
9039 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9040 }
9041 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009042 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9043 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009044 if (carrierPrivilegeRules == null) {
9045 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9046 } else {
9047 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009049 } finally {
9050 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009051 }
fionaxua13278b2018-03-21 00:08:13 -07009052 }
9053
9054 @Override
9055 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009056 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009057
9058 final long identity = Binder.clearCallingIdentity();
9059 try {
9060 final Phone phone = getPhone(subId);
9061 if (phone == null) {
9062 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9063 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9064 }
9065 return phone.getCarrierIdListVersion();
9066 } finally {
9067 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009068 }
fionaxua13278b2018-03-21 00:08:13 -07009069 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009070
9071 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009072 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9073 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009075 mApp, subId, callingPackage, callingFeatureId,
9076 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009077 return -1;
9078 }
9079
9080 final long identity = Binder.clearCallingIdentity();
9081 try {
9082 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9083 } finally {
9084 Binder.restoreCallingIdentity(identity);
9085 }
9086 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009087
9088 @Override
9089 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009090 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009091 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009092 mApp, subId, "getCdmaRoamingMode");
9093
9094 final long identity = Binder.clearCallingIdentity();
9095 try {
9096 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9097 } finally {
9098 Binder.restoreCallingIdentity(identity);
9099 }
9100 }
9101
9102 @Override
9103 public boolean setCdmaRoamingMode(int subId, int mode) {
9104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9105 mApp, subId, "setCdmaRoamingMode");
9106
9107 final long identity = Binder.clearCallingIdentity();
9108 try {
9109 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9110 } finally {
9111 Binder.restoreCallingIdentity(identity);
9112 }
9113 }
9114
9115 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009116 public int getCdmaSubscriptionMode(int subId) {
9117 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009118 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009119 mApp, subId, "getCdmaSubscriptionMode");
9120
9121 final long identity = Binder.clearCallingIdentity();
9122 try {
9123 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9124 } finally {
9125 Binder.restoreCallingIdentity(identity);
9126 }
9127 }
9128
9129 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009130 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9132 mApp, subId, "setCdmaSubscriptionMode");
9133
9134 final long identity = Binder.clearCallingIdentity();
9135 try {
9136 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9137 } finally {
9138 Binder.restoreCallingIdentity(identity);
9139 }
9140 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009141
sqianc5eccab2018-10-19 18:46:41 -07009142 @Override
sqian8c685422019-02-22 15:55:18 -08009143 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009144 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009145 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009146 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9147 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009148 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9149 }
9150 final long identity = Binder.clearCallingIdentity();
9151 try {
sqian854d44b2018-12-12 16:48:18 -08009152 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9153 for (Phone phone: PhoneFactory.getPhones()) {
9154 if (phone.getEmergencyNumberTracker() != null
9155 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9156 emergencyNumberListInternal.put(
9157 phone.getSubId(),
9158 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9159 }
sqian11b7a0e2018-12-05 18:48:28 -08009160 }
sqian854d44b2018-12-12 16:48:18 -08009161 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009162 } finally {
9163 Binder.restoreCallingIdentity(identity);
9164 }
sqianc5eccab2018-10-19 18:46:41 -07009165 }
9166
9167 @Override
sqian8c685422019-02-22 15:55:18 -08009168 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009169 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009170 if (!exactMatch) {
9171 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009172 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009173 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009174 }
9175 final long identity = Binder.clearCallingIdentity();
9176 try {
sqian854d44b2018-12-12 16:48:18 -08009177 for (Phone phone: PhoneFactory.getPhones()) {
9178 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009179 && phone.getEmergencyNumberTracker()
9180 .isEmergencyNumber(number, exactMatch)) {
9181 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009182 }
sqian11b7a0e2018-12-05 18:48:28 -08009183 }
9184 return false;
9185 } finally {
9186 Binder.restoreCallingIdentity(identity);
9187 }
9188 }
9189
sqianf4ca7ed2019-01-15 18:32:07 -08009190 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009191 * Start emergency callback mode for GsmCdmaPhone for testing.
9192 */
9193 @Override
9194 public void startEmergencyCallbackMode() {
9195 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9196 "startEmergencyCallbackMode");
9197 enforceModifyPermission();
9198 final long identity = Binder.clearCallingIdentity();
9199 try {
9200 for (Phone phone : PhoneFactory.getPhones()) {
9201 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9202 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9203 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9204 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9205 gsmCdmaPhone.obtainMessage(
9206 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9207 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9208 }
9209 }
9210 } finally {
9211 Binder.restoreCallingIdentity(identity);
9212 }
9213 }
9214
9215 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009216 * Update emergency number list for test mode.
9217 */
9218 @Override
9219 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9220 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9221 "updateEmergencyNumberListTestMode");
9222
9223 final long identity = Binder.clearCallingIdentity();
9224 try {
9225 for (Phone phone: PhoneFactory.getPhones()) {
9226 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9227 if (tracker != null) {
9228 tracker.executeEmergencyNumberTestModeCommand(action, num);
9229 }
9230 }
9231 } finally {
9232 Binder.restoreCallingIdentity(identity);
9233 }
9234 }
9235
9236 /**
9237 * Get the full emergency number list for test mode.
9238 */
9239 @Override
9240 public List<String> getEmergencyNumberListTestMode() {
9241 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9242 "getEmergencyNumberListTestMode");
9243
9244 final long identity = Binder.clearCallingIdentity();
9245 try {
9246 Set<String> emergencyNumbers = new HashSet<>();
9247 for (Phone phone: PhoneFactory.getPhones()) {
9248 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9249 if (tracker != null) {
9250 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9251 emergencyNumbers.add(num.getNumber());
9252 }
9253 }
9254 }
9255 return new ArrayList<>(emergencyNumbers);
9256 } finally {
9257 Binder.restoreCallingIdentity(identity);
9258 }
9259 }
9260
chen xud6b45bd2018-10-30 22:27:10 -07009261 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009262 public int getEmergencyNumberDbVersion(int subId) {
9263 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9264
9265 final long identity = Binder.clearCallingIdentity();
9266 try {
9267 final Phone phone = getPhone(subId);
9268 if (phone == null) {
9269 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9270 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9271 }
9272 return phone.getEmergencyNumberDbVersion();
9273 } finally {
9274 Binder.restoreCallingIdentity(identity);
9275 }
9276 }
9277
9278 @Override
9279 public void notifyOtaEmergencyNumberDbInstalled() {
9280 enforceModifyPermission();
9281
9282 final long identity = Binder.clearCallingIdentity();
9283 try {
9284 for (Phone phone: PhoneFactory.getPhones()) {
9285 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9286 if (tracker != null) {
9287 tracker.updateOtaEmergencyNumberDatabase();
9288 }
9289 }
9290 } finally {
9291 Binder.restoreCallingIdentity(identity);
9292 }
9293 }
9294
9295 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009296 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009297 enforceActiveEmergencySessionPermission();
9298
9299 final long identity = Binder.clearCallingIdentity();
9300 try {
9301 for (Phone phone: PhoneFactory.getPhones()) {
9302 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9303 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009304 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9305 }
9306 }
9307 } finally {
9308 Binder.restoreCallingIdentity(identity);
9309 }
9310 }
9311
9312 @Override
9313 public void resetOtaEmergencyNumberDbFilePath() {
9314 enforceActiveEmergencySessionPermission();
9315
9316 final long identity = Binder.clearCallingIdentity();
9317 try {
9318 for (Phone phone: PhoneFactory.getPhones()) {
9319 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9320 if (tracker != null) {
9321 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009322 }
9323 }
9324 } finally {
9325 Binder.restoreCallingIdentity(identity);
9326 }
9327 }
9328
9329 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009330 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9331 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9332 Phone phone = getPhone(subId);
9333 if (phone == null) {
9334 return null;
9335 }
9336 final long identity = Binder.clearCallingIdentity();
9337 try {
9338 UiccProfile profile = UiccController.getInstance()
9339 .getUiccProfileForPhone(phone.getPhoneId());
9340 if (profile != null) {
9341 return profile.getCertsFromCarrierPrivilegeAccessRules();
9342 }
9343 } finally {
9344 Binder.restoreCallingIdentity(identity);
9345 }
9346 return null;
9347 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009348
9349 /**
9350 * Enable or disable a modem stack.
9351 */
9352 @Override
9353 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9354 enforceModifyPermission();
9355
9356 final long identity = Binder.clearCallingIdentity();
9357 try {
9358 Phone phone = PhoneFactory.getPhone(slotIndex);
9359 if (phone == null) {
9360 return false;
9361 } else {
9362 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9363 }
9364 } finally {
9365 Binder.restoreCallingIdentity(identity);
9366 }
9367 }
Michelecea4cf22018-12-21 15:00:11 -08009368
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009369 /**
9370 * Whether a modem stack is enabled or not.
9371 */
9372 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009373 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9374 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009375 Phone phone = PhoneFactory.getPhone(slotIndex);
9376 if (phone == null) return false;
9377
9378 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009379 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9380 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009381 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9382 }
9383
9384 final long identity = Binder.clearCallingIdentity();
9385 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009386 try {
9387 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9388 } catch (NoSuchElementException ex) {
9389 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9390 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009391 } finally {
9392 Binder.restoreCallingIdentity(identity);
9393 }
9394 }
9395
Michelecea4cf22018-12-21 15:00:11 -08009396 @Override
Michele0ea7d782019-03-19 14:58:42 -07009397 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009398 enforceModifyPermission();
9399
9400 final long identity = Binder.clearCallingIdentity();
9401 try {
9402 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009403 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009404 .commit();
9405 } finally {
9406 Binder.restoreCallingIdentity(identity);
9407 }
9408 }
9409
9410 @Override
Michele0ea7d782019-03-19 14:58:42 -07009411 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009412 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009413 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009414 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9415 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009416 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009417 }
Michelecea4cf22018-12-21 15:00:11 -08009418
9419 final long identity = Binder.clearCallingIdentity();
9420 try {
Michele0ea7d782019-03-19 14:58:42 -07009421 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009422 } finally {
9423 Binder.restoreCallingIdentity(identity);
9424 }
9425 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009426
Michele0ea7d782019-03-19 14:58:42 -07009427 @TelephonyManager.IsMultiSimSupportedResult
9428 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009429 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9430 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9431 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009432 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9433 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009434 }
9435 // Check if the hardware supports multisim functionality. If usage of multisim is not
9436 // supported by the modem, indicate that it is restricted.
9437 PhoneCapability staticCapability =
9438 mPhoneConfigurationManager.getStaticPhoneCapability();
9439 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009440 loge("isMultiSimSupportedInternal: no static configuration available");
9441 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009442 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009443 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009444 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9445 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009446 }
9447 // Check if support of multiple SIMs is restricted by carrier
9448 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009449 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009450 }
9451
Michele0ea7d782019-03-19 14:58:42 -07009452 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009453 }
9454
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009455 /**
9456 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009457 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9458 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9459 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009460 * @param numOfSims number of active sims we want to switch to
9461 */
9462 @Override
9463 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009464 if (numOfSims == 1) {
9465 enforceModifyPermission();
9466 } else {
9467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9468 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9469 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009470 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009471
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009472 try {
Michele30b57b22019-03-01 12:01:14 -08009473 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009474 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009475 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9476 return;
9477 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009478 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9479 } finally {
9480 Binder.restoreCallingIdentity(identity);
9481 }
9482 }
9483
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009484 @Override
9485 public boolean isApplicationOnUicc(int subId, int appType) {
9486 enforceReadPrivilegedPermission("isApplicationOnUicc");
9487 Phone phone = getPhone(subId);
9488 if (phone == null) {
9489 return false;
9490 }
9491 final long identity = Binder.clearCallingIdentity();
9492 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009493 UiccPort uiccPort = phone.getUiccPort();
9494 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009495 return false;
9496 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009497 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009498 if (uiccProfile == null) {
9499 return false;
9500 }
9501 if (TelephonyManager.APPTYPE_SIM <= appType
9502 && appType <= TelephonyManager.APPTYPE_ISIM) {
9503 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9504 }
9505 return false;
9506 } finally {
9507 Binder.restoreCallingIdentity(identity);
9508 }
9509 }
9510
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009511 /**
chen xub4baa772019-04-03 10:23:41 -07009512 * Get whether making changes to modem configurations will trigger reboot.
9513 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009514 */
9515 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009516 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9517 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009519 mApp, subId, callingPackage, callingFeatureId,
9520 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009521 return false;
9522 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009523 final long identity = Binder.clearCallingIdentity();
9524 try {
9525 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9526 } finally {
9527 Binder.restoreCallingIdentity(identity);
9528 }
9529 }
9530
Nathan Harold29f5f052019-02-15 13:41:57 -08009531 private void updateModemStateMetrics() {
9532 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9533 // TODO: check the state for each modem if the api is ready.
9534 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9535 }
9536
Pengquan Meng3889a572019-01-23 11:16:29 -08009537 @Override
sandeepjs29b7e8e2021-11-17 04:05:58 +00009538 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009539 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjs29b7e8e2021-11-17 04:05:58 +00009540 // Verify that the callingPackage belongs to the calling UID
9541 mApp.getSystemService(AppOpsManager.class)
9542 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009543 final long identity = Binder.clearCallingIdentity();
sandeepjs29b7e8e2021-11-17 04:05:58 +00009544 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009545 try {
sandeepjs29b7e8e2021-11-17 04:05:58 +00009546 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9547 if (slotInfos != null) {
9548 for (int i = 0; i < slotInfos.length; i++) {
9549 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9550 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9551 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9552 portInfo.getLogicalSlotIndex()));
9553 }
9554 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009555 }
9556 }
sandeepjs29b7e8e2021-11-17 04:05:58 +00009557 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009558 } finally {
9559 Binder.restoreCallingIdentity(identity);
9560 }
9561 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009562
9563 /**
9564 * Get the IRadio HAL Version
9565 */
9566 @Override
9567 public int getRadioHalVersion() {
9568 Phone phone = getDefaultPhone();
9569 if (phone == null) return -1;
9570 HalVersion hv = phone.getHalVersion();
9571 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9572 return hv.major * 100 + hv.minor;
9573 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009574
9575 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009576 * Get the current calling package name.
9577 * @return the current calling package name
9578 */
9579 @Override
9580 public String getCurrentPackageName() {
9581 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9582 }
9583
9584 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009585 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9586 * corresponding network requests on a subId.
9587 *
9588 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009589 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009590 * 2) APN is un-metered for this subscription, or
9591 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009592 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009593 *
9594 * @return whether data is allowed for a apn type.
9595 *
9596 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009597 */
9598 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009599 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009600 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9601 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009602
9603 // Now that all security checks passes, perform the operation as ourselves.
9604 final long identity = Binder.clearCallingIdentity();
9605 try {
9606 Phone phone = getPhone(subId);
9607 if (phone == null) return false;
9608
Jack Yu41407ee2019-05-13 16:54:09 -07009609 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009610 boolean isDataEnabled;
9611 if (phone.isUsingNewDataStack()) {
9612 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9613 } else {
9614 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9615 }
9616 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009617 } finally {
9618 Binder.restoreCallingIdentity(identity);
9619 }
9620 }
9621
9622 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009623 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009624 enforceReadPrivilegedPermission("isApnMetered");
9625
9626 // Now that all security checks passes, perform the operation as ourselves.
9627 final long identity = Binder.clearCallingIdentity();
9628 try {
9629 Phone phone = getPhone(subId);
9630 if (phone == null) return true; // By default return true.
9631
Jack Yu41407ee2019-05-13 16:54:09 -07009632 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009633 } finally {
9634 Binder.restoreCallingIdentity(identity);
9635 }
9636 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009637
9638 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009639 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9640 int subscriptionId, IBooleanConsumer resultCallback) {
9641 enforceModifyPermission();
9642 long token = Binder.clearCallingIdentity();
9643 try {
9644 Phone phone = getPhone(subscriptionId);
9645 if (phone == null) {
9646 try {
9647 if (resultCallback != null) {
9648 resultCallback.accept(false);
9649 }
9650 } catch (RemoteException e) {
9651 // ignore
9652 }
9653 return;
9654 }
9655 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9656 Pair.create(specifiers, (x) -> {
9657 try {
9658 if (resultCallback != null) {
9659 resultCallback.accept(x);
9660 }
9661 } catch (RemoteException e) {
9662 // ignore
9663 }
9664 });
9665 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9666 } finally {
9667 Binder.restoreCallingIdentity(token);
9668 }
9669 }
9670
9671 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009672 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9673 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009674 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009675 mApp, subId, "getSystemSelectionChannels");
9676 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9677 final long identity = Binder.clearCallingIdentity();
9678 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009679 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9680 if (result instanceof IllegalStateException) {
9681 throw (IllegalStateException) result;
9682 }
9683 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009684 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9685 return specifiers;
9686 } finally {
9687 Binder.restoreCallingIdentity(identity);
9688 }
9689 }
9690
9691 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009692 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009693 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009694 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9695 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9696 if (iccRecords == null) {
9697 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9698 return false;
9699 }
9700 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9701 }
9702
9703 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009704 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9705 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009706 if (callingPackage == null) {
9707 callingPackage = getCurrentPackageName();
9708 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009709 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9710 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009711 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9712 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009713 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9714 }
9715 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9716 Intent intent = new Intent();
9717 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9718 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9719 // Bring up choose default SMS subscription dialog right now
9720 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9721 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9722 mApp.startActivity(intent);
9723 }
chen xud5ca2d52019-05-28 15:20:57 -07009724
9725 @Override
9726 public String getMmsUAProfUrl(int subId) {
9727 //TODO investigate if this API should require proper permission check in R b/133791609
9728 final long identity = Binder.clearCallingIdentity();
9729 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009730 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9731 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9732 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9733 return carrierUAProfUrl;
9734 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009735 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9736 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009737 } finally {
9738 Binder.restoreCallingIdentity(identity);
9739 }
9740 }
9741
9742 @Override
9743 public String getMmsUserAgent(int subId) {
9744 //TODO investigate if this API should require proper permission check in R b/133791609
9745 final long identity = Binder.clearCallingIdentity();
9746 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009747 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9748 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9749 if (!TextUtils.isEmpty(carrierUserAgent)) {
9750 return carrierUserAgent;
9751 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009752 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9753 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009754 } finally {
9755 Binder.restoreCallingIdentity(identity);
9756 }
9757 }
Jack Yub07d4972019-05-28 16:12:25 -07009758
9759 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009760 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9761 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009762
Jack Yub07d4972019-05-28 16:12:25 -07009763 final long identity = Binder.clearCallingIdentity();
9764 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009765 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009766 if (phone == null) return false;
9767
Hall Liua62f5da2020-09-25 10:42:19 -07009768 switch (policy) {
9769 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009770 if (phone.isUsingNewDataStack()) {
9771 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9772 } else {
9773 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9774 }
Hall Liua62f5da2020-09-25 10:42:19 -07009775 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009776 if (phone.isUsingNewDataStack()) {
9777 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9778 } else {
9779 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9780 }
Hall Liua62f5da2020-09-25 10:42:19 -07009781 default:
9782 throw new IllegalArgumentException(policy + " is not a valid policy");
9783 }
Jack Yub07d4972019-05-28 16:12:25 -07009784 } finally {
9785 Binder.restoreCallingIdentity(identity);
9786 }
9787 }
9788
9789 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009790 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009791 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009792 enforceModifyPermission();
9793
changbettyd5c246e2019-12-24 15:40:37 +08009794 final long identity = Binder.clearCallingIdentity();
9795 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009796 Phone phone = getPhone(subscriptionId);
9797 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009798
Hall Liua62f5da2020-09-25 10:42:19 -07009799 switch (policy) {
9800 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009801 if (phone.isUsingNewDataStack()) {
9802 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9803 } else {
9804 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9805 }
Hall Liua62f5da2020-09-25 10:42:19 -07009806 break;
9807 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009808 if (phone.isUsingNewDataStack()) {
9809 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9810 } else {
9811 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9812 }
Hall Liua62f5da2020-09-25 10:42:19 -07009813 break;
9814 default:
9815 throw new IllegalArgumentException(policy + " is not a valid policy");
9816 }
changbettyd5c246e2019-12-24 15:40:37 +08009817 } finally {
9818 Binder.restoreCallingIdentity(identity);
9819 }
9820 }
9821
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009822 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009823 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009824 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9825 * otherwise.
9826 */
9827 @Override
9828 public void setCepEnabled(boolean isCepEnabled) {
9829 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9830
9831 final long identity = Binder.clearCallingIdentity();
9832 try {
9833 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9834 for (Phone phone : PhoneFactory.getPhones()) {
9835 Phone defaultPhone = phone.getImsPhone();
9836 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9837 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9838 ImsPhoneCallTracker imsPhoneCallTracker =
9839 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9840 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9841 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9842 + imsPhone.getMsisdn());
9843 }
9844 }
9845 } finally {
9846 Binder.restoreCallingIdentity(identity);
9847 }
9848 }
allenwtsu46dcc572020-01-08 18:24:03 +08009849
9850 /**
9851 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9852 *
9853 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9854 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9855 * before being read.
9856 */
9857 @Override
9858 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9859 isCompressed) {
9860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9861 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009862 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9863 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9864 }
9865 if (!isImsAvailableOnDevice()) {
9866 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9867 "IMS not available on device.");
9868 }
9869
9870 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009871 try {
Hui Wang761a6682020-10-31 05:12:53 +00009872 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9873 } finally {
9874 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009875 }
9876 }
zoey chene02881a2019-12-30 16:11:23 +08009877
9878 @Override
9879 public boolean isIccLockEnabled(int subId) {
9880 enforceReadPrivilegedPermission("isIccLockEnabled");
9881
9882 // Now that all security checks passes, perform the operation as ourselves.
9883 final long identity = Binder.clearCallingIdentity();
9884 try {
9885 Phone phone = getPhone(subId);
9886 if (phone != null && phone.getIccCard() != null) {
9887 return phone.getIccCard().getIccLockEnabled();
9888 } else {
9889 return false;
9890 }
9891 } finally {
9892 Binder.restoreCallingIdentity(identity);
9893 }
9894 }
9895
9896 /**
9897 * Set the ICC pin lock enabled or disabled.
9898 *
9899 * @return an integer representing the status of IccLock enabled or disabled in the following
9900 * three cases:
9901 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9902 * successfully.
9903 * - Positive number and zero for remaining password attempts.
9904 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9905 *
9906 */
9907 @Override
9908 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9909 enforceModifyPermission();
9910
9911 Phone phone = getPhone(subId);
9912 if (phone == null) {
9913 return 0;
9914 }
9915 // Now that all security checks passes, perform the operation as ourselves.
9916 final long identity = Binder.clearCallingIdentity();
9917 try {
9918 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9919 new Pair<Boolean, String>(enabled, password), phone, null);
9920 return attemptsRemaining;
9921
9922 } catch (Exception e) {
9923 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9924 } finally {
9925 Binder.restoreCallingIdentity(identity);
9926 }
9927 return 0;
9928 }
9929
9930 /**
9931 * Change the ICC password used in ICC pin lock.
9932 *
9933 * @return an integer representing the status of IccLock changed in the following three cases:
9934 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9935 * - Positive number and zero for remaining password attempts.
9936 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9937 *
9938 */
9939 @Override
9940 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9941 enforceModifyPermission();
9942
9943 Phone phone = getPhone(subId);
9944 if (phone == null) {
9945 return 0;
9946 }
9947 // Now that all security checks passes, perform the operation as ourselves.
9948 final long identity = Binder.clearCallingIdentity();
9949 try {
9950 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9951 new Pair<String, String>(oldPassword, newPassword), phone, null);
9952 return attemptsRemaining;
9953
9954 } catch (Exception e) {
9955 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9956 } finally {
9957 Binder.restoreCallingIdentity(identity);
9958 }
9959 return 0;
9960 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009961
9962 /**
9963 * Request for receiving user activity notification
9964 */
9965 @Override
9966 public void requestUserActivityNotification() {
9967 if (!mNotifyUserActivity.get()
9968 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9969 mNotifyUserActivity.set(true);
9970 }
9971 }
9972
9973 /**
9974 * Called when userActivity is signalled in the power manager.
9975 * This is safe to call from any thread, with any window manager locks held or not.
9976 */
9977 @Override
9978 public void userActivity() {
9979 // ***************************************
9980 // * Inherited from PhoneWindowManager *
9981 // ***************************************
9982 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9983 // WITH ITS LOCKS HELD.
9984 //
9985 // This code must be VERY careful about the locks
9986 // it acquires.
9987 // In fact, the current code acquires way too many,
9988 // and probably has lurking deadlocks.
9989
9990 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9991 throw new SecurityException("Only the OS may call notifyUserActivity()");
9992 }
9993
9994 if (mNotifyUserActivity.getAndSet(false)) {
9995 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9996 USER_ACTIVITY_NOTIFICATION_DELAY);
9997 }
9998 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009999
10000 @Override
10001 public boolean canConnectTo5GInDsdsMode() {
10002 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10003 }
Jack Yud10cdd42020-09-28 20:28:01 -070010004
10005 @Override
10006 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10007 String callingFeatureId) {
10008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10009 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10010 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10011 }
10012
10013 Phone phone = getPhone(subId);
10014 if (phone == null) {
10015 throw new RuntimeException("phone is not available");
10016 }
10017 // Now that all security checks passes, perform the operation as ourselves.
10018 final long identity = Binder.clearCallingIdentity();
10019 try {
10020 return phone.getEquivalentHomePlmns();
10021 } finally {
10022 Binder.restoreCallingIdentity(identity);
10023 }
10024 }
Daniel Bright59e67312020-11-13 11:49:37 -080010025
10026 @Override
10027 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010028 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10029 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010030 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010031 if (radioInterfaceCapabilities == null) {
10032 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010033 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010034 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010035 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010036
Hui Wang641e81c2020-10-12 12:14:23 -070010037 @Override
10038 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10039 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010040 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10041 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10042 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10043 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10044 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010045 if (DBG) {
10046 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10047 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10048 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10049 }
10050
10051 if (!SubscriptionManager.isValidSubscriptionId(subId)
10052 || appType < TelephonyManager.APPTYPE_UNKNOWN
10053 || appType > TelephonyManager.APPTYPE_ISIM
10054 || nafUrl == null || securityProtocol == null || callback == null) {
10055 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10056 if (callback != null) {
10057 try {
10058 callback.onAuthenticationFailure(
10059 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10060 } catch (RemoteException exception) {
10061 log("Fail to notify onAuthenticationFailure due to " + exception);
10062 }
10063 return;
10064 }
10065 }
10066
10067 final long token = Binder.clearCallingIdentity();
10068 try {
10069 getGbaManager(subId).bootstrapAuthenticationRequest(
10070 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10071 forceBootStrapping, callback));
10072 } finally {
10073 Binder.restoreCallingIdentity(token);
10074 }
10075 }
10076
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010077 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010078 * Attempts to set the radio power state for all phones for thermal reason.
10079 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010080 * requested radio power state will actually be set. See {@link
10081 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10082 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010083 * @param enable {@code true} if trying to turn radio on.
10084 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10085 * false}.
10086 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010087 private boolean setRadioPowerForThermal(boolean enable) {
10088 boolean isPhoneAvailable = false;
10089 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10090 Phone phone = PhoneFactory.getPhone(i);
10091 if (phone != null) {
10092 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10093 isPhoneAvailable = true;
10094 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010095 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010096
10097 // return true if successfully informed the phone object about the thermal radio power
10098 // request.
10099 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010100 }
10101
10102 private int handleDataThrottlingRequest(int subId,
10103 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010104 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10105 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10106 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10107 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10108 throw new IllegalArgumentException("modem does not support data throttling");
10109 }
10110
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010111 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10112 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010113 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010114 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10115 }
10116
10117 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10118
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010119 if (isDataThrottlingSupported) {
10120 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010121 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010122 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10123 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10124 } else if (thermalMitigationResult
10125 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010126 log("Modem likely does not support data throttling on secondary carrier. Data " +
10127 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10128 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010129 }
10130 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010131 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010132
10133 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010134 }
10135
Jack Nudelman644b91a2021-03-12 14:09:48 -080010136 private static List<String> getThermalMitigationAllowlist(Context context) {
10137 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10138 for (String pckg : context.getResources()
10139 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10140 sThermalMitigationAllowlistedPackages.add(pckg);
10141 }
10142 }
10143
10144 return sThermalMitigationAllowlistedPackages;
10145 }
10146
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010147 private boolean isAnyPhoneInEmergencyState() {
10148 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10149 if (tm.isInEmergencyCall()) {
10150 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10151 return true;
10152 }
10153 for (Phone phone : PhoneFactory.getPhones()) {
10154 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10155 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10156 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10157 + phone.isInEcm());
10158 return true;
10159 }
10160 }
10161
10162 return false;
10163 }
10164
Jack Nudelman644b91a2021-03-12 14:09:48 -080010165 /**
10166 * Used by shell commands to add an authorized package name for thermal mitigation.
10167 * @param packageName name of package to be allowlisted
10168 * @param context
10169 */
10170 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10171 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10172 sThermalMitigationAllowlistedPackages.add(packageName);
10173 }
10174
10175 /**
10176 * Used by shell commands to remove an authorized package name for thermal mitigation.
10177 * @param packageName name of package to remove from allowlist
10178 * @param context
10179 */
10180 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10181 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10182 sThermalMitigationAllowlistedPackages.remove(packageName);
10183 }
10184
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010185 /**
10186 * Thermal mitigation request to control functionalities at modem.
10187 *
10188 * @param subId the id of the subscription.
10189 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010190 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010191 *
10192 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10193 */
10194 @Override
10195 @ThermalMitigationResult
10196 public int sendThermalMitigationRequest(
10197 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010198 ThermalMitigationRequest thermalMitigationRequest,
10199 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010200 enforceModifyPermission();
10201
Jack Nudelman644b91a2021-03-12 14:09:48 -080010202 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10203 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10204 .contains(callingPackage)) {
10205 throw new SecurityException("Calling package must be configured in the device config. "
10206 + "calling package: " + callingPackage);
10207 }
10208
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010209 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10210 final long identity = Binder.clearCallingIdentity();
10211
10212 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10213 try {
10214 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10215 switch (thermalMitigationAction) {
10216 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10217 thermalMitigationResult =
10218 handleDataThrottlingRequest(subId,
10219 thermalMitigationRequest.getDataThrottlingRequest());
10220 break;
10221 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10222 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10223 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10224 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10225 }
10226
10227 // Ensure that radio is on. If not able to power on due to phone being
10228 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010229 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010230 thermalMitigationResult =
10231 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10232 break;
10233 }
10234
10235 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10236 false);
10237 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10238 break;
10239 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10240 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10241 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10242 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10243 }
10244
10245 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10246 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010247 Phone phone = getPhone(subId);
10248 if (phone == null) {
10249 thermalMitigationResult =
10250 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10251 break;
10252 }
10253
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010254 TelephonyConnectionService service =
10255 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010256 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010257 Log.e(LOG_TAG, "An emergency call is pending");
10258 thermalMitigationResult =
10259 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10260 break;
10261 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010262 thermalMitigationResult =
10263 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10264 break;
10265 }
10266 } else {
10267 thermalMitigationResult =
10268 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10269 break;
10270 }
10271
10272 // Turn radio off. If not able to power off due to phone being unavailable,
10273 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010274 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010275 thermalMitigationResult =
10276 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10277 break;
10278 }
10279 thermalMitigationResult =
10280 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10281 break;
10282 default:
10283 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10284 + "not exist. Requested action: " + thermalMitigationAction);
10285 }
10286 } catch (IllegalArgumentException e) {
10287 throw e;
10288 } catch (Exception e) {
10289 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10290 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10291 } finally {
10292 Binder.restoreCallingIdentity(identity);
10293 }
10294
10295 if (DBG) {
10296 log("thermalMitigationRequest returning with thermalMitigationResult: "
10297 + thermalMitigationResult);
10298 }
10299
10300 return thermalMitigationResult;
10301 }
Hui Wang641e81c2020-10-12 12:14:23 -070010302
10303 /**
10304 * Set the GbaService Package Name that Telephony will bind to.
10305 *
10306 * @param subId The sim that the GbaService is associated with.
10307 * @param packageName The name of the package to be replaced with.
10308 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10309 */
10310 @Override
10311 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10312 enforceModifyPermission();
10313
10314 final long identity = Binder.clearCallingIdentity();
10315 try {
10316 return getGbaManager(subId).overrideServicePackage(packageName);
10317 } finally {
10318 Binder.restoreCallingIdentity(identity);
10319 }
10320 }
10321
10322 /**
10323 * Return the package name of the currently bound GbaService.
10324 *
10325 * @param subId The sim that the GbaService is associated with.
10326 * @return the package name of the GbaService configuration, null if GBA is not supported.
10327 */
10328 @Override
10329 public String getBoundGbaService(int subId) {
10330 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10331
10332 final long identity = Binder.clearCallingIdentity();
10333 try {
10334 return getGbaManager(subId).getServicePackage();
10335 } finally {
10336 Binder.restoreCallingIdentity(identity);
10337 }
10338 }
10339
10340 /**
10341 * Set the release time for telephony to unbind GbaService.
10342 *
10343 * @param subId The sim that the GbaService is associated with.
10344 * @param interval The release time to unbind GbaService by millisecond.
10345 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10346 */
10347 @Override
10348 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10349 enforceModifyPermission();
10350
10351 final long identity = Binder.clearCallingIdentity();
10352 try {
10353 return getGbaManager(subId).overrideReleaseTime(interval);
10354 } finally {
10355 Binder.restoreCallingIdentity(identity);
10356 }
10357 }
10358
10359 /**
10360 * Return the release time for telephony to unbind GbaService.
10361 *
10362 * @param subId The sim that the GbaService is associated with.
10363 * @return The release time to unbind GbaService by millisecond.
10364 */
10365 @Override
10366 public int getGbaReleaseTime(int subId) {
10367 enforceReadPrivilegedPermission("getGbaReleaseTime");
10368
10369 final long identity = Binder.clearCallingIdentity();
10370 try {
10371 return getGbaManager(subId).getReleaseTime();
10372 } finally {
10373 Binder.restoreCallingIdentity(identity);
10374 }
10375 }
10376
10377 private GbaManager getGbaManager(int subId) {
10378 GbaManager instance = GbaManager.getInstance(subId);
10379 if (instance == null) {
10380 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10381 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10382 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10383 }
10384 return instance;
10385 }
Hui Wang761a6682020-10-31 05:12:53 +000010386
10387 /**
10388 * indicate whether the device and the carrier can support
10389 * RCS VoLTE single registration.
10390 */
10391 @Override
10392 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010393 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10394 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10395 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10396 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010397
10398 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10399 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10400 }
10401
10402 final long identity = Binder.clearCallingIdentity();
10403 try {
10404 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10405 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010406 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10407 if (isCapable != null) {
10408 return isCapable;
10409 }
Hui Wang761a6682020-10-31 05:12:53 +000010410 }
Hui Wang67af90e2021-06-04 16:57:15 -070010411 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10412 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010413 } finally {
10414 Binder.restoreCallingIdentity(identity);
10415 }
10416 }
10417
10418 /**
10419 * Register RCS provisioning callback.
10420 */
10421 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010422 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010423 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010424 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010425 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010426 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10427 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010428
10429 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10430 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10431 }
10432 if (!isImsAvailableOnDevice()) {
10433 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10434 "IMS not available on device.");
10435 }
10436
10437 final long identity = Binder.clearCallingIdentity();
10438 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010439 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010440 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010441 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10442 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010443 }
Hui Wang761a6682020-10-31 05:12:53 +000010444 } finally {
10445 Binder.restoreCallingIdentity(identity);
10446 }
10447 }
10448
10449 /**
10450 * Unregister RCS provisioning callback.
10451 */
10452 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010453 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010454 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010455 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010456 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010457 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10458 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010459
10460 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10461 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10462 }
10463 if (!isImsAvailableOnDevice()) {
10464 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10465 "IMS not available on device.");
10466 }
10467
10468 final long identity = Binder.clearCallingIdentity();
10469 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010470 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010471 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010472 } finally {
10473 Binder.restoreCallingIdentity(identity);
10474 }
10475 }
10476
10477 /**
10478 * trigger RCS reconfiguration.
10479 */
10480 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010481 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10482 "triggerRcsReconfiguration",
10483 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010484
10485 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10486 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10487 }
10488 if (!isImsAvailableOnDevice()) {
10489 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10490 "IMS not available on device.");
10491 }
10492
10493 final long identity = Binder.clearCallingIdentity();
10494 try {
10495 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10496 } finally {
10497 Binder.restoreCallingIdentity(identity);
10498 }
10499 }
10500
10501 /**
10502 * Provide the client configuration parameters of the RCS application.
10503 */
10504 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010505 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10506 "setRcsClientConfiguration",
10507 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010508
10509 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10510 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10511 }
10512 if (!isImsAvailableOnDevice()) {
10513 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10514 "IMS not available on device.");
10515 }
10516
10517 final long identity = Binder.clearCallingIdentity();
10518
10519 try {
10520 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10521 if (configBinder == null) {
10522 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010523 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10524 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010525 } else {
10526 configBinder.setRcsClientConfiguration(rcc);
10527 }
joonhunshinfa314642021-09-17 06:33:39 +000010528
10529 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10530 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010531 } catch (RemoteException e) {
10532 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010533 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10534 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010535 } finally {
10536 Binder.restoreCallingIdentity(identity);
10537 }
10538 }
10539
10540 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010541 * Enables or disables the test mode for RCS VoLTE single registration.
10542 */
10543 @Override
10544 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10545 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10546 "setRcsSingleRegistrationTestModeEnabled");
10547
10548 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10549 }
10550
10551 /**
10552 * Gets the test mode for RCS VoLTE single registration.
10553 */
10554 @Override
10555 public boolean getRcsSingleRegistrationTestModeEnabled() {
10556 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10557 "getRcsSingleRegistrationTestModeEnabled");
10558
10559 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10560 }
10561
10562 /**
Hui Wang761a6682020-10-31 05:12:53 +000010563 * Overrides the config of RCS VoLTE single registration enabled for the device.
10564 */
10565 @Override
10566 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10567 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10568 "setDeviceSingleRegistrationEnabledOverride");
10569 enforceModifyPermission();
10570
10571 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10572 : Boolean.parseBoolean(enabledStr);
10573 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010574 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010575 }
10576
10577 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010578 * Sends a device to device communication message. Only usable via shell.
10579 * @param message message to send.
10580 * @param value message value.
10581 */
10582 @Override
10583 public void sendDeviceToDeviceMessage(int message, int value) {
10584 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010585 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010586 enforceModifyPermission();
10587
10588 final long identity = Binder.clearCallingIdentity();
10589 try {
10590 TelephonyConnectionService service =
10591 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10592 if (service == null) {
10593 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10594 return;
10595 }
10596 service.sendTestDeviceToDeviceMessage(message, value);
10597 } finally {
10598 Binder.restoreCallingIdentity(identity);
10599 }
10600 }
10601
Tyler Gunnbabbda02021-02-10 11:05:02 -080010602 /**
10603 * Sets the specified device to device transport active.
10604 * @param transport The transport to set active.
10605 */
10606 @Override
10607 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10608 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10609 "setActiveDeviceToDeviceTransport");
10610 enforceModifyPermission();
10611
10612 final long identity = Binder.clearCallingIdentity();
10613 try {
10614 TelephonyConnectionService service =
10615 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10616 if (service == null) {
10617 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10618 return;
10619 }
10620 service.setActiveDeviceToDeviceTransport(transport);
10621 } finally {
10622 Binder.restoreCallingIdentity(identity);
10623 }
10624 }
Tyler Gunn92479152021-01-20 16:30:10 -080010625
Tyler Gunnd4575212021-05-03 14:46:49 -070010626 @Override
10627 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10628 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10629 "setDeviceToDeviceForceEnabled");
10630
10631 final long identity = Binder.clearCallingIdentity();
10632 try {
10633 Arrays.stream(PhoneFactory.getPhones()).forEach(
10634 p -> {
10635 Phone thePhone = p.getImsPhone();
10636 if (thePhone != null && thePhone instanceof ImsPhone) {
10637 ImsPhone imsPhone = (ImsPhone) thePhone;
10638 CallTracker tracker = imsPhone.getCallTracker();
10639 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10640 ImsPhoneCallTracker imsPhoneCallTracker =
10641 (ImsPhoneCallTracker) tracker;
10642 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10643 }
10644 }
10645 }
10646 );
10647 } finally {
10648 Binder.restoreCallingIdentity(identity);
10649 }
10650 }
10651
Tyler Gunn92479152021-01-20 16:30:10 -080010652 /**
Hui Wang761a6682020-10-31 05:12:53 +000010653 * Gets the config of RCS VoLTE single registration enabled for the device.
10654 */
10655 @Override
10656 public boolean getDeviceSingleRegistrationEnabled() {
10657 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10658 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10659 }
10660
10661 /**
10662 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10663 */
10664 @Override
10665 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10666 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10667 "setCarrierSingleRegistrationEnabledOverride");
10668 enforceModifyPermission();
10669
10670 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10671 : Boolean.parseBoolean(enabledStr);
10672 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10673 subId, enabled);
10674 }
10675
10676 /**
10677 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10678 */
10679 @Override
10680 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10681 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10682 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10683 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010684
10685 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010686 * Overrides the ims feature validation result
10687 */
10688 @Override
10689 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10690 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10691 "setImsFeatureValidationOverride");
10692
10693 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10694 : Boolean.parseBoolean(enabledStr);
10695 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10696 subId, enabled);
10697 }
10698
10699 /**
10700 * Gets the ims feature validation override value
10701 */
10702 @Override
10703 public boolean getImsFeatureValidationOverride(int subId) {
10704 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10705 "getImsFeatureValidationOverride");
10706 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10707 }
10708
10709 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010710 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10711 * their mobile plan.
10712 */
10713 @Override
10714 public String getMobileProvisioningUrl() {
10715 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10716 final long identity = Binder.clearCallingIdentity();
10717 try {
10718 return getDefaultPhone().getMobileProvisioningUrl();
10719 } finally {
10720 Binder.restoreCallingIdentity(identity);
10721 }
10722 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010723
James.cf Linbcdf8b32021-01-14 16:44:13 +080010724 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010725 * Get the EAB contact from the EAB database.
10726 */
10727 @Override
10728 public String getContactFromEab(String contact) {
10729 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10730 enforceModifyPermission();
10731 final long identity = Binder.clearCallingIdentity();
10732 try {
10733 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10734 } finally {
10735 Binder.restoreCallingIdentity(identity);
10736 }
10737 }
10738
10739 /**
Calvin Pana1434322021-07-01 19:27:01 +080010740 * Get the EAB capability from the EAB database.
10741 */
10742 @Override
10743 public String getCapabilityFromEab(String contact) {
10744 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10745 enforceModifyPermission();
10746 final long identity = Binder.clearCallingIdentity();
10747 try {
10748 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10749 } finally {
10750 Binder.restoreCallingIdentity(identity);
10751 }
10752 }
10753
10754 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010755 * Remove the EAB contacts from the EAB database.
10756 */
10757 @Override
10758 public int removeContactFromEab(int subId, String contacts) {
10759 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10760 enforceModifyPermission();
10761 final long identity = Binder.clearCallingIdentity();
10762 try {
10763 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10764 } finally {
10765 Binder.restoreCallingIdentity(identity);
10766 }
10767 }
10768
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010769 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010770 public boolean getDeviceUceEnabled() {
10771 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10772 final long identity = Binder.clearCallingIdentity();
10773 try {
10774 return mApp.getDeviceUceEnabled();
10775 } finally {
10776 Binder.restoreCallingIdentity(identity);
10777 }
10778 }
10779
10780 @Override
10781 public void setDeviceUceEnabled(boolean isEnabled) {
10782 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10783 final long identity = Binder.clearCallingIdentity();
10784 try {
10785 mApp.setDeviceUceEnabled(isEnabled);
10786 } finally {
10787 Binder.restoreCallingIdentity(identity);
10788 }
10789 }
10790
Brad Ebinger14d467f2021-02-12 06:18:28 +000010791 /**
10792 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10793 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10794 */
10795 // Used for SHELL command only right now.
10796 @Override
10797 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10798 List<String> featureTags) {
10799 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10800 "addUceRegistrationOverrideShell");
10801 final long identity = Binder.clearCallingIdentity();
10802 try {
10803 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10804 new ArraySet<>(featureTags));
10805 } catch (ImsException e) {
10806 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10807 } finally {
10808 Binder.restoreCallingIdentity(identity);
10809 }
10810 }
10811
10812 /**
10813 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10814 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10815 */
10816 // Used for SHELL command only right now.
10817 @Override
10818 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10819 List<String> featureTags) {
10820 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10821 "removeUceRegistrationOverrideShell");
10822 final long identity = Binder.clearCallingIdentity();
10823 try {
10824 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10825 new ArraySet<>(featureTags));
10826 } catch (ImsException e) {
10827 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10828 } finally {
10829 Binder.restoreCallingIdentity(identity);
10830 }
10831 }
10832
10833 /**
10834 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10835 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10836 */
10837 // Used for SHELL command only right now.
10838 @Override
10839 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10840 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10841 "clearUceRegistrationOverrideShell");
10842 final long identity = Binder.clearCallingIdentity();
10843 try {
10844 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10845 } catch (ImsException e) {
10846 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10847 } finally {
10848 Binder.restoreCallingIdentity(identity);
10849 }
10850 }
10851
10852 /**
10853 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10854 */
10855 // Used for SHELL command only right now.
10856 @Override
10857 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10858 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10859 "getLatestRcsContactUceCapabilityShell");
10860 final long identity = Binder.clearCallingIdentity();
10861 try {
10862 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10863 } catch (ImsException e) {
10864 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10865 } finally {
10866 Binder.restoreCallingIdentity(identity);
10867 }
10868 }
10869
10870 /**
10871 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10872 * device does not have an active PUBLISH.
10873 */
10874 // Used for SHELL command only right now.
10875 @Override
10876 public String getLastUcePidfXmlShell(int subId) {
10877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10878 final long identity = Binder.clearCallingIdentity();
10879 try {
10880 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10881 } catch (ImsException e) {
10882 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10883 } finally {
10884 Binder.restoreCallingIdentity(identity);
10885 }
10886 }
10887
James.cf Line8713a42021-04-29 16:04:26 +080010888 /**
10889 * Remove UCE requests cannot be sent to the network status.
10890 */
10891 // Used for SHELL command only right now.
10892 @Override
10893 public boolean removeUceRequestDisallowedStatus(int subId) {
10894 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10895 final long identity = Binder.clearCallingIdentity();
10896 try {
10897 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10898 } catch (ImsException e) {
10899 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10900 } finally {
10901 Binder.restoreCallingIdentity(identity);
10902 }
10903 }
10904
James.cf Lin0fc71b02021-05-25 01:37:38 +080010905 /**
10906 * Remove UCE requests cannot be sent to the network status.
10907 */
10908 // Used for SHELL command only.
10909 @Override
10910 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10912 final long identity = Binder.clearCallingIdentity();
10913 try {
10914 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10915 } catch (ImsException e) {
10916 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10917 } finally {
10918 Binder.restoreCallingIdentity(identity);
10919 }
10920 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010921
James.cf Lin4b784aa2021-01-31 03:25:15 +080010922 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010923 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10924 String callingPackage) {
10925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10926 mApp, subId, "setSignalStrengthUpdateRequest");
10927
10928 final int callingUid = Binder.getCallingUid();
10929 // Verify that tha callingPackage belongs to the calling UID
10930 mApp.getSystemService(AppOpsManager.class)
10931 .checkPackage(callingUid, callingPackage);
10932
Rambo Wang3607f502021-02-01 21:51:40 -080010933 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010934
10935 final long identity = Binder.clearCallingIdentity();
10936 try {
10937 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10938 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10939
10940 if (result instanceof IllegalStateException) {
10941 throw (IllegalStateException) result;
10942 }
10943 } finally {
10944 Binder.restoreCallingIdentity(identity);
10945 }
10946 }
10947
10948 @Override
10949 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10950 String callingPackage) {
10951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10952 mApp, subId, "clearSignalStrengthUpdateRequest");
10953
10954 final int callingUid = Binder.getCallingUid();
10955 // Verify that tha callingPackage belongs to the calling UID
10956 mApp.getSystemService(AppOpsManager.class)
10957 .checkPackage(callingUid, callingPackage);
10958
10959 final long identity = Binder.clearCallingIdentity();
10960 try {
10961 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10962 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10963
10964 if (result instanceof IllegalStateException) {
10965 throw (IllegalStateException) result;
10966 }
10967 } finally {
10968 Binder.restoreCallingIdentity(identity);
10969 }
10970 }
10971
Rambo Wang3607f502021-02-01 21:51:40 -080010972 private static void validateSignalStrengthUpdateRequest(Context context,
10973 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010974 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10975 // phone/system process do not have further restriction on request
10976 return;
10977 }
10978
10979 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010980 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010981 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010982 context.enforceCallingOrSelfPermission(
10983 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10984 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010985 }
10986
10987 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10988 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10989 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10990 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10991 || info.isEnabled()) {
10992 throw new IllegalArgumentException(
10993 "Only system can set hide fields in SignalThresholdInfo");
10994 }
10995
10996 // Thresholds length for each RAN need in range. This has been validated in
10997 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10998 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10999 final int[] thresholds = info.getThresholds();
11000 Objects.requireNonNull(thresholds);
11001 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11002 || thresholds.length
11003 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11004 throw new IllegalArgumentException(
11005 "thresholds length is out of range: " + thresholds.length);
11006 }
11007 }
11008 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011009
11010 /**
11011 * Gets the current phone capability.
11012 *
11013 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11014 * @return the PhoneCapability which describes the data connection capability of modem.
11015 * It's used to evaluate possible phone config change, for example from single
11016 * SIM device to multi-SIM device.
11017 */
11018 @Override
11019 public PhoneCapability getPhoneCapability() {
11020 enforceReadPrivilegedPermission("getPhoneCapability");
11021 final long identity = Binder.clearCallingIdentity();
11022 try {
11023 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11024 } finally {
11025 Binder.restoreCallingIdentity(identity);
11026 }
11027 }
Michele Berionne5e411512020-11-13 02:36:59 +000011028
11029 /**
11030 * Prepare TelephonyManager for an unattended reboot. The reboot is
11031 * required to be done shortly after the API is invoked.
11032 */
11033 @Override
11034 @TelephonyManager.PrepareUnattendedRebootResult
11035 public int prepareForUnattendedReboot() {
11036 enforceRebootPermission();
11037
11038 final long identity = Binder.clearCallingIdentity();
11039 try {
11040 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
11041 } finally {
11042 Binder.restoreCallingIdentity(identity);
11043 }
11044 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011045
11046 /**
11047 * Request to get the current slicing configuration including URSP rules and
11048 * NSSAIs (configured, allowed and rejected).
11049 *
11050 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11051 */
11052 @Override
11053 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011054 TelephonyPermissions
11055 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11056 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011057
11058 final long identity = Binder.clearCallingIdentity();
11059 try {
11060 Phone phone = getDefaultPhone();
11061 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11062 } finally {
11063 Binder.restoreCallingIdentity(identity);
11064 }
11065 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000011066
11067 /**
11068 * Register an IMS connection state callback
11069 */
11070 @Override
11071 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11072 String callingPackage) {
11073 if (feature == ImsFeature.FEATURE_MMTEL) {
11074 // ImsMmTelManager
11075 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11076 TelephonyPermissions
11077 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11078 mApp, subId, "registerImsStateCallback");
11079 } else if (feature == ImsFeature.FEATURE_RCS) {
11080 // ImsRcsManager or SipDelegateManager
11081 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11082 Binder.getCallingUid(), "registerImsStateCallback",
11083 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11084 Manifest.permission.READ_PRECISE_PHONE_STATE,
11085 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11086 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11087 }
11088
11089 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11090 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11091 "IMS not available on device.");
11092 }
11093
11094 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11095 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11096 }
11097
11098 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11099 if (controller == null) {
11100 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11101 "IMS not available on device.");
11102 }
11103
11104 if (callingPackage == null) {
11105 callingPackage = getCurrentPackageName();
11106 }
11107
11108 final long token = Binder.clearCallingIdentity();
11109 try {
11110 int slotId = getSlotIndexOrException(subId);
11111 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11112 } catch (ImsException e) {
11113 throw new ServiceSpecificException(e.getCode());
11114 } finally {
11115 Binder.restoreCallingIdentity(token);
11116 }
11117 }
11118
11119 /**
11120 * Unregister an IMS connection state callback
11121 */
11122 @Override
11123 public void unregisterImsStateCallback(IImsStateCallback cb) {
11124 final long token = Binder.clearCallingIdentity();
11125 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11126 if (controller == null) {
11127 return;
11128 }
11129 try {
11130 controller.unregisterImsStateCallback(cb);
11131 } finally {
11132 Binder.restoreCallingIdentity(token);
11133 }
11134 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011135
11136 /**
11137 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11138 *
11139 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11140 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11141 * SecurityException.
11142 * If there is current registered network this value will be same as the registered cell
11143 * identity. If the device goes out of service the previous cell identity is cached and
11144 * will be returned. If the cache age of the Cell identity is more than 24 hours
11145 * it will be cleared and null will be returned.
11146 *
11147 */
11148 @Override
11149 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11150 String callingFeatureId) {
11151 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11152 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11153 LocationAccessPolicy.checkLocationPermission(mApp,
11154 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11155 .setCallingPackage(callingPackage)
11156 .setCallingFeatureId(callingFeatureId)
11157 .setCallingPid(Binder.getCallingPid())
11158 .setCallingUid(Binder.getCallingUid())
11159 .setMethod("getLastKnownCellIdentity")
11160 .setLogAsInfo(true)
11161 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11162 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11163 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11164 .build());
11165
11166 boolean hasFinePermission =
11167 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11168 if (!hasFinePermission
11169 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11170 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11171 + "and BIND_CONNECTION_SERVICE permission.");
11172 }
11173
11174 final long identity = Binder.clearCallingIdentity();
11175 try {
11176 Phone phone = getPhone(subId);
11177 if (phone == null) return null;
11178 ServiceStateTracker sst = phone.getServiceStateTracker();
11179 if (sst == null) return null;
11180 return sst.getLastKnownCellIdentity();
11181 } finally {
11182 Binder.restoreCallingIdentity(identity);
11183 }
11184 }
jimsun38340bf2021-10-26 15:01:23 +080011185
11186 /**
11187 * Sets the modem service class Name that Telephony will bind to.
11188 *
11189 * @param serviceName The class name of the modem service.
11190 * @return true if the operation is succeed, otherwise false.
11191 */
11192 public boolean setModemService(String serviceName) {
11193 Log.d(LOG_TAG, "setModemService - " + serviceName);
11194 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11196 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11197 "setModemService");
11198 return mPhoneConfigurationManager.setModemService(serviceName);
11199 }
11200
11201 /**
11202 * Return the class name of the currently bounded modem service.
11203 *
11204 * @return the class name of the modem service.
11205 */
11206 public String getModemService() {
11207 String result;
11208 Log.d(LOG_TAG, "getModemService");
11209 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11210 TelephonyPermissions
11211 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11212 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11213 "getModemService");
11214 result = mPhoneConfigurationManager.getModemService();
11215 Log.d(LOG_TAG, "result = " + result);
11216 return result;
11217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011218}