blob: 0ce22c77f5d7f4503ebce187ab379566f787f0f5 [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;
joonhunshin3e154242021-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;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000034import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080035import android.app.role.RoleManager;
Chen Xu540470b2021-12-14 17:15:47 -080036import android.compat.Compatibility;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080045import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070046import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.net.Uri;
48import android.os.AsyncResult;
49import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080050import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.Bundle;
52import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070053import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.Looper;
55import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080057import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070058import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070059import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080060import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080061import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070062import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070063import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080064import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070066import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070068import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070069import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080070import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070071import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090072import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080073import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080074import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070075import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070076import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080077import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080078import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070079import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080080import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070081import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080082import android.telephony.CellIdentityCdma;
83import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070085import android.telephony.CellInfoGsm;
86import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070087import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080088import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070089import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070090import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070091import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080092import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070093import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080094import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070095import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080096import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080097import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070098import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080099import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800101import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800102import android.telephony.SignalStrengthUpdateRequest;
103import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800104import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800105import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800106import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700107import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700108import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800109import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800110import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800111import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000112import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000113import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000114import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700115import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700116import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800117import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800118import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800119import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700120import android.telephony.gba.GbaAuthRequest;
121import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700122import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800123import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000124import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000125import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700126import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700127import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800128import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700129import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800130import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700131import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000132import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700133import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800135import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800136import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800137import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700140import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800142import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800143
Andrew Lee312e8172014-10-23 17:01:36 -0700144import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800145import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800146import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800147import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700150import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700151import com.android.internal.telephony.CallTracker;
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 Choi3b742d62021-10-25 19:48:34 +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 Wanga1782702021-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;
joonhunshin3e154242021-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 Reddy472c2ae2021-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 Reddyeb809e32021-11-19 03:07:54 +0000228import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800229import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800230import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800231import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100232import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800233import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700234import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800235import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800236import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800237import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800238import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800239import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240
241/**
242 * Implementation of the ITelephony interface.
243 */
Santos Cordon117fee72014-05-16 17:56:12 -0700244public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245 private static final String LOG_TAG = "PhoneInterfaceManager";
246 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
247 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800248 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249
250 // Message codes used with mMainThreadHandler
251 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700252 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
253 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700254 private static final int CMD_OPEN_CHANNEL = 9;
255 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
256 private static final int CMD_CLOSE_CHANNEL = 11;
257 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800258 private static final int CMD_NV_READ_ITEM = 13;
259 private static final int EVENT_NV_READ_ITEM_DONE = 14;
260 private static final int CMD_NV_WRITE_ITEM = 15;
261 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
262 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
263 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700264 private static final int CMD_RESET_MODEM_CONFIG = 19;
265 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800266 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
267 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800268 private static final int CMD_SEND_ENVELOPE = 25;
269 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000270 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
271 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700272 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
273 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
274 private static final int CMD_EXCHANGE_SIM_IO = 31;
275 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800276 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
277 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700278 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
279 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700280 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
281 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700282 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
283 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
284 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
285 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700286 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
287 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
288 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
289 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700290 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800291 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
292 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000293 private static final int CMD_SWITCH_SLOTS = 50;
294 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700295 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
296 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
297 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
298 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
299 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
300 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
301 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
302 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700303 private static final int CMD_GET_ALL_CELL_INFO = 60;
304 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
305 private static final int CMD_GET_CELL_LOCATION = 62;
306 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700307 private static final int CMD_MODEM_REBOOT = 64;
308 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700309 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
310 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800311 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
312 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700313 private static final int CMD_GET_MODEM_STATUS = 70;
314 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700315 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
316 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700317 private static final int CMD_ERASE_MODEM_CONFIG = 74;
318 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800319 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
320 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
321 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
322 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800323 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
324 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800325 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800326 private static final int CMD_GET_CALL_FORWARDING = 83;
327 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
328 private static final int CMD_SET_CALL_FORWARDING = 85;
329 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
330 private static final int CMD_GET_CALL_WAITING = 87;
331 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
332 private static final int CMD_SET_CALL_WAITING = 89;
333 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700334 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
335 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
336 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
337 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700338 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
339 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800340 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
341 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800342 private static final int CMD_SET_DATA_THROTTLING = 99;
343 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800344 private static final int CMD_SET_SIM_POWER = 101;
345 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800346 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
347 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
348 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
349 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800350 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
351 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000352 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800353 private static final int CMD_GET_SLICING_CONFIG = 110;
354 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800355 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700356 private static final int CMD_ENABLE_VONR = 113;
357 private static final int EVENT_ENABLE_VONR_DONE = 114;
358 private static final int CMD_IS_VONR_ENABLED = 115;
359 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800361 // Parameters of select command.
362 private static final int SELECT_COMMAND = 0xA4;
363 private static final int SELECT_P1 = 0x04;
364 private static final int SELECT_P2 = 0;
365 private static final int SELECT_P3 = 0x10;
366
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 /** The singleton instance. */
368 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800369 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Wink Saville3ab207e2014-11-20 13:07:20 -0800371 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800373 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700374 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700376 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800378 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700380 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800381 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Peter Wangdafb9ac2020-01-15 14:13:38 -0800383 /** User Activity */
384 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800385 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
386
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700387 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
388
Derek Tan97ebb422014-09-05 16:55:38 -0700389 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
390 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800391 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800392 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700393
Michelecea4cf22018-12-21 15:00:11 -0800394 // String to store multi SIM allowed
395 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
396
Derek Tan740e1672017-06-27 14:56:27 -0700397 // The AID of ISD-R.
398 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
399
yinxub1bed742017-04-17 11:45:04 -0700400 private NetworkScanRequestTracker mNetworkScanRequestTracker;
401
David Kelly5e06a7f2018-03-12 14:10:59 +0000402 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
403 private static final int MANUFACTURER_CODE_LENGTH = 8;
404
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800405 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800406 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800407
Derek Tan89e89d42014-07-08 17:00:10 -0700408 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700409 * Experiment flag to enable erase modem config on reset network, default value is false
410 */
411 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
412 "reset_network_erase_modem_config_enabled";
413
Rambo Wang0f050d82021-02-12 11:43:36 -0800414 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800415
sandeepjsb6c87872021-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 /**
Chen Xu540470b2021-12-14 17:15:47 -0800428 * Apps targeting on Android T and beyond will get exception whenever icc close channel
429 * operation fails.
430 */
431 @ChangeId
432 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
433 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
434
435 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 * A request object to use for transmitting data to an ICC.
437 */
438 private static final class IccAPDUArgument {
439 public int channel, cla, command, p1, p2, p3;
440 public String data;
441
442 public IccAPDUArgument(int channel, int cla, int command,
443 int p1, int p2, int p3, String data) {
444 this.channel = channel;
445 this.cla = cla;
446 this.command = command;
447 this.p1 = p1;
448 this.p2 = p2;
449 this.p3 = p3;
450 this.data = data;
451 }
452 }
453
454 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700455 * A request object to use for transmitting data to an ICC.
456 */
457 private static final class ManualNetworkSelectionArgument {
458 public OperatorInfo operatorInfo;
459 public boolean persistSelection;
460
461 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
462 this.operatorInfo = operatorInfo;
463 this.persistSelection = persistSelection;
464 }
465 }
466
467 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
469 * request after sending. The main thread will notify the request when it is complete.
470 */
471 private static final class MainThreadRequest {
472 /** The argument to use for the request */
473 public Object argument;
474 /** The result of the request that is run on the main thread */
475 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800476 // The subscriber id that this request applies to. Defaults to
477 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
478 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479
Nathan Harold92bed182018-10-12 18:16:49 -0700480 // In cases where subId is unavailable, the caller needs to specify the phone.
481 public Phone phone;
482
vagdeviaf9a5b92018-08-15 16:01:53 -0700483 public WorkSource workSource;
484
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485 public MainThreadRequest(Object argument) {
486 this.argument = argument;
487 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800488
Nathan Harold92bed182018-10-12 18:16:49 -0700489 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
490 this.argument = argument;
491 if (phone != null) {
492 this.phone = phone;
493 }
494 this.workSource = workSource;
495 }
496
vagdeviaf9a5b92018-08-15 16:01:53 -0700497 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800498 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800499 if (subId != null) {
500 this.subId = subId;
501 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700502 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504 }
505
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800506 private static final class IncomingThirdPartyCallArgs {
507 public final ComponentName component;
508 public final String callId;
509 public final String callerDisplayName;
510
511 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
512 String callerDisplayName) {
513 this.component = component;
514 this.callId = callId;
515 this.callerDisplayName = callerDisplayName;
516 }
517 }
518
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 /**
520 * A handler that processes messages on the main thread in the phone process. Since many
521 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
522 * inbound binder threads to the main thread in the phone process. The Binder thread
523 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
524 * on, which will be notified when the operation completes and will contain the result of the
525 * request.
526 *
527 * <p>If a MainThreadRequest object is provided in the msg.obj field,
528 * note that request.result must be set to something non-null for the calling thread to
529 * unblock.
530 */
531 private final class MainThreadHandler extends Handler {
532 @Override
533 public void handleMessage(Message msg) {
534 MainThreadRequest request;
535 Message onCompleted;
536 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000537 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800539 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540
541 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 case CMD_HANDLE_USSD_REQUEST: {
543 request = (MainThreadRequest) msg.obj;
544 final Phone phone = getPhoneFromRequest(request);
545 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
546 String ussdRequest = ussdObject.first;
547 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700548
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 if (!isUssdApiAllowed(request.subId)) {
550 // Carrier does not support use of this API, return failure.
551 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
552 UssdResponse response = new UssdResponse(ussdRequest, null);
553 Bundle returnData = new Bundle();
554 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
555 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700556
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 request.result = true;
558 notifyRequester(request);
559 return;
560 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700561
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 try {
563 request.result = phone != null
564 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
565 } catch (CallStateException cse) {
566 request.result = false;
567 }
568 // Wake up the requesting thread
569 notifyRequester(request);
570 break;
pkanwar32d516d2016-10-14 19:37:38 -0700571 }
572
Yorke Lee716f67e2015-06-17 15:39:16 -0700573 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700574 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700575 final Phone phone = getPhoneFromRequest(request);
576 request.result = phone != null ?
577 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
578 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700579 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000587 uiccPort = getUiccPortFromRequest(request);
588 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 loge("iccTransmitApduLogicalChannel: No UICC");
590 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
594 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000595 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 iccArgument.channel, iccArgument.cla, iccArgument.command,
597 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 break;
601
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
605 if (ar.exception == null && ar.result != null) {
606 request.result = ar.result;
607 } else {
608 request.result = new IccIoResult(0x6F, 0, (byte[])null);
609 if (ar.result == null) {
610 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800611 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800613 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 } else {
615 loge("iccTransmitApduLogicalChannel: Unknown exception");
616 }
617 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 break;
620
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
622 request = (MainThreadRequest) msg.obj;
623 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000624 uiccPort = getUiccPortFromRequest(request);
625 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 loge("iccTransmitApduBasicChannel: No UICC");
627 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
631 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000632 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
634 iccArgument.p3, iccArgument.data, onCompleted);
635 }
636 break;
637
638 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
639 ar = (AsyncResult) msg.obj;
640 request = (MainThreadRequest) ar.userObj;
641 if (ar.exception == null && ar.result != null) {
642 request.result = ar.result;
643 } else {
644 request.result = new IccIoResult(0x6F, 0, (byte[])null);
645 if (ar.result == null) {
646 loge("iccTransmitApduBasicChannel: Empty response");
647 } else if (ar.exception instanceof CommandException) {
648 loge("iccTransmitApduBasicChannel: CommandException: " +
649 ar.exception);
650 } else {
651 loge("iccTransmitApduBasicChannel: Unknown exception");
652 }
653 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 break;
656
657 case CMD_EXCHANGE_SIM_IO:
658 request = (MainThreadRequest) msg.obj;
659 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000660 uiccPort = getUiccPortFromRequest(request);
661 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 loge("iccExchangeSimIO: No UICC");
663 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700664 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 } else {
666 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
667 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000668 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
670 iccArgument.data, onCompleted);
671 }
672 break;
673
674 case EVENT_EXCHANGE_SIM_IO_DONE:
675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
677 if (ar.exception == null && ar.result != null) {
678 request.result = ar.result;
679 } else {
680 request.result = new IccIoResult(0x6f, 0, (byte[])null);
681 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700682 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 break;
684
Derek Tan4d5e5c12014-02-04 11:54:58 -0800685 case CMD_SEND_ENVELOPE:
686 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000687 uiccPort = getUiccPortFromRequest(request);
688 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700689 loge("sendEnvelopeWithStatus: No UICC");
690 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 } else {
693 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000694 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800696 break;
697
698 case EVENT_SEND_ENVELOPE_DONE:
699 ar = (AsyncResult) msg.obj;
700 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700701 if (ar.exception == null && ar.result != null) {
702 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700704 request.result = new IccIoResult(0x6F, 0, (byte[])null);
705 if (ar.result == null) {
706 loge("sendEnvelopeWithStatus: Empty response");
707 } else if (ar.exception instanceof CommandException) {
708 loge("sendEnvelopeWithStatus: CommandException: " +
709 ar.exception);
710 } else {
711 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
712 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800713 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800715 break;
716
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 case CMD_OPEN_CHANNEL:
718 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000719 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800720 IccLogicalChannelRequest openChannelRequest =
721 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000722 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700723 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800724 request.result = new IccOpenLogicalChannelResponse(-1,
725 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700726 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700727 } else {
728 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800729 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
730 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700731 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700732 break;
733
734 case EVENT_OPEN_CHANNEL_DONE:
735 ar = (AsyncResult) msg.obj;
736 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700737 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 int[] result = (int[]) ar.result;
740 int channelId = result[0];
741 byte[] selectResponse = null;
742 if (result.length > 1) {
743 selectResponse = new byte[result.length - 1];
744 for (int i = 1; i < result.length; ++i) {
745 selectResponse[i - 1] = (byte) result[i];
746 }
747 }
748 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700749 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700750 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700751 if (ar.result == null) {
752 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700753 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700754 if (ar.exception != null) {
755 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
756 }
757
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700758 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700759 if (ar.exception instanceof CommandException) {
760 CommandException.Error error =
761 ((CommandException) (ar.exception)).getCommandError();
762 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700763 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700764 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700765 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700766 }
767 }
768 openChannelResp = new IccOpenLogicalChannelResponse(
769 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700771 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700772 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 break;
774
775 case CMD_CLOSE_CHANNEL:
776 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000777 uiccPort = getUiccPortFromRequest(request);
778 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700779 loge("iccCloseLogicalChannel: No UICC");
Chen Xu540470b2021-12-14 17:15:47 -0800780 throw new IllegalArgumentException("iccCloseLogicalChannel: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700781 } else {
782 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000783 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700784 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 break;
786
787 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800788 ar = (AsyncResult) msg.obj;
789 request = (MainThreadRequest) ar.userObj;
790 if (ar.exception == null) {
791 request.result = true;
792 } else {
793 request.result = false;
794 if (ar.exception instanceof CommandException) {
795 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
796 CommandException.Error error =
797 ((CommandException) (ar.exception)).getCommandError();
798 // before this feature is enabled, this API should only return false if
799 // the operation fails instead of throwing runtime exception for
800 // backward-compatibility.
801 if (Compatibility.isChangeEnabled(
802 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)
803 && error == CommandException.Error.INVALID_ARGUMENTS) {
804 throw new IllegalArgumentException(
805 "iccCloseLogicalChannel: invalid argument ");
806 }
807 } else {
808 loge("iccCloseLogicalChannel: Unknown exception");
809 }
810 if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) {
811 throw new IllegalStateException(
812 "exception from modem to close iccLogical Channel");
813 }
814 }
815 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800816 break;
817
818 case CMD_NV_READ_ITEM:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800821 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
822 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800823 break;
824
825 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700826 ar = (AsyncResult) msg.obj;
827 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800828 if (ar.exception == null && ar.result != null) {
829 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700830 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800831 request.result = "";
832 if (ar.result == null) {
833 loge("nvReadItem: Empty response");
834 } else if (ar.exception instanceof CommandException) {
835 loge("nvReadItem: CommandException: " +
836 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700837 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800838 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 }
840 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700841 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700842 break;
843
Jake Hambye994d462014-02-03 13:10:13 -0800844 case CMD_NV_WRITE_ITEM:
845 request = (MainThreadRequest) msg.obj;
846 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
847 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800848 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700849 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800850 break;
851
852 case EVENT_NV_WRITE_ITEM_DONE:
853 handleNullReturnEvent(msg, "nvWriteItem");
854 break;
855
856 case CMD_NV_WRITE_CDMA_PRL:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800859 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800860 break;
861
862 case EVENT_NV_WRITE_CDMA_PRL_DONE:
863 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
864 break;
865
chen xu6dac5ab2018-10-26 17:39:23 -0700866 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800867 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700868 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800869 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800870 break;
871
chen xu6dac5ab2018-10-26 17:39:23 -0700872 case EVENT_RESET_MODEM_CONFIG_DONE:
873 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800874 break;
875
Sooraj Sasindran37444802020-08-11 10:40:43 -0700876 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
877 request = (MainThreadRequest) msg.obj;
878 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
879 request);
880 Phone phone = getPhoneFromRequest(request);
881 if (phone != null) {
882 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
883 } else {
884 loge("isNRDualConnectivityEnabled: No phone object");
885 request.result = false;
886 notifyRequester(request);
887 }
888 break;
889 }
890
891 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
894 if (ar.exception == null && ar.result != null) {
895 request.result = ar.result;
896 } else {
897 // request.result must be set to something non-null
898 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700899 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700900 request.result = ar.result;
901 } else {
902 request.result = false;
903 }
904 if (ar.result == null) {
905 loge("isNRDualConnectivityEnabled: Empty response");
906 } else if (ar.exception instanceof CommandException) {
907 loge("isNRDualConnectivityEnabled: CommandException: "
908 + ar.exception);
909 } else {
910 loge("isNRDualConnectivityEnabled: Unknown exception");
911 }
912 }
913 notifyRequester(request);
914 break;
915
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700916 case CMD_IS_VONR_ENABLED: {
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
919 request);
920 Phone phone = getPhoneFromRequest(request);
921 if (phone != null) {
922 phone.isVoNrEnabled(onCompleted, request.workSource);
923 } else {
924 loge("isVoNrEnabled: No phone object");
925 request.result = false;
926 notifyRequester(request);
927 }
928 break;
929 }
930
931 case EVENT_IS_VONR_ENABLED_DONE:
932 ar = (AsyncResult) msg.obj;
933 request = (MainThreadRequest) ar.userObj;
934 if (ar.exception == null && ar.result != null) {
935 request.result = ar.result;
936 } else {
937 // request.result must be set to something non-null
938 // for the calling thread to unblock
939 if (ar.result != null) {
940 request.result = ar.result;
941 } else {
942 request.result = false;
943 }
944 if (ar.result == null) {
945 loge("isVoNrEnabled: Empty response");
946 } else if (ar.exception instanceof CommandException) {
947 loge("isVoNrEnabled: CommandException: "
948 + ar.exception);
949 } else {
950 loge("isVoNrEnabled: Unknown exception");
951 }
952 }
953 notifyRequester(request);
954 break;
955
Sooraj Sasindran37444802020-08-11 10:40:43 -0700956 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
957 request = (MainThreadRequest) msg.obj;
958 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
959 Phone phone = getPhoneFromRequest(request);
960 if (phone != null) {
961 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
962 request.workSource);
963 } else {
964 loge("enableNrDualConnectivity: No phone object");
965 request.result =
966 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
967 notifyRequester(request);
968 }
969 break;
970 }
971
972 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 if (ar.exception == null) {
976 request.result =
977 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
978 } else {
979 request.result =
980 TelephonyManager
981 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
982 if (ar.exception instanceof CommandException) {
983 CommandException.Error error =
984 ((CommandException) (ar.exception)).getCommandError();
985 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
986 request.result =
987 TelephonyManager
988 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000989 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
990 request.result =
991 TelephonyManager
992 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700993 }
994 loge("enableNrDualConnectivity" + ": CommandException: "
995 + ar.exception);
996 } else {
997 loge("enableNrDualConnectivity" + ": Unknown exception");
998 }
999 }
1000 notifyRequester(request);
1001 break;
1002 }
1003
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001004 case CMD_ENABLE_VONR: {
1005 request = (MainThreadRequest) msg.obj;
1006 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1007 Phone phone = getPhoneFromRequest(request);
1008 if (phone != null) {
1009 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1010 request.workSource);
1011 } else {
1012 loge("setVoNrEnabled: No phone object");
1013 request.result =
1014 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1015 notifyRequester(request);
1016 }
1017 break;
1018 }
1019
1020 case EVENT_ENABLE_VONR_DONE: {
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 if (ar.exception == null) {
1024 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1025 } else {
1026 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1027 if (ar.exception instanceof CommandException) {
1028 CommandException.Error error =
1029 ((CommandException) (ar.exception)).getCommandError();
1030 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1031 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1032 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1033 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1034 } else {
1035 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1036 }
1037 loge("setVoNrEnabled" + ": CommandException: "
1038 + ar.exception);
1039 } else {
1040 loge("setVoNrEnabled" + ": Unknown exception");
1041 }
1042 }
1043 notifyRequester(request);
1044 break;
1045 }
1046
SongFerngWang3ef3e072020-12-21 16:41:52 +08001047 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001048 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001049 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1050 request);
1051 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001052 break;
1053
SongFerngWang3ef3e072020-12-21 16:41:52 +08001054 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
1057 if (ar.exception == null && ar.result != null) {
1058 request.result = ar.result; // Integer
1059 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301060 // request.result must be set to something non-null
1061 // for the calling thread to unblock
1062 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001063 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001064 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001065 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001066 loge("getAllowedNetworkTypesBitmask: CommandException: "
1067 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001068 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001069 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001070 }
1071 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001072 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001073 break;
1074
SongFerngWang3ef3e072020-12-21 16:41:52 +08001075 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001076 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001077 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1078 request);
1079 Pair<Integer, Long> reasonWithNetworkTypes =
1080 (Pair<Integer, Long>) request.argument;
1081 getPhoneFromRequest(request).setAllowedNetworkTypes(
1082 reasonWithNetworkTypes.first,
1083 reasonWithNetworkTypes.second,
1084 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 break;
1086
SongFerngWang3ef3e072020-12-21 16:41:52 +08001087 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1088 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001089 break;
1090
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001091 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1092 request = (MainThreadRequest)msg.obj;
1093 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001094 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001095 break;
1096
1097 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1098 ar = (AsyncResult)msg.obj;
1099 request = (MainThreadRequest)ar.userObj;
1100 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001101 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001102 break;
1103
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001104 case CMD_SET_VOICEMAIL_NUMBER:
1105 request = (MainThreadRequest) msg.obj;
1106 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1107 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001108 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1109 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001110 break;
1111
1112 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1113 handleNullReturnEvent(msg, "setVoicemailNumber");
1114 break;
1115
Stuart Scott54788802015-03-30 13:18:01 -07001116 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1117 request = (MainThreadRequest) msg.obj;
1118 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1119 request);
1120 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1121 break;
1122
1123 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1124 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1125 break;
1126
Shishir Agrawal302c8692015-06-19 13:49:39 -07001127 case CMD_PERFORM_NETWORK_SCAN:
1128 request = (MainThreadRequest) msg.obj;
1129 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1130 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1131 break;
1132
Hall Liu27d24262020-09-18 19:04:59 -07001133 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001134 request = (MainThreadRequest) msg.obj;
1135 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001136 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1137 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1138 request.argument;
1139 int callForwardingReason = args.first;
1140 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001141 break;
Hall Liu27d24262020-09-18 19:04:59 -07001142 }
1143 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001144 ar = (AsyncResult) msg.obj;
1145 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001146 TelephonyManager.CallForwardingInfoCallback callback =
1147 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1148 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001149 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001150 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001151 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1152 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1153 // Service Class is a bit mask per 3gpp 27.007. Search for
1154 // any service for voice call.
1155 if ((callForwardInfo.serviceClass
1156 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001157 callForwardingInfo = new CallForwardingInfo(
1158 callForwardInfo.status
1159 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001160 callForwardInfo.reason,
1161 callForwardInfo.number,
1162 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001163 break;
1164 }
1165 }
1166 // Didn't find a call forward info for voice call.
1167 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001168 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1169 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001170 }
Hall Liu27d24262020-09-18 19:04:59 -07001171 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001172 } else {
1173 if (ar.result == null) {
1174 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1175 }
1176 if (ar.exception != null) {
1177 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1178 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001179 int errorCode = TelephonyManager
1180 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001181 if (ar.exception instanceof CommandException) {
1182 CommandException.Error error =
1183 ((CommandException) (ar.exception)).getCommandError();
1184 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001185 errorCode = TelephonyManager
1186 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001187 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001188 errorCode = TelephonyManager
1189 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001190 }
1191 }
Hall Liu27d24262020-09-18 19:04:59 -07001192 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001193 }
Shuo Qian4a594052020-01-23 11:59:30 -08001194 break;
Hall Liu27d24262020-09-18 19:04:59 -07001195 }
Shuo Qian4a594052020-01-23 11:59:30 -08001196
Hall Liu27d24262020-09-18 19:04:59 -07001197 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001198 request = (MainThreadRequest) msg.obj;
1199 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001200 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001201 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001202 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1203 request.argument).first;
1204 request.phone.setCallForwardingOption(
1205 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001206 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001207 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001208 callForwardingInfoToSet.getReason(),
1209 callForwardingInfoToSet.getNumber(),
1210 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1211 break;
Hall Liu27d24262020-09-18 19:04:59 -07001212 }
Shuo Qian4a594052020-01-23 11:59:30 -08001213
Hall Liu27d24262020-09-18 19:04:59 -07001214 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001215 ar = (AsyncResult) msg.obj;
1216 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001217 Consumer<Integer> callback =
1218 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1219 request.argument).second;
1220 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001221 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001222 int errorCode = TelephonyManager.CallForwardingInfoCallback
1223 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001224 if (ar.exception instanceof CommandException) {
1225 CommandException.Error error =
1226 ((CommandException) (ar.exception)).getCommandError();
1227 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001228 errorCode = TelephonyManager.CallForwardingInfoCallback
1229 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001230 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001231 errorCode = TelephonyManager.CallForwardingInfoCallback
1232 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001233 }
1234 }
1235 callback.accept(errorCode);
1236 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001237 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001238 }
Shuo Qian4a594052020-01-23 11:59:30 -08001239 break;
Hall Liu27d24262020-09-18 19:04:59 -07001240 }
Shuo Qian4a594052020-01-23 11:59:30 -08001241
Hall Liu27d24262020-09-18 19:04:59 -07001242 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001243 request = (MainThreadRequest) msg.obj;
1244 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1245 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1246 break;
Hall Liu27d24262020-09-18 19:04:59 -07001247 }
Shuo Qian4a594052020-01-23 11:59:30 -08001248
Hall Liu27d24262020-09-18 19:04:59 -07001249 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001250 ar = (AsyncResult) msg.obj;
1251 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001252 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001253 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1254 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001255 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001256 // Service Class is a bit mask per 3gpp 27.007.
1257 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001258 if (callForwardResults.length > 1
1259 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001260 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001261 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001262 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1263 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001264 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001265 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001266 }
1267 } else {
1268 if (ar.result == null) {
1269 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1270 }
1271 if (ar.exception != null) {
1272 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1273 }
1274 if (ar.exception instanceof CommandException) {
1275 CommandException.Error error =
1276 ((CommandException) (ar.exception)).getCommandError();
1277 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1278 callForwardingStatus =
1279 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1280 }
1281 }
1282 }
Hall Liu27d24262020-09-18 19:04:59 -07001283 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001284 break;
Hall Liu27d24262020-09-18 19:04:59 -07001285 }
Shuo Qian4a594052020-01-23 11:59:30 -08001286
Hall Liu27d24262020-09-18 19:04:59 -07001287 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001288 request = (MainThreadRequest) msg.obj;
1289 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001290 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1291 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001292 break;
Hall Liu27d24262020-09-18 19:04:59 -07001293 }
Shuo Qian4a594052020-01-23 11:59:30 -08001294
Hall Liu27d24262020-09-18 19:04:59 -07001295 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001296 ar = (AsyncResult) msg.obj;
1297 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001298 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1299 Consumer<Integer> callback =
1300 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1301 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001302 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001303 if (ar.exception instanceof CommandException) {
1304 CommandException.Error error =
1305 ((CommandException) (ar.exception)).getCommandError();
1306 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1307 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1308 } else {
1309 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1310 }
1311 } else {
1312 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1313 }
1314 } else {
1315 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1316 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001317 }
Shuo Qian4a594052020-01-23 11:59:30 -08001318 break;
Hall Liu27d24262020-09-18 19:04:59 -07001319 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001320 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1321 ar = (AsyncResult) msg.obj;
1322 request = (MainThreadRequest) ar.userObj;
1323 CellNetworkScanResult cellScanResult;
1324 if (ar.exception == null && ar.result != null) {
1325 cellScanResult = new CellNetworkScanResult(
1326 CellNetworkScanResult.STATUS_SUCCESS,
1327 (List<OperatorInfo>) ar.result);
1328 } else {
1329 if (ar.result == null) {
1330 loge("getCellNetworkScanResults: Empty response");
1331 }
1332 if (ar.exception != null) {
1333 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1334 }
1335 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1336 if (ar.exception instanceof CommandException) {
1337 CommandException.Error error =
1338 ((CommandException) (ar.exception)).getCommandError();
1339 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1340 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1341 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1342 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1343 }
1344 }
1345 cellScanResult = new CellNetworkScanResult(errorCode, null);
1346 }
1347 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001348 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001349 break;
1350
1351 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1352 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001353 ManualNetworkSelectionArgument selArg =
1354 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001355 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1356 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001357 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1358 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001359 break;
1360
1361 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001362 ar = (AsyncResult) msg.obj;
1363 request = (MainThreadRequest) ar.userObj;
1364 if (ar.exception == null) {
1365 request.result = true;
1366 } else {
1367 request.result = false;
1368 loge("setNetworkSelectionModeManual " + ar.exception);
1369 }
1370 notifyRequester(request);
1371 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001372 break;
1373
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001374 case CMD_GET_MODEM_ACTIVITY_INFO:
1375 request = (MainThreadRequest) msg.obj;
1376 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001377 if (defaultPhone != null) {
1378 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001379 } else {
1380 ResultReceiver result = (ResultReceiver) request.argument;
1381 Bundle bundle = new Bundle();
1382 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001383 new ModemActivityInfo(0, 0, 0,
1384 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001385 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001386 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001387 break;
1388
Hall Liud0f208c2020-10-14 16:54:44 -07001389 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001390 ar = (AsyncResult) msg.obj;
1391 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001392 ResultReceiver result = (ResultReceiver) request.argument;
1393
Hall Liud0f208c2020-10-14 16:54:44 -07001394 ModemActivityInfo ret = null;
1395 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001396 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001397 // Update the last modem activity info and the result of the request.
1398 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1399 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001400 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001401 int[] txTimeMs = info.getTransmitTimeMillis();
1402 int[] lastModemTxTimeMs = mLastModemActivityInfo
1403 .getTransmitTimeMillis();
1404 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1405 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1406 }
Hall Liu49656c02020-10-09 19:00:11 -07001407 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001408 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1409 + mLastModemActivityInfo.getSleepTimeMillis());
1410 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1411 + mLastModemActivityInfo.getIdleTimeMillis());
1412 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1413 mLastModemActivityInfo.setReceiveTimeMillis(
1414 info.getReceiveTimeMillis()
1415 + mLastModemActivityInfo.getReceiveTimeMillis());
1416 }
Hall Liu49656c02020-10-09 19:00:11 -07001417 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001418 mLastModemActivityInfo.getSleepTimeMillis(),
1419 mLastModemActivityInfo.getIdleTimeMillis(),
1420 mLastModemActivityInfo.getTransmitTimeMillis(),
1421 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001422 } else {
1423 if (ar.result == null) {
1424 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001425 error = TelephonyManager.ModemActivityInfoException
1426 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001427 } else if (ar.exception instanceof CommandException) {
1428 loge("queryModemActivityInfo: CommandException: " +
1429 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001430 error = TelephonyManager.ModemActivityInfoException
1431 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001432 } else {
1433 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001434 error = TelephonyManager.ModemActivityInfoException
1435 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001436 }
1437 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001438 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001439 if (ret != null) {
1440 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1441 } else {
1442 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1443 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001444 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001445 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001446 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001447 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001448
Meng Wang1a7c35a2016-05-05 20:56:15 -07001449 case CMD_SET_ALLOWED_CARRIERS:
1450 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001451 CarrierRestrictionRules argument =
1452 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001453 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001454 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001455 break;
1456
1457 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1458 ar = (AsyncResult) msg.obj;
1459 request = (MainThreadRequest) ar.userObj;
1460 if (ar.exception == null && ar.result != null) {
1461 request.result = ar.result;
1462 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001463 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1464 if (ar.exception instanceof CommandException) {
1465 loge("setAllowedCarriers: CommandException: " + ar.exception);
1466 CommandException.Error error =
1467 ((CommandException) (ar.exception)).getCommandError();
1468 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1469 request.result =
1470 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1471 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001472 } else {
1473 loge("setAllowedCarriers: Unknown exception");
1474 }
1475 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001476 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001477 break;
1478
1479 case CMD_GET_ALLOWED_CARRIERS:
1480 request = (MainThreadRequest) msg.obj;
1481 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001482 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001483 break;
1484
1485 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1486 ar = (AsyncResult) msg.obj;
1487 request = (MainThreadRequest) ar.userObj;
1488 if (ar.exception == null && ar.result != null) {
1489 request.result = ar.result;
1490 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001491 request.result = new IllegalStateException(
1492 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001493 if (ar.result == null) {
1494 loge("getAllowedCarriers: Empty response");
1495 } else if (ar.exception instanceof CommandException) {
1496 loge("getAllowedCarriers: CommandException: " +
1497 ar.exception);
1498 } else {
1499 loge("getAllowedCarriers: Unknown exception");
1500 }
1501 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001502 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001503 break;
1504
Nathan Haroldb3014052017-01-25 15:57:32 -08001505 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1506 ar = (AsyncResult) msg.obj;
1507 request = (MainThreadRequest) ar.userObj;
1508 if (ar.exception == null && ar.result != null) {
1509 request.result = ar.result;
1510 } else {
1511 request.result = new IllegalArgumentException(
1512 "Failed to retrieve Forbidden Plmns");
1513 if (ar.result == null) {
1514 loge("getForbiddenPlmns: Empty response");
1515 } else {
1516 loge("getForbiddenPlmns: Unknown exception");
1517 }
1518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001519 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001520 break;
1521
1522 case CMD_GET_FORBIDDEN_PLMNS:
1523 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001524 uiccPort = getUiccPortFromRequest(request);
1525 if (uiccPort == null) {
1526 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001527 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001528 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001529 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001530 break;
1531 }
1532 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001533 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001534 if (uiccApp == null) {
1535 loge("getForbiddenPlmns() no app with specified type -- "
1536 + appType);
1537 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001538 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001539 break;
1540 } else {
1541 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1542 + " specified type -- " + appType);
1543 }
1544 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1545 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1546 onCompleted);
1547 break;
1548
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001549 case CMD_SWITCH_SLOTS:
1550 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001551 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001552 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001553 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001554 break;
1555
1556 case EVENT_SWITCH_SLOTS_DONE:
1557 ar = (AsyncResult) msg.obj;
1558 request = (MainThreadRequest) ar.userObj;
1559 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001560 notifyRequester(request);
1561 break;
1562 case CMD_GET_NETWORK_SELECTION_MODE:
1563 request = (MainThreadRequest) msg.obj;
1564 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1565 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1566 break;
1567
1568 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1569 ar = (AsyncResult) msg.obj;
1570 request = (MainThreadRequest) ar.userObj;
1571 if (ar.exception != null) {
1572 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1573 } else {
1574 int mode = ((int[]) ar.result)[0];
1575 if (mode == 0) {
1576 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1577 } else {
1578 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1579 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001580 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001581 notifyRequester(request);
1582 break;
1583 case CMD_GET_CDMA_ROAMING_MODE:
1584 request = (MainThreadRequest) msg.obj;
1585 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1586 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1587 break;
1588 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1589 ar = (AsyncResult) msg.obj;
1590 request = (MainThreadRequest) ar.userObj;
1591 if (ar.exception != null) {
1592 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1593 } else {
1594 request.result = ((int[]) ar.result)[0];
1595 }
1596 notifyRequester(request);
1597 break;
1598 case CMD_SET_CDMA_ROAMING_MODE:
1599 request = (MainThreadRequest) msg.obj;
1600 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1601 int mode = (int) request.argument;
1602 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1603 break;
1604 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1605 ar = (AsyncResult) msg.obj;
1606 request = (MainThreadRequest) ar.userObj;
1607 request.result = ar.exception == null;
1608 notifyRequester(request);
1609 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001610 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1611 request = (MainThreadRequest) msg.obj;
1612 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1613 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1614 break;
1615 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1616 ar = (AsyncResult) msg.obj;
1617 request = (MainThreadRequest) ar.userObj;
1618 if (ar.exception != null) {
1619 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1620 } else {
1621 request.result = ((int[]) ar.result)[0];
1622 }
1623 notifyRequester(request);
1624 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001625 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1626 request = (MainThreadRequest) msg.obj;
1627 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1628 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001629 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1630 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001631 break;
1632 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1633 ar = (AsyncResult) msg.obj;
1634 request = (MainThreadRequest) ar.userObj;
1635 request.result = ar.exception == null;
1636 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001637 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001638 case CMD_GET_ALL_CELL_INFO:
1639 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001640 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001641 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001642 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001643 case EVENT_GET_ALL_CELL_INFO_DONE:
1644 ar = (AsyncResult) msg.obj;
1645 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001646 // If a timeout occurs, the response will be null
1647 request.result = (ar.exception == null && ar.result != null)
1648 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001649 synchronized (request) {
1650 request.notifyAll();
1651 }
1652 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001653 case CMD_REQUEST_CELL_INFO_UPDATE:
1654 request = (MainThreadRequest) msg.obj;
1655 request.phone.requestCellInfoUpdate(request.workSource,
1656 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1657 break;
1658 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1659 ar = (AsyncResult) msg.obj;
1660 request = (MainThreadRequest) ar.userObj;
1661 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1662 try {
1663 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001664 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001665 cb.onError(
1666 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1667 ar.exception.getClass().getName(),
1668 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001669 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001670 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001671 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001672 } else {
1673 // use the result as returned
1674 cb.onCellInfo((List<CellInfo>) ar.result);
1675 }
1676 } catch (RemoteException re) {
1677 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1678 }
1679 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001680 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001681 request = (MainThreadRequest) msg.obj;
1682 WorkSource ws = (WorkSource) request.argument;
1683 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001684 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001685 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001686 }
1687 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001688 ar = (AsyncResult) msg.obj;
1689 request = (MainThreadRequest) ar.userObj;
1690 if (ar.exception == null) {
1691 request.result = ar.result;
1692 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001693 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001694 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001695 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001696 }
1697
1698 synchronized (request) {
1699 request.notifyAll();
1700 }
1701 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001702 }
chen xu6dac5ab2018-10-26 17:39:23 -07001703 case CMD_MODEM_REBOOT:
1704 request = (MainThreadRequest) msg.obj;
1705 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001706 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001707 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001708 case EVENT_CMD_MODEM_REBOOT_DONE:
1709 handleNullReturnEvent(msg, "rebootModem");
1710 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001711 case CMD_REQUEST_ENABLE_MODEM:
1712 request = (MainThreadRequest) msg.obj;
1713 boolean enable = (boolean) request.argument;
1714 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001715 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001716 PhoneConfigurationManager.getInstance()
1717 .enablePhone(request.phone, enable, onCompleted);
1718 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001719 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001720 ar = (AsyncResult) msg.obj;
1721 request = (MainThreadRequest) ar.userObj;
1722 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001723 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001724 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001725 if ((boolean) request.result) {
1726 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1727 updateModemStateMetrics();
1728 } else {
1729 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1730 + ar.exception);
1731 }
1732 notifyRequester(request);
1733 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001734 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001735 case CMD_GET_MODEM_STATUS:
1736 request = (MainThreadRequest) msg.obj;
1737 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1738 PhoneConfigurationManager.getInstance()
1739 .getPhoneStatusFromModem(request.phone, onCompleted);
1740 break;
1741 case EVENT_GET_MODEM_STATUS_DONE:
1742 ar = (AsyncResult) msg.obj;
1743 request = (MainThreadRequest) ar.userObj;
1744 int id = request.phone.getPhoneId();
1745 if (ar.exception == null && ar.result != null) {
1746 request.result = ar.result;
1747 //update the cache as modem status has changed
1748 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1749 (boolean) request.result);
1750 } else {
1751 // Return true if modem status cannot be retrieved. For most cases,
1752 // modem status is on. And for older version modems, GET_MODEM_STATUS
1753 // and disable modem are not supported. Modem is always on.
1754 // TODO: this should be fixed in R to support a third
1755 // status UNKNOWN b/131631629
1756 request.result = true;
1757 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1758 + ar.exception);
1759 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001760 notifyRequester(request);
1761 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001762 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1763 request = (MainThreadRequest) msg.obj;
1764 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1765 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1766 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1767 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1768 break;
1769 }
1770 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1771 ar = (AsyncResult) msg.obj;
1772 request = (MainThreadRequest) ar.userObj;
1773 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1774 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1775 args.second.accept(ar.exception == null);
1776 notifyRequester(request);
1777 break;
1778 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001779 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1780 request = (MainThreadRequest) msg.obj;
1781 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1782 Phone phone = getPhoneFromRequest(request);
1783 if (phone != null) {
1784 phone.getSystemSelectionChannels(onCompleted);
1785 } else {
1786 loge("getSystemSelectionChannels: No phone object");
1787 request.result = new ArrayList<RadioAccessSpecifier>();
1788 notifyRequester(request);
1789 }
1790 break;
1791 }
1792 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1793 ar = (AsyncResult) msg.obj;
1794 request = (MainThreadRequest) ar.userObj;
1795 if (ar.exception == null && ar.result != null) {
1796 request.result = ar.result;
1797 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001798 request.result = new IllegalStateException(
1799 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001800 if (ar.result == null) {
1801 loge("getSystemSelectionChannels: Empty response");
1802 } else {
1803 loge("getSystemSelectionChannels: Unknown exception");
1804 }
1805 }
1806 notifyRequester(request);
1807 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001808 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1809 ar = (AsyncResult) msg.obj;
1810 request = (MainThreadRequest) ar.userObj;
1811 if (ar.exception == null && ar.result != null) {
1812 request.result = ar.result;
1813 } else {
1814 request.result = -1;
1815 loge("Failed to set Forbidden Plmns");
1816 if (ar.result == null) {
1817 loge("setForbidenPlmns: Empty response");
1818 } else if (ar.exception != null) {
1819 loge("setForbiddenPlmns: Exception: " + ar.exception);
1820 request.result = -1;
1821 } else {
1822 loge("setForbiddenPlmns: Unknown exception");
1823 }
1824 }
1825 notifyRequester(request);
1826 break;
1827 case CMD_SET_FORBIDDEN_PLMNS:
1828 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001829 uiccPort = getUiccPortFromRequest(request);
1830 if (uiccPort == null) {
1831 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001832 request.result = -1;
1833 notifyRequester(request);
1834 break;
1835 }
1836 Pair<Integer, List<String>> setFplmnsArgs =
1837 (Pair<Integer, List<String>>) request.argument;
1838 appType = setFplmnsArgs.first;
1839 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001840 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001841 if (uiccApp == null) {
1842 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1843 request.result = -1;
1844 loge("Failed to get UICC App");
1845 notifyRequester(request);
1846 } else {
1847 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1848 ((SIMRecords) uiccApp.getIccRecords())
1849 .setForbiddenPlmns(onCompleted, fplmns);
1850 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001851 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001852 case CMD_ERASE_MODEM_CONFIG:
1853 request = (MainThreadRequest) msg.obj;
1854 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1855 defaultPhone.eraseModemConfig(onCompleted);
1856 break;
1857 case EVENT_ERASE_MODEM_CONFIG_DONE:
1858 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001859 break;
zoey chene02881a2019-12-30 16:11:23 +08001860
Kai Shif70f46f2021-03-03 13:59:46 -08001861 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1862 request = (MainThreadRequest) msg.obj;
1863 request.result = defaultPhone.eraseDataInSharedPreferences();
1864 notifyRequester(request);
1865 break;
1866
zoey chene02881a2019-12-30 16:11:23 +08001867 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1868 request = (MainThreadRequest) msg.obj;
1869 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1870 Pair<String, String> changed = (Pair<String, String>) request.argument;
1871 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1872 changed.first, changed.second, onCompleted);
1873 break;
1874 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1875 ar = (AsyncResult) msg.obj;
1876 request = (MainThreadRequest) ar.userObj;
1877 if (ar.exception == null) {
1878 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001879 // If the operation is successful, update the PIN storage
1880 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1881 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001882 UiccController.getInstance().getPinStorage()
1883 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001884 } else {
1885 request.result = msg.arg1;
1886 }
1887 notifyRequester(request);
1888 break;
1889
Michele Berionne5e411512020-11-13 02:36:59 +00001890 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001891 request = (MainThreadRequest) msg.obj;
1892 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1893 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1894 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1895 enabled.first, enabled.second, onCompleted);
1896 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001897 }
zoey chene02881a2019-12-30 16:11:23 +08001898 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1899 ar = (AsyncResult) msg.obj;
1900 request = (MainThreadRequest) ar.userObj;
1901 if (ar.exception == null) {
1902 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001903 // If the operation is successful, update the PIN storage
1904 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1905 int phoneId = getPhoneFromRequest(request).getPhoneId();
1906 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001907 UiccController.getInstance().getPinStorage()
1908 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001909 } else {
1910 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1911 }
zoey chene02881a2019-12-30 16:11:23 +08001912 } else {
1913 request.result = msg.arg1;
1914 }
Michele Berionne5e411512020-11-13 02:36:59 +00001915
1916
zoey chene02881a2019-12-30 16:11:23 +08001917 notifyRequester(request);
1918 break;
1919
Peter Wangdafb9ac2020-01-15 14:13:38 -08001920 case MSG_NOTIFY_USER_ACTIVITY:
1921 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001922 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001923 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1924 getDefaultPhone().getContext().sendBroadcastAsUser(
1925 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1926 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001927
1928 case CMD_SET_DATA_THROTTLING: {
1929 request = (MainThreadRequest) msg.obj;
1930 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1931 DataThrottlingRequest dataThrottlingRequest =
1932 (DataThrottlingRequest) request.argument;
1933 Phone phone = getPhoneFromRequest(request);
1934 if (phone != null) {
1935 phone.setDataThrottling(onCompleted,
1936 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1937 dataThrottlingRequest.getCompletionDurationMillis());
1938 } else {
1939 loge("setDataThrottling: No phone object");
1940 request.result =
1941 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1942 notifyRequester(request);
1943 }
1944
1945 break;
1946 }
1947 case EVENT_SET_DATA_THROTTLING_DONE:
1948 ar = (AsyncResult) msg.obj;
1949 request = (MainThreadRequest) ar.userObj;
1950
1951 if (ar.exception == null) {
1952 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1953 } else if (ar.exception instanceof CommandException) {
1954 loge("setDataThrottling: CommandException: " + ar.exception);
1955 CommandException.Error error =
1956 ((CommandException) (ar.exception)).getCommandError();
1957
1958 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1959 request.result = TelephonyManager
1960 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1961 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1962 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001963 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1964 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001965 } else {
1966 request.result =
1967 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1968 }
1969 } else {
1970 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1971 }
1972 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1973 notifyRequester(request);
1974 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001975
1976 case CMD_SET_SIM_POWER: {
1977 request = (MainThreadRequest) msg.obj;
1978 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1979 request = (MainThreadRequest) msg.obj;
1980 int stateToSet =
1981 ((Pair<Integer, IIntegerConsumer>)
1982 request.argument).first;
1983 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1984 break;
1985 }
1986 case EVENT_SET_SIM_POWER_DONE: {
1987 ar = (AsyncResult) msg.obj;
1988 request = (MainThreadRequest) ar.userObj;
1989 IIntegerConsumer callback =
1990 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1991 if (ar.exception != null) {
1992 loge("setSimPower exception: " + ar.exception);
1993 int errorCode = TelephonyManager.CallForwardingInfoCallback
1994 .RESULT_ERROR_UNKNOWN;
1995 if (ar.exception instanceof CommandException) {
1996 CommandException.Error error =
1997 ((CommandException) (ar.exception)).getCommandError();
1998 if (error == CommandException.Error.SIM_ERR) {
1999 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2000 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2001 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2002 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2003 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2004 } else {
2005 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2006 }
2007 }
2008 try {
2009 callback.accept(errorCode);
2010 } catch (RemoteException e) {
2011 // Ignore if the remote process is no longer available to call back.
2012 Log.w(LOG_TAG, "setSimPower: callback not available.");
2013 }
2014 } else {
2015 try {
2016 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2017 } catch (RemoteException e) {
2018 // Ignore if the remote process is no longer available to call back.
2019 Log.w(LOG_TAG, "setSimPower: callback not available.");
2020 }
2021 }
2022 break;
2023 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002024 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2025 request = (MainThreadRequest) msg.obj;
2026
2027 final Phone phone = getPhoneFromRequest(request);
2028 if (phone == null || phone.getServiceStateTracker() == null) {
2029 request.result = new IllegalStateException("Phone or SST is null");
2030 notifyRequester(request);
2031 break;
2032 }
2033
2034 Pair<Integer, SignalStrengthUpdateRequest> pair =
2035 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2036 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2037 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002038 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002039 request.subId, pair.first /*callingUid*/,
2040 pair.second /*request*/, onCompleted);
2041 break;
2042 }
2043 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2044 ar = (AsyncResult) msg.obj;
2045 request = (MainThreadRequest) ar.userObj;
2046 // request.result will be the exception of ar if present, true otherwise.
2047 // Be cautious not to leave result null which will wait() forever
2048 request.result = ar.exception != null ? ar.exception : true;
2049 notifyRequester(request);
2050 break;
2051 }
2052 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2053 request = (MainThreadRequest) msg.obj;
2054
2055 Phone phone = getPhoneFromRequest(request);
2056 if (phone == null || phone.getServiceStateTracker() == null) {
2057 request.result = new IllegalStateException("Phone or SST is null");
2058 notifyRequester(request);
2059 break;
2060 }
2061
2062 Pair<Integer, SignalStrengthUpdateRequest> pair =
2063 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2064 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2065 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002066 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002067 request.subId, pair.first /*callingUid*/,
2068 pair.second /*request*/, onCompleted);
2069 break;
2070 }
2071 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2072 ar = (AsyncResult) msg.obj;
2073 request = (MainThreadRequest) ar.userObj;
2074 request.result = ar.exception != null ? ar.exception : true;
2075 notifyRequester(request);
2076 break;
2077 }
Jordan Liu109698e2020-11-24 14:50:34 -08002078
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002079 case CMD_GET_SLICING_CONFIG: {
2080 request = (MainThreadRequest) msg.obj;
2081 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2082 request.phone.getSlicingConfig(onCompleted);
2083 break;
2084 }
2085 case EVENT_GET_SLICING_CONFIG_DONE: {
2086 ar = (AsyncResult) msg.obj;
2087 request = (MainThreadRequest) ar.userObj;
2088 ResultReceiver result = (ResultReceiver) request.argument;
2089
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002090 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002091 Bundle bundle = new Bundle();
2092 int resultCode = 0;
2093 if (ar.exception != null) {
2094 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2095 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002096 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002097 } else if (ar.result == null) {
2098 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002099 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002100 } else {
2101 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002102 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2103 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002104 }
2105
2106 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002107 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002108 }
2109 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2110 result.send(resultCode, bundle);
2111 notifyRequester(request);
2112 break;
2113 }
2114
Michele Berionne5e411512020-11-13 02:36:59 +00002115 case CMD_PREPARE_UNATTENDED_REBOOT:
2116 request = (MainThreadRequest) msg.obj;
2117 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002118 UiccController.getInstance().getPinStorage()
2119 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002120 notifyRequester(request);
2121 break;
2122
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 default:
2124 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2125 break;
2126 }
2127 }
Jake Hambye994d462014-02-03 13:10:13 -08002128
Pengquan Menga1bb6272018-09-06 09:59:22 -07002129 private void notifyRequester(MainThreadRequest request) {
2130 synchronized (request) {
2131 request.notifyAll();
2132 }
2133 }
2134
Jake Hambye994d462014-02-03 13:10:13 -08002135 private void handleNullReturnEvent(Message msg, String command) {
2136 AsyncResult ar = (AsyncResult) msg.obj;
2137 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2138 if (ar.exception == null) {
2139 request.result = true;
2140 } else {
2141 request.result = false;
2142 if (ar.exception instanceof CommandException) {
2143 loge(command + ": CommandException: " + ar.exception);
2144 } else {
2145 loge(command + ": Unknown exception");
2146 }
2147 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002148 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 }
2151
2152 /**
2153 * Posts the specified command to be executed on the main thread,
2154 * waits for the request to complete, and returns the result.
2155 * @see #sendRequestAsync
2156 */
2157 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002158 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2159 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002160 }
2161
2162 /**
2163 * Posts the specified command to be executed on the main thread,
2164 * waits for the request to complete, and returns the result.
2165 * @see #sendRequestAsync
2166 */
2167 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2168 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002169 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002170 }
2171
2172 /**
2173 * Posts the specified command to be executed on the main thread,
2174 * waits for the request to complete, and returns the result.
2175 * @see #sendRequestAsync
2176 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002177 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002178 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2179 }
2180
2181 /**
2182 * Posts the specified command to be executed on the main thread,
2183 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2184 * if not timeout or null otherwise.
2185 * @see #sendRequestAsync
2186 */
2187 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2188 long timeoutInMs) {
2189 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002190 }
2191
2192 /**
2193 * Posts the specified command to be executed on the main thread,
2194 * waits for the request to complete, and returns the result.
2195 * @see #sendRequestAsync
2196 */
Nathan Harold92bed182018-10-12 18:16:49 -07002197 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002198 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002199 }
2200
2201 /**
2202 * Posts the specified command to be executed on the main thread,
2203 * waits for the request to complete, and returns the result.
2204 * @see #sendRequestAsync
2205 */
2206 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002207 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2208 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002209 }
2210
2211 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002212 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2213 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2214 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002215 * @see #sendRequestAsync
2216 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002217 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2218 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2220 throw new RuntimeException("This method will deadlock if called from the main thread.");
2221 }
2222
Nathan Harold92bed182018-10-12 18:16:49 -07002223 MainThreadRequest request = null;
2224 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2225 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2226 } else if (phone != null) {
2227 request = new MainThreadRequest(argument, phone, workSource);
2228 } else {
2229 request = new MainThreadRequest(argument, subId, workSource);
2230 }
2231
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 Message msg = mMainThreadHandler.obtainMessage(command, request);
2233 msg.sendToTarget();
2234
Rambo Wang0f050d82021-02-12 11:43:36 -08002235
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002237 if (timeoutInMs >= 0) {
2238 // Wait for at least timeoutInMs before returning null request result
2239 long now = SystemClock.elapsedRealtime();
2240 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002241 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002242 try {
2243 request.wait(deadline - now);
2244 } catch (InterruptedException e) {
2245 // Do nothing, go back and check if request is completed or timeout
2246 } finally {
2247 now = SystemClock.elapsedRealtime();
2248 }
2249 }
2250 } else {
2251 // Wait for the request to complete
2252 while (request.result == null) {
2253 try {
2254 request.wait();
2255 } catch (InterruptedException e) {
2256 // Do nothing, go back and wait until the request is complete
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
2259 }
2260 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002261 if (request.result == null) {
2262 Log.wtf(LOG_TAG,
2263 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 return request.result;
2266 }
2267
2268 /**
2269 * Asynchronous ("fire and forget") version of sendRequest():
2270 * Posts the specified command to be executed on the main thread, and
2271 * returns immediately.
2272 * @see #sendRequest
2273 */
2274 private void sendRequestAsync(int command) {
2275 mMainThreadHandler.sendEmptyMessage(command);
2276 }
2277
2278 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002279 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002280 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002281 */
2282 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002283 sendRequestAsync(command, argument, null, null);
2284 }
2285
2286 /**
2287 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2288 * @see {@link #sendRequest(int,Object)}
2289 */
2290 private void sendRequestAsync(
2291 int command, Object argument, Phone phone, WorkSource workSource) {
2292 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002293 Message msg = mMainThreadHandler.obtainMessage(command, request);
2294 msg.sendToTarget();
2295 }
2296
2297 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 * Initialize the singleton PhoneInterfaceManager instance.
2299 * This is only done once, at startup, from PhoneApp.onCreate().
2300 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002301 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002302 synchronized (PhoneInterfaceManager.class) {
2303 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002304 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 } else {
2306 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2307 }
2308 return sInstance;
2309 }
2310 }
2311
2312 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002313 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002316 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002317 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002319 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002321 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002322 mTelephonySharedPreferences =
2323 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002324 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002325 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002326 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002327 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 publish();
2330 }
2331
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002332 private Phone getDefaultPhone() {
2333 Phone thePhone = getPhone(getDefaultSubscription());
2334 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2335 }
2336
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 private void publish() {
2338 if (DBG) log("publish: " + this);
2339
Peter Wangc035ce42020-01-08 21:00:22 -08002340 TelephonyFrameworkInitializer
2341 .getTelephonyServiceManager()
2342 .getTelephonyServiceRegisterer()
2343 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 }
2345
Stuart Scott584921c2015-01-15 17:10:34 -08002346 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002347 if (request.phone != null) {
2348 return request.phone;
2349 } else {
2350 return getPhoneFromSubId(request.subId);
2351 }
2352 }
2353
2354 private Phone getPhoneFromSubId(int subId) {
2355 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2356 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002357 }
2358
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002359 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002360 Phone phone = getPhoneFromRequest(request);
2361 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002362 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002363 }
2364
Wink Saville36469e72014-06-11 15:17:00 -07002365 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002366 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002367 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369
Kai Shif70f46f2021-03-03 13:59:46 -08002370 private void sendEraseModemConfig(@NonNull Phone phone) {
2371 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2372 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2373 }
2374
2375 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2376 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2377 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002378 }
2379
Peter Wang44b186e2020-01-13 23:33:09 -08002380 private boolean isImsAvailableOnDevice() {
2381 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2382 if (pm == null) {
2383 // For some reason package manger is not available.. This will fail internally anyway,
2384 // so do not throw error and allow.
2385 return true;
2386 }
2387 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2388 }
2389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002391 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002392 }
2393
Wink Savilleb564aae2014-10-23 10:18:09 -07002394 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 if (DBG) log("dial: " + number);
2396 // No permission check needed here: This is just a wrapper around the
2397 // ACTION_DIAL intent, which is available to any app since it puts up
2398 // the UI before it does anything.
2399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002400 final long identity = Binder.clearCallingIdentity();
2401 try {
2402 String url = createTelUrl(number);
2403 if (url == null) {
2404 return;
2405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002407 // PENDING: should we just silently fail if phone is offhook or ringing?
2408 PhoneConstants.State state = mCM.getState(subId);
2409 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2410 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2411 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2412 mApp.startActivity(intent);
2413 }
2414 } finally {
2415 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 }
2417 }
2418
2419 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002420 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002421 }
2422
Wink Savilleb564aae2014-10-23 10:18:09 -07002423 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 if (DBG) log("call: " + number);
2425
2426 // This is just a wrapper around the ACTION_CALL intent, but we still
2427 // need to do a permission check since we're calling startActivity()
2428 // from the context of the phone app.
2429 enforceCallPermission();
2430
Jordan Liu1617b712019-07-10 15:06:26 -07002431 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 != AppOpsManager.MODE_ALLOWED) {
2433 return;
2434 }
2435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436 final long identity = Binder.clearCallingIdentity();
2437 try {
2438 String url = createTelUrl(number);
2439 if (url == null) {
2440 return;
2441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443 boolean isValid = false;
2444 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2445 if (slist != null) {
2446 for (SubscriptionInfo subInfoRecord : slist) {
2447 if (subInfoRecord.getSubscriptionId() == subId) {
2448 isValid = true;
2449 break;
2450 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002451 }
Wink Saville08874612014-08-31 19:19:58 -07002452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453 if (!isValid) {
2454 return;
2455 }
Wink Saville08874612014-08-31 19:19:58 -07002456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2458 intent.putExtra(SUBSCRIPTION_KEY, subId);
2459 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2460 mApp.startActivity(intent);
2461 } finally {
2462 Binder.restoreCallingIdentity(identity);
2463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465
Wink Savilleb564aae2014-10-23 10:18:09 -07002466 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002467 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002468 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2469 }
2470
Wink Savilleb564aae2014-10-23 10:18:09 -07002471 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002472 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002473 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2474 }
2475
Wink Savilleb564aae2014-10-23 10:18:09 -07002476 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478
2479 final long identity = Binder.clearCallingIdentity();
2480 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002481 Phone phone = getPhone(subId);
2482 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483 checkSimPin.start();
2484 return checkSimPin.unlockSim(null, pin);
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
2487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 }
2489
Wink Savilleb564aae2014-10-23 10:18:09 -07002490 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492
2493 final long identity = Binder.clearCallingIdentity();
2494 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002495 Phone phone = getPhone(subId);
2496 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002497 checkSimPuk.start();
2498 return checkSimPuk.unlockSim(puk, pin);
2499 } finally {
2500 Binder.restoreCallingIdentity(identity);
2501 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 }
2503
2504 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002505 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 * a synchronous one.
2507 */
2508 private static class UnlockSim extends Thread {
2509
2510 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002511 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512
2513 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002514 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2515 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516
2517 // For replies from SimCard interface
2518 private Handler mHandler;
2519
2520 // For async handler to identify request type
2521 private static final int SUPPLY_PIN_COMPLETE = 100;
2522
Michele Berionne5e411512020-11-13 02:36:59 +00002523 UnlockSim(int phoneId, IccCard simCard) {
2524 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 mSimCard = simCard;
2526 }
2527
2528 @Override
2529 public void run() {
2530 Looper.prepare();
2531 synchronized (UnlockSim.this) {
2532 mHandler = new Handler() {
2533 @Override
2534 public void handleMessage(Message msg) {
2535 AsyncResult ar = (AsyncResult) msg.obj;
2536 switch (msg.what) {
2537 case SUPPLY_PIN_COMPLETE:
2538 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2539 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002540 mRetryCount = msg.arg1;
2541 if (ar.exception != null) {
2542 if (ar.exception instanceof CommandException &&
2543 ((CommandException)(ar.exception)).getCommandError()
2544 == CommandException.Error.PASSWORD_INCORRECT) {
2545 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002546 } //When UiccCardApp dispose,handle message and return exception
2547 else if (ar.exception instanceof CommandException &&
2548 ((CommandException) (ar.exception)).getCommandError()
2549 == CommandException.Error.ABORTED) {
2550 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002551 } else {
2552 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2553 }
2554 } else {
2555 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 mDone = true;
2558 UnlockSim.this.notifyAll();
2559 }
2560 break;
2561 }
2562 }
2563 };
2564 UnlockSim.this.notifyAll();
2565 }
2566 Looper.loop();
2567 }
2568
2569 /*
2570 * Use PIN or PUK to unlock SIM card
2571 *
2572 * If PUK is null, unlock SIM card with PIN
2573 *
2574 * If PUK is not null, unlock SIM card with PUK and set PIN code
2575 */
Wink Saville9de0f752013-10-22 19:04:03 -07002576 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577
2578 while (mHandler == null) {
2579 try {
2580 wait();
2581 } catch (InterruptedException e) {
2582 Thread.currentThread().interrupt();
2583 }
2584 }
2585 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2586
2587 if (puk == null) {
2588 mSimCard.supplyPin(pin, callback);
2589 } else {
2590 mSimCard.supplyPuk(puk, pin, callback);
2591 }
2592
2593 while (!mDone) {
2594 try {
2595 Log.d(LOG_TAG, "wait for done");
2596 wait();
2597 } catch (InterruptedException e) {
2598 // Restore the interrupted status
2599 Thread.currentThread().interrupt();
2600 }
2601 }
2602 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002603 int[] resultArray = new int[2];
2604 resultArray[0] = mResult;
2605 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002606
2607 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002608 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002609 }
2610
Wink Saville9de0f752013-10-22 19:04:03 -07002611 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 }
2613 }
2614
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002615 /**
2616 * This method has been removed due to privacy and stability concerns.
2617 */
2618 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002620 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2621 return;
Wink Saville36469e72014-06-11 15:17:00 -07002622 }
2623
Nathan Harold1f889d82020-06-04 17:05:26 -07002624 @Override
2625 public void updateServiceLocationWithPackageName(String callingPackage) {
2626 mApp.getSystemService(AppOpsManager.class)
2627 .checkPackage(Binder.getCallingUid(), callingPackage);
2628
Nathan Haroldf096d982020-11-18 17:18:06 -08002629 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002630 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2631 // Callers targeting S have no business invoking this method.
2632 return;
2633 }
2634
2635 LocationAccessPolicy.LocationPermissionResult locationResult =
2636 LocationAccessPolicy.checkLocationPermission(mApp,
2637 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2638 .setCallingPackage(callingPackage)
2639 .setCallingFeatureId(null)
2640 .setCallingPid(Binder.getCallingPid())
2641 .setCallingUid(Binder.getCallingUid())
2642 .setMethod("updateServiceLocation")
2643 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2644 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2645 .build());
2646 // Apps that lack location permission have no business calling this method;
2647 // however, because no permission was declared in the public API, denials must
2648 // all be "soft".
2649 switch (locationResult) {
2650 case DENIED_HARD: /* fall through */
2651 case DENIED_SOFT:
2652 return;
2653 }
2654
2655 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656 final long identity = Binder.clearCallingIdentity();
2657 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002658 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002660 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 }
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 }
2666
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002667 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002668 @Override
2669 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002670 return isRadioOnWithFeature(callingPackage, null);
2671 }
2672
2673
2674 @Override
2675 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2676 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2677 callingFeatureId);
2678 }
2679
2680 @Deprecated
2681 @Override
2682 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2683 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002684 }
2685
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002686 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002687 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2688 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002690 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002691 return false;
2692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693
2694 final long identity = Binder.clearCallingIdentity();
2695 try {
2696 return isRadioOnForSubscriber(subId);
2697 } finally {
2698 Binder.restoreCallingIdentity(identity);
2699 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002700 }
2701
2702 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 final Phone phone = getPhone(subId);
2706 if (phone != null) {
2707 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2708 } else {
2709 return false;
2710 }
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
2716 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002717 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 }
Wink Saville36469e72014-06-11 15:17:00 -07002719
Wink Savilleb564aae2014-10-23 10:18:09 -07002720 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722
2723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 final Phone phone = getPhone(subId);
2726 if (phone != null) {
2727 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2728 }
2729 } finally {
2730 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002731 }
Wink Saville36469e72014-06-11 15:17:00 -07002732 }
2733
2734 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002735 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002736 }
2737
Wink Savilleb564aae2014-10-23 10:18:09 -07002738 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002739 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740
2741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 final Phone phone = getPhone(subId);
2744 if (phone == null) {
2745 return false;
2746 }
2747 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2748 toggleRadioOnOffForSubscriber(subId);
2749 }
2750 return true;
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002753 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 }
Wink Saville36469e72014-06-11 15:17:00 -07002755
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002756 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002757 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002758 /*
2759 * If any of the Radios are available, it will need to be
2760 * shutdown. So return true if any Radio is available.
2761 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2765 Phone phone = PhoneFactory.getPhone(i);
2766 if (phone != null && phone.isRadioAvailable()) return true;
2767 }
2768 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2769 return false;
2770 } finally {
2771 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002772 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002773 }
2774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002775 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002776 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777 enforceModifyPermission();
2778
2779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2782 logv("Shutting down Phone " + i);
2783 shutdownRadioUsingPhoneId(i);
2784 }
2785 } finally {
2786 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002787 }
2788 }
2789
2790 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002791 Phone phone = PhoneFactory.getPhone(phoneId);
2792 if (phone != null && phone.isRadioAvailable()) {
2793 phone.shutdownRadio();
2794 }
2795 }
2796
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002798 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2803 if (defaultPhone != null) {
2804 defaultPhone.setRadioPower(turnOn);
2805 return true;
2806 } else {
2807 loge("There's no default phone.");
2808 return false;
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002812 }
Wink Saville36469e72014-06-11 15:17:00 -07002813 }
2814
Wink Savilleb564aae2014-10-23 10:18:09 -07002815 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002816 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817
2818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 final Phone phone = getPhone(subId);
2821 if (phone != null) {
2822 phone.setRadioPower(turnOn);
2823 return true;
2824 } else {
2825 return false;
2826 }
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 }
2831
Wink Saville36469e72014-06-11 15:17:00 -07002832 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002833 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 public boolean enableDataConnectivity() {
2835 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 int subId = mSubscriptionController.getDefaultDataSubId();
2840 final Phone phone = getPhone(subId);
2841 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002842 phone.getDataEnabledSettings().setDataEnabled(
2843 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844 return true;
2845 } else {
2846 return false;
2847 }
2848 } finally {
2849 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002850 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 }
2852
Wink Saville36469e72014-06-11 15:17:00 -07002853 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002854 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 public boolean disableDataConnectivity() {
2856 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857
2858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 int subId = mSubscriptionController.getDefaultDataSubId();
2861 final Phone phone = getPhone(subId);
2862 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002863 phone.getDataEnabledSettings().setDataEnabled(
2864 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 return true;
2866 } else {
2867 return false;
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 }
2873
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002875 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 final long identity = Binder.clearCallingIdentity();
2877 try {
2878 final Phone phone = getPhone(subId);
2879 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002880 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881 } else {
2882 return false;
2883 }
2884 } finally {
2885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 }
2888
2889 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002890 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002891 }
2892
pkanwarae03a6b2016-11-06 20:37:09 -08002893 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 enforceCallPermission();
2895
2896 final long identity = Binder.clearCallingIdentity();
2897 try {
2898 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2899 return;
2900 }
2901 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2902 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
2905 }
pkanwar32d516d2016-10-14 19:37:38 -07002906 };
2907
Wink Savilleb564aae2014-10-23 10:18:09 -07002908 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002909 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910
2911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2914 return false;
2915 }
2916 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 }
2921
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002922 /**
2923 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2924 * tag on getCallState Binder call.
2925 */
2926 @Deprecated
2927 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002929 if (CompatChanges.isChangeEnabled(
2930 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2931 Binder.getCallingUid())) {
2932 // Do not allow this API to be called on API version 31+, it should only be
2933 // called on old apps using this Binder call directly.
2934 throw new SecurityException("This method can only be used for applications "
2935 + "targeting API version 30 or less.");
2936 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 final long identity = Binder.clearCallingIdentity();
2938 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002939 Phone phone = getPhone(getDefaultSubscription());
2940 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2941 PhoneConstantConversions.convertCallState(phone.getState());
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
2944 }
2945 }
2946
2947 @Override
2948 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2949 if (CompatChanges.isChangeEnabled(
2950 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2951 Binder.getCallingUid())) {
2952 // Check READ_PHONE_STATE for API version 31+
2953 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2954 featureId, "getCallStateForSubscription")) {
2955 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2956 + "targeting API level 31+.");
2957 }
2958 }
2959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2963 PhoneConstantConversions.convertCallState(phone.getState());
2964 } finally {
2965 Binder.restoreCallingIdentity(identity);
2966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002967 }
2968
Sanket Padawe356d7632015-06-22 14:03:32 -07002969 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002970 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002971 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2972 }
2973
2974 @Override
2975 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976 final long identity = Binder.clearCallingIdentity();
2977 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002978 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08002980 if (phone.isUsingNewDataStack()) {
2981 return phone.getDataNetworkController().getInternetDataNetworkState();
2982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2984 } else {
2985 return PhoneConstantConversions.convertDataState(
2986 PhoneConstants.DataState.DISCONNECTED);
2987 }
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 }
2992
Sanket Padawe356d7632015-06-22 14:03:32 -07002993 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002994 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002995 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2996 }
2997
2998 @Override
2999 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 final long identity = Binder.clearCallingIdentity();
3001 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003002 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 if (phone != null) {
3004 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3005 } else {
3006 return TelephonyManager.DATA_ACTIVITY_NONE;
3007 }
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003011 }
3012
3013 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003014 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003015 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003016 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003017
3018 LocationAccessPolicy.LocationPermissionResult locationResult =
3019 LocationAccessPolicy.checkLocationPermission(mApp,
3020 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3021 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003022 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003023 .setCallingPid(Binder.getCallingPid())
3024 .setCallingUid(Binder.getCallingUid())
3025 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003026 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003027 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3028 .build());
3029 switch (locationResult) {
3030 case DENIED_HARD:
3031 throw new SecurityException("Not allowed to access cell location");
3032 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003033 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3034 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003035 }
3036
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003037 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038 final long identity = Binder.clearCallingIdentity();
3039 try {
3040 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003041 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003042 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043 } finally {
3044 Binder.restoreCallingIdentity(identity);
3045 }
Svetoslav64fad262015-04-14 14:35:21 -07003046 }
3047
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003049 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003050 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3051 // registered cell info, so return a NULL country instead.
3052 final long identity = Binder.clearCallingIdentity();
3053 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003054 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3055 // Get default phone in this case.
3056 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3057 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003058 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003060 if (phone == null) return "";
3061 ServiceStateTracker sst = phone.getServiceStateTracker();
3062 if (sst == null) return "";
3063 LocaleTracker lt = sst.getLocaleTracker();
3064 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003065 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003069 }
3070
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003071 /**
3072 * This method was removed due to potential issues caused by performing partial
3073 * updates of service state, and lack of a credible use case.
3074 *
3075 * This has the ability to break the telephony implementation by disabling notification of
3076 * changes in device connectivity. DO NOT USE THIS!
3077 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003078 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003079 public void enableLocationUpdates() {
3080 mApp.enforceCallingOrSelfPermission(
3081 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003082 }
3083
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003084 /**
3085 * This method was removed due to potential issues caused by performing partial
3086 * updates of service state, and lack of a credible use case.
3087 *
3088 * This has the ability to break the telephony implementation by disabling notification of
3089 * changes in device connectivity. DO NOT USE THIS!
3090 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091 @Override
3092 public void disableLocationUpdates() {
3093 mApp.enforceCallingOrSelfPermission(
3094 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003095 }
3096
3097 @Override
3098 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003099 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3100 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003101 try {
3102 mApp.getSystemService(AppOpsManager.class)
3103 .checkPackage(Binder.getCallingUid(), callingPackage);
3104 } catch (SecurityException e) {
3105 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3106 throw e;
3107 }
3108
Nathan Haroldf096d982020-11-18 17:18:06 -08003109 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003110 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3111 throw new SecurityException(
3112 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3113 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003114
Jordan Liu1617b712019-07-10 15:06:26 -07003115 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3117 return null;
3118 }
Svetoslav64fad262015-04-14 14:35:21 -07003119
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003120 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003121
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003122 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003123 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003124
Nathan Haroldf180aac2018-06-01 18:43:55 -07003125 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3126 for (CellInfo ci : info) {
3127 if (ci instanceof CellInfoGsm) {
3128 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3129 } else if (ci instanceof CellInfoWcdma) {
3130 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003133 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003134 }
3135
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003136 private List<CellInfo> getCachedCellInfo() {
3137 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3138 for (Phone phone : PhoneFactory.getPhones()) {
3139 List<CellInfo> info = phone.getAllCellInfo();
3140 if (info != null) cellInfos.addAll(info);
3141 }
3142 return cellInfos;
3143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144
3145 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003146 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003147 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003148 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003149
3150 LocationAccessPolicy.LocationPermissionResult locationResult =
3151 LocationAccessPolicy.checkLocationPermission(mApp,
3152 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3153 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003154 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003155 .setCallingPid(Binder.getCallingPid())
3156 .setCallingUid(Binder.getCallingUid())
3157 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003158 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003159 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3160 .build());
3161 switch (locationResult) {
3162 case DENIED_HARD:
3163 throw new SecurityException("Not allowed to access cell info");
3164 case DENIED_SOFT:
3165 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003166 }
3167
Nathan Haroldf096d982020-11-18 17:18:06 -08003168 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003169 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3170 return getCachedCellInfo();
3171 }
3172
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003173 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003174 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3178 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003179 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003180 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181 if (info != null) cellInfos.addAll(info);
3182 }
3183 return cellInfos;
3184 } finally {
3185 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 }
3187 }
3188
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003189 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003190 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3191 String callingFeatureId) {
3192 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3193 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003194 }
3195
3196 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003197 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3198 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003199 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003200 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003201 }
3202
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003203 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3204 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003205 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003206 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003207
3208 LocationAccessPolicy.LocationPermissionResult locationResult =
3209 LocationAccessPolicy.checkLocationPermission(mApp,
3210 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3211 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003212 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003213 .setCallingPid(Binder.getCallingPid())
3214 .setCallingUid(Binder.getCallingUid())
3215 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003216 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3217 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003218 .build());
3219 switch (locationResult) {
3220 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003221 if (TelephonyPermissions
3222 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003223 // Safetynet logging for b/154934934
3224 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3225 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003226 throw new SecurityException("Not allowed to access cell info");
3227 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003228 if (TelephonyPermissions
3229 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003230 // Safetynet logging for b/154934934
3231 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3232 }
Nathan Harold5320c422019-05-09 10:26:08 -07003233 try {
3234 cb.onCellInfo(new ArrayList<CellInfo>());
3235 } catch (RemoteException re) {
3236 // Drop without consequences
3237 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003238 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003239 }
3240
Nathan Harolda939a962019-05-09 10:13:47 -07003241
3242 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003243 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3244
3245 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3246 }
3247
3248 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003249 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003250 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003251 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252
3253 final long identity = Binder.clearCallingIdentity();
3254 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003255 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003256 } finally {
3257 Binder.restoreCallingIdentity(identity);
3258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 }
3260
Shishir Agrawala9f32182016-04-12 12:00:16 -07003261 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003262 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003263 Phone phone = PhoneFactory.getPhone(slotIndex);
3264 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003265 return null;
3266 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003267 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003268 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003269 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003270 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003271 return null;
3272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273
3274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 return phone.getImei();
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
3279 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003280 }
3281
3282 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003283 public String getTypeAllocationCodeForSlot(int slotIndex) {
3284 Phone phone = PhoneFactory.getPhone(slotIndex);
3285 String tac = null;
3286 if (phone != null) {
3287 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003288 try {
3289 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3290 } catch (IndexOutOfBoundsException e) {
3291 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3292 return null;
3293 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003294 }
3295 return tac;
3296 }
3297
3298 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003299 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003300 try {
3301 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3302 } catch (SecurityException se) {
3303 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3304 throw new SecurityException("Package " + callingPackage + " does not belong to "
3305 + Binder.getCallingUid());
3306 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003307 Phone phone = PhoneFactory.getPhone(slotIndex);
3308 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003309 return null;
3310 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003311
Jeff Davidson913390f2018-02-23 17:11:49 -08003312 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003313 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003314 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003315 return null;
3316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003317
3318 final long identity = Binder.clearCallingIdentity();
3319 try {
3320 return phone.getMeid();
3321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
Jack Yu2af8d712017-03-15 17:14:14 -07003324 }
3325
3326 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003327 public String getManufacturerCodeForSlot(int slotIndex) {
3328 Phone phone = PhoneFactory.getPhone(slotIndex);
3329 String manufacturerCode = null;
3330 if (phone != null) {
3331 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003332 try {
3333 manufacturerCode =
3334 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3335 } catch (IndexOutOfBoundsException e) {
3336 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3337 return null;
3338 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003339 }
3340 return manufacturerCode;
3341 }
3342
3343 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003344 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3345 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003346 Phone phone = PhoneFactory.getPhone(slotIndex);
3347 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003348 return null;
3349 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003350 int subId = phone.getSubId();
3351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003352 mApp, subId, callingPackage, callingFeatureId,
3353 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003354 return null;
3355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003356
3357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 return phone.getDeviceSvn();
3360 } finally {
3361 Binder.restoreCallingIdentity(identity);
3362 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003363 }
3364
fionaxu43304da2017-11-27 22:51:16 -08003365 @Override
3366 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 final long identity = Binder.clearCallingIdentity();
3368 try {
3369 final Phone phone = getPhone(subId);
3370 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3371 } finally {
3372 Binder.restoreCallingIdentity(identity);
3373 }
fionaxu43304da2017-11-27 22:51:16 -08003374 }
3375
3376 @Override
3377 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 final Phone phone = getPhone(subId);
3381 return phone == null ? null : phone.getCarrierName();
3382 } finally {
3383 Binder.restoreCallingIdentity(identity);
3384 }
fionaxu43304da2017-11-27 22:51:16 -08003385 }
3386
calvinpanffe225e2018-11-01 19:43:06 +08003387 @Override
chen xu0026ca62019-03-06 15:28:50 -08003388 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 final Phone phone = getPhone(subId);
3392 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003393 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003394 } finally {
3395 Binder.restoreCallingIdentity(identity);
3396 }
3397 }
3398
3399 @Override
chen xu0026ca62019-03-06 15:28:50 -08003400 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003404 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003405 } finally {
3406 Binder.restoreCallingIdentity(identity);
3407 }
3408 }
3409
chen xu651eec72018-11-11 19:03:44 -08003410 @Override
chen xu864e11c2018-12-06 22:10:03 -08003411 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3412 if (!isSubscriptionMccMnc) {
3413 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3414 }
chen xu651eec72018-11-11 19:03:44 -08003415 final Phone phone = PhoneFactory.getPhone(slotIndex);
3416 if (phone == null) {
3417 return TelephonyManager.UNKNOWN_CARRIER_ID;
3418 }
3419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
3425 }
3426
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003427 //
3428 // Internal helper methods.
3429 //
3430
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003431 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003432 * Make sure the caller is the calling package itself
3433 *
3434 * @throws SecurityException if the caller is not the calling package
3435 */
3436 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3437 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003438 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3439 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003440 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003441 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003442 } catch (PackageManager.NameNotFoundException e) {
3443 // packageUid is -1
3444 }
3445 if (packageUid != callingUid) {
3446 throw new SecurityException(message + ": Package " + callingPackage
3447 + " does not belong to " + callingUid);
3448 }
3449 }
3450
3451 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3453 *
3454 * @throws SecurityException if the caller does not have the required permission
3455 */
3456 private void enforceModifyPermission() {
3457 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3458 }
3459
Shuo Qian3b6ee772019-11-13 17:43:31 -08003460 private void enforceActiveEmergencySessionPermission() {
3461 mApp.enforceCallingOrSelfPermission(
3462 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3463 }
3464
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003465 /**
3466 * Make sure the caller has the CALL_PHONE permission.
3467 *
3468 * @throws SecurityException if the caller does not have the required permission
3469 */
3470 private void enforceCallPermission() {
3471 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3472 }
3473
paulhu5a773602019-08-23 19:17:33 +08003474 private void enforceSettingsPermission() {
3475 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003476 }
3477
Michele Berionne5e411512020-11-13 02:36:59 +00003478 private void enforceRebootPermission() {
3479 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3480 }
3481
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003482 private String createTelUrl(String number) {
3483 if (TextUtils.isEmpty(number)) {
3484 return null;
3485 }
3486
Jake Hambye994d462014-02-03 13:10:13 -08003487 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003488 }
3489
Ihab Awadf9e92732013-12-05 18:02:52 -08003490 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3492 }
3493
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003494 private static void logv(String msg) {
3495 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3496 }
3497
Ihab Awadf9e92732013-12-05 18:02:52 -08003498 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003499 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3500 }
3501
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003502 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003504 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003505 }
3506
Sanket Padawe356d7632015-06-22 14:03:32 -07003507 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003508 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 final Phone phone = PhoneFactory.getPhone(slotIndex);
3512 if (phone == null) {
3513 return PhoneConstants.PHONE_TYPE_NONE;
3514 } else {
3515 return phone.getPhoneType();
3516 }
3517 } finally {
3518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003520 }
3521
3522 /**
3523 * Returns the CDMA ERI icon index to display
3524 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003525 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003526 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3527 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3528 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003529 }
3530
Sanket Padawe356d7632015-06-22 14:03:32 -07003531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003532 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3533 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003535 mApp, subId, callingPackage, callingFeatureId,
3536 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003537 return -1;
3538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003539
3540 final long identity = Binder.clearCallingIdentity();
3541 try {
3542 final Phone phone = getPhone(subId);
3543 if (phone != null) {
3544 return phone.getCdmaEriIconIndex();
3545 } else {
3546 return -1;
3547 }
3548 } finally {
3549 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003551 }
3552
3553 /**
3554 * Returns the CDMA ERI icon mode,
3555 * 0 - ON
3556 * 1 - FLASHING
3557 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003558 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003559 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3560 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3561 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003562 }
3563
Sanket Padawe356d7632015-06-22 14:03:32 -07003564 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003565 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3566 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003568 mApp, subId, callingPackage, callingFeatureId,
3569 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003570 return -1;
3571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 final Phone phone = getPhone(subId);
3576 if (phone != null) {
3577 return phone.getCdmaEriIconMode();
3578 } else {
3579 return -1;
3580 }
3581 } finally {
3582 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003584 }
3585
3586 /**
3587 * Returns the CDMA ERI text,
3588 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003589 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003590 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3591 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3592 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003593 }
3594
Sanket Padawe356d7632015-06-22 14:03:32 -07003595 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003596 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3597 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003598 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003599 mApp, subId, callingPackage, callingFeatureId,
3600 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003601 return null;
3602 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003603
3604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 final Phone phone = getPhone(subId);
3607 if (phone != null) {
3608 return phone.getCdmaEriText();
3609 } else {
3610 return null;
3611 }
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003615 }
3616
3617 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003618 * Returns the CDMA MDN.
3619 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003620 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003621 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3623 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003624
3625 final long identity = Binder.clearCallingIdentity();
3626 try {
3627 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003628 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629 return phone.getLine1Number();
3630 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003631 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003632 return null;
3633 }
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003636 }
3637 }
3638
3639 /**
3640 * Returns the CDMA MIN.
3641 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003642 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003643 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3645 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646
3647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 final Phone phone = getPhone(subId);
3650 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3651 return phone.getCdmaMin();
3652 } else {
3653 return null;
3654 }
3655 } finally {
3656 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003657 }
3658 }
3659
Hall Liud892bec2018-11-30 14:51:45 -08003660 @Override
3661 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3662 INumberVerificationCallback callback, String callingPackage) {
3663 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3664 != PERMISSION_GRANTED) {
3665 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3666 }
3667 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3668
3669 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3670 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003671 throw new SecurityException("Calling package must be configured in the device config: "
3672 + "calling package: " + callingPackage
3673 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003674 }
3675
3676 if (range == null) {
3677 throw new NullPointerException("Range must be non-null");
3678 }
3679
3680 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003681 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003682
3683 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3684 }
3685
Junda Liuca05d5d2014-08-14 22:36:34 -07003686 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003687 * Returns true if CDMA provisioning needs to run.
3688 */
3689 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003690 final long identity = Binder.clearCallingIdentity();
3691 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003696 }
3697
3698 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003699 * Sets the voice mail number of a given subId.
3700 */
3701 @Override
3702 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003703 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3704 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003705
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3709 new Pair<String, String>(alphaTag, number), new Integer(subId));
3710 return success;
3711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003714 }
3715
Ta-wei Yen87c49842016-05-13 21:19:52 -07003716 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003717 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003719 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3720 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003721 if (!TextUtils.equals(callingPackage, systemDialer)) {
3722 throw new SecurityException("caller must be system dialer");
3723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724
3725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3728 if (phoneAccountHandle == null) {
3729 return null;
3730 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003731 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003732 } finally {
3733 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003734 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003735 }
3736
3737 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003738 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3739 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003740 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003742 mApp, subId, callingPackage, callingFeatureId,
3743 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003744 return null;
3745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003747 final long identity = Binder.clearCallingIdentity();
3748 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003749 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003750 } finally {
3751 Binder.restoreCallingIdentity(identity);
3752 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003753 }
3754
3755 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003756 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3757 VisualVoicemailSmsFilterSettings settings) {
3758 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003759
3760 final long identity = Binder.clearCallingIdentity();
3761 try {
3762 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003763 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003764 } finally {
3765 Binder.restoreCallingIdentity(identity);
3766 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003767 }
3768
3769 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003770 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3771 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772
3773 final long identity = Binder.clearCallingIdentity();
3774 try {
3775 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003776 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003777 } finally {
3778 Binder.restoreCallingIdentity(identity);
3779 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003780 }
3781
3782 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003783 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3784 String callingPackage, int subId) {
3785 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786
3787 final long identity = Binder.clearCallingIdentity();
3788 try {
3789 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003790 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791 } finally {
3792 Binder.restoreCallingIdentity(identity);
3793 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003794 }
3795
3796 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003797 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003798 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799
3800 final long identity = Binder.clearCallingIdentity();
3801 try {
3802 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003803 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804 } finally {
3805 Binder.restoreCallingIdentity(identity);
3806 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003807 }
3808
3809 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003810 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3811 String callingAttributionTag, int subId, String number, int port, String text,
3812 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003813 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003814 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003815 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003816 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003817 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3818 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003819 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003820
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003821 /**
fionaxu0152e512016-11-14 13:36:14 -08003822 * Sets the voice activation state of a given subId.
3823 */
3824 @Override
3825 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3827 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828
3829 final long identity = Binder.clearCallingIdentity();
3830 try {
3831 final Phone phone = getPhone(subId);
3832 if (phone != null) {
3833 phone.setVoiceActivationState(activationState);
3834 } else {
3835 loge("setVoiceActivationState fails with invalid subId: " + subId);
3836 }
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003839 }
3840 }
3841
3842 /**
3843 * Sets the data activation state of a given subId.
3844 */
3845 @Override
3846 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3848 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003849
3850 final long identity = Binder.clearCallingIdentity();
3851 try {
3852 final Phone phone = getPhone(subId);
3853 if (phone != null) {
3854 phone.setDataActivationState(activationState);
3855 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003856 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 }
3858 } finally {
3859 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003860 }
3861 }
3862
3863 /**
3864 * Returns the voice activation state of a given subId.
3865 */
3866 @Override
3867 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003868 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869
fionaxu0152e512016-11-14 13:36:14 -08003870 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 if (phone != null) {
3874 return phone.getVoiceActivationState();
3875 } else {
3876 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3877 }
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003880 }
3881 }
3882
3883 /**
3884 * Returns the data activation state of a given subId.
3885 */
3886 @Override
3887 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003888 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889
fionaxu0152e512016-11-14 13:36:14 -08003890 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891 final long identity = Binder.clearCallingIdentity();
3892 try {
3893 if (phone != null) {
3894 return phone.getDataActivationState();
3895 } else {
3896 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3897 }
3898 } finally {
3899 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003900 }
3901 }
3902
3903 /**
Wink Saville36469e72014-06-11 15:17:00 -07003904 * Returns the unread count of voicemails for a subId
3905 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003906 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003907 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3908 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003910 mApp, subId, callingPackage, callingFeatureId,
3911 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003912 return 0;
3913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 final Phone phone = getPhone(subId);
3917 if (phone != null) {
3918 return phone.getVoiceMessageCount();
3919 } else {
3920 return 0;
3921 }
3922 } finally {
3923 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003925 }
3926
3927 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003928 * returns true, if the device is in a state where both voice and data
3929 * are supported simultaneously. This can change based on location or network condition.
3930 */
3931 @Override
3932 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 final Phone phone = getPhone(subId);
3936 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3937 } finally {
3938 Binder.restoreCallingIdentity(identity);
3939 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003940 }
3941
3942 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003943 * Send the dialer code if called from the current default dialer or the caller has
3944 * carrier privilege.
3945 * @param inputCode The dialer code to send
3946 */
3947 @Override
3948 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003949 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003950 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003951 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3952 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003953 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003954 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003955 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003960 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003961 } finally {
3962 Binder.restoreCallingIdentity(identity);
3963 }
fionaxu235cc5e2017-03-06 22:25:57 -08003964 }
3965
Pengquan Menga1bb6272018-09-06 09:59:22 -07003966 @Override
3967 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003968 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003969 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003970 mApp, subId, "getNetworkSelectionMode");
3971 final long identity = Binder.clearCallingIdentity();
3972 try {
3973 if (!isActiveSubscription(subId)) {
3974 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3975 }
3976 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3977 } finally {
3978 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003979 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003980 }
3981
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003983 public boolean isInEmergencySmsMode() {
3984 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3985 final long identity = Binder.clearCallingIdentity();
3986 try {
3987 for (Phone phone : PhoneFactory.getPhones()) {
3988 if (phone.isInEmergencySmsMode()) {
3989 return true;
3990 }
3991 }
3992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
3995 return false;
3996 }
3997
shilu366312e2019-12-17 09:28:10 -08003998 /**
3999 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4000 * @param subId The subscription to use to check the configuration.
4001 * @param c The callback that will be used to send the result.
4002 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004003 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004004 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4005 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004006 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004007 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08004008
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004009 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4010 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4011 "IMS not available on device.");
4012 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004013 final long token = Binder.clearCallingIdentity();
4014 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004015 int slotId = getSlotIndexOrException(subId);
4016 verifyImsMmTelConfiguredOrThrow(slotId);
4017 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004018 } catch (ImsException e) {
4019 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 } finally {
4021 Binder.restoreCallingIdentity(token);
4022 }
4023 }
4024
shilu366312e2019-12-17 09:28:10 -08004025 /**
4026 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4027 * @param subId The subscription to use to check the configuration.
4028 * @param c The callback that will be used to send the result.
4029 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004030 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004031 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004032 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004033 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004034 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4035 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4036 }
Meng Wangafbc5852019-09-19 17:37:13 -07004037 final long token = Binder.clearCallingIdentity();
4038 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004039 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4040 .removeRegistrationCallbackForSubscription(c, subId);
4041 } catch (ImsException e) {
4042 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4043 + "is inactive, ignoring unregister.");
4044 // If the subscription is no longer active, just return, since the callback
4045 // will already have been removed internally.
4046 } finally {
4047 Binder.restoreCallingIdentity(token);
4048 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 }
4050
Brad Ebingera34a6c22019-10-22 17:36:18 -07004051 /**
4052 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4053 */
4054 @Override
4055 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4056 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4057 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4058 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4059 "IMS not available on device.");
4060 }
4061 final long token = Binder.clearCallingIdentity();
4062 try {
4063 Phone phone = getPhone(subId);
4064 if (phone == null) {
4065 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4066 + subId + "'");
4067 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4068 }
4069 phone.getImsRegistrationState(regState -> {
4070 try {
4071 consumer.accept((regState == null)
4072 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4073 } catch (RemoteException e) {
4074 // Ignore if the remote process is no longer available to call back.
4075 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4076 }
4077 });
4078 } finally {
4079 Binder.restoreCallingIdentity(token);
4080 }
4081 }
4082
4083 /**
4084 * Get the transport type for the IMS service registration state.
4085 */
4086 @Override
4087 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004088 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004089 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004090 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4091 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4092 "IMS not available on device.");
4093 }
4094 final long token = Binder.clearCallingIdentity();
4095 try {
4096 Phone phone = getPhone(subId);
4097 if (phone == null) {
4098 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4099 + subId + "'");
4100 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4101 }
4102 phone.getImsRegistrationTech(regTech -> {
4103 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4104 int regTechConverted = (regTech == null)
4105 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4106 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4107 regTechConverted);
4108 try {
4109 consumer.accept(regTechConverted);
4110 } catch (RemoteException e) {
4111 // Ignore if the remote process is no longer available to call back.
4112 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4113 }
4114 });
4115 } finally {
4116 Binder.restoreCallingIdentity(token);
4117 }
4118 }
4119
shilu366312e2019-12-17 09:28:10 -08004120 /**
4121 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4122 * @param subId The subscription to use to check the configuration.
4123 * @param c The callback that will be used to send the result.
4124 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004126 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4127 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004128 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004129 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004130 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4131 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4132 "IMS not available on device.");
4133 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 final long token = Binder.clearCallingIdentity();
4135 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004136 int slotId = getSlotIndexOrException(subId);
4137 verifyImsMmTelConfiguredOrThrow(slotId);
4138 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004139 } catch (ImsException e) {
4140 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 } finally {
4142 Binder.restoreCallingIdentity(token);
4143 }
4144 }
4145
shilu366312e2019-12-17 09:28:10 -08004146 /**
4147 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4148 * @param subId The subscription to use to check the configuration.
4149 * @param c The callback that will be used to send the result.
4150 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004152 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004153 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004154 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004155 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4156 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4157 }
Meng Wangafbc5852019-09-19 17:37:13 -07004158
4159 final long token = Binder.clearCallingIdentity();
4160 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004161 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004162 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004163 } catch (ImsException e) {
4164 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4165 + "is inactive, ignoring unregister.");
4166 // If the subscription is no longer active, just return, since the callback
4167 // will already have been removed internally.
4168 } finally {
4169 Binder.restoreCallingIdentity(token);
4170 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004171 }
4172
4173 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004174 public boolean isCapable(int subId, int capability, int regTech) {
4175 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004176 final long token = Binder.clearCallingIdentity();
4177 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004178 int slotId = getSlotIndexOrException(subId);
4179 verifyImsMmTelConfiguredOrThrow(slotId);
4180 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004181 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004182 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4183 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004184 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004185 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4186 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004187 } finally {
4188 Binder.restoreCallingIdentity(token);
4189 }
4190 }
4191
4192 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004193 public boolean isAvailable(int subId, int capability, int regTech) {
4194 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 final long token = Binder.clearCallingIdentity();
4196 try {
4197 Phone phone = getPhone(subId);
4198 if (phone == null) return false;
4199 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004200 } catch (com.android.ims.ImsException e) {
4201 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4202 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004203 } finally {
4204 Binder.restoreCallingIdentity(token);
4205 }
4206 }
4207
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004208 /**
4209 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4210 * subscription.
4211 * @param subId The subscription to use to check the configuration.
4212 * @param callback The callback that will be used to send the result.
4213 * @param capability The MmTelFeature capability that will be used to send the result.
4214 * @param transportType The transport type of the MmTelFeature capability.
4215 */
4216 @Override
4217 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4218 int transportType) {
4219 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4220 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4221 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4222 "IMS not available on device.");
4223 }
4224 final long token = Binder.clearCallingIdentity();
4225 try {
4226 int slotId = getSlotIndex(subId);
4227 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4228 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4229 + subId + "'");
4230 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4231 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004232 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004233 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4234 transportType, aBoolean -> {
4235 try {
4236 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4237 } catch (RemoteException e) {
4238 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4239 + "running. Ignore");
4240 }
4241 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004242 } catch (ImsException e) {
4243 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004244 } finally {
4245 Binder.restoreCallingIdentity(token);
4246 }
4247 }
4248
shilu366312e2019-12-17 09:28:10 -08004249 /**
4250 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4251 * @param subId The subscription to use to check the configuration.
4252 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004253 @Override
4254 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004255 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004256 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004257
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 final long token = Binder.clearCallingIdentity();
4259 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004260 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004261 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004262 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004263 } catch (ImsException e) {
4264 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004265 } finally {
4266 Binder.restoreCallingIdentity(token);
4267 }
4268 }
4269
4270 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004271 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004273 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004274 final long identity = Binder.clearCallingIdentity();
4275 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004276 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004277 // This setting doesn't require an active ImsService connection, so do not verify. The
4278 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004279 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004280 } catch (ImsException e) {
4281 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004282 } finally {
4283 Binder.restoreCallingIdentity(identity);
4284 }
4285 }
4286
shilu366312e2019-12-17 09:28:10 -08004287 /**
4288 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4289 * @param subId The subscription to use to check the configuration.
4290 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004292 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004293 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004294 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 final long identity = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004298 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004300 } catch (ImsException e) {
4301 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 } finally {
4303 Binder.restoreCallingIdentity(identity);
4304 }
4305 }
4306
4307 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004308 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004310 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 final long identity = Binder.clearCallingIdentity();
4312 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004313 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004314 // This setting doesn't require an active ImsService connection, so do not verify. The
4315 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004316 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004317 } catch (ImsException e) {
4318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
4322 }
4323
shilu366312e2019-12-17 09:28:10 -08004324 /**
4325 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4326 * @param subId The subscription to use to check the configuration.
4327 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 @Override
4329 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004330 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004331 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 final long identity = Binder.clearCallingIdentity();
4333 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004335 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004336 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004337 } catch (ImsException e) {
4338 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
4342 }
4343
4344 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004345 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004347 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004348 final long identity = Binder.clearCallingIdentity();
4349 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004350 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004351 // This setting doesn't require an active ImsService connection, so do not verify. The
4352 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004353 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004354 } catch (ImsException e) {
4355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
4359 }
4360
shilu366312e2019-12-17 09:28:10 -08004361 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004362 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4363 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4364 * @param subId The subscription to use to check the configuration.
4365 */
4366 @Override
4367 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004368 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004369 mApp, subId, "isCrossSimCallingEnabledByUser");
4370 final long identity = Binder.clearCallingIdentity();
4371 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004372 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004373 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004374 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004375 } catch (ImsException e) {
4376 throw new ServiceSpecificException(e.getCode());
4377 } finally {
4378 Binder.restoreCallingIdentity(identity);
4379 }
4380 }
4381
4382 /**
4383 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4384 * Requires MODIFY_PHONE_STATE permission.
4385 * @param subId The subscription to use to check the configuration.
4386 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4387 * false otherwise
4388 */
4389 @Override
4390 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4392 "setCrossSimCallingEnabled");
4393 final long identity = Binder.clearCallingIdentity();
4394 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004396 // This setting doesn't require an active ImsService connection, so do not verify. The
4397 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004398 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004399 } catch (ImsException e) {
4400 throw new ServiceSpecificException(e.getCode());
4401 } finally {
4402 Binder.restoreCallingIdentity(identity);
4403 }
4404 }
4405
4406 /**
shilu366312e2019-12-17 09:28:10 -08004407 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4408 * @param subId The subscription to use to check the configuration.
4409 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004410 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004411
Brad Ebinger35c841c2018-10-01 10:40:55 -07004412 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004413 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004414 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004415 final long identity = Binder.clearCallingIdentity();
4416 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004417 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004418 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004419 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004420 } catch (ImsException e) {
4421 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004422 } finally {
4423 Binder.restoreCallingIdentity(identity);
4424 }
4425 }
4426
4427 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004428 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004430 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004431 final long identity = Binder.clearCallingIdentity();
4432 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004433 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004434 // This setting doesn't require an active ImsService connection, so do not verify. The
4435 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004436 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004437 } catch (ImsException e) {
4438 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004439 } finally {
4440 Binder.restoreCallingIdentity(identity);
4441 }
4442 }
4443
4444 @Override
4445 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4447 "setVoWiFiNonPersistent");
4448 final long identity = Binder.clearCallingIdentity();
4449 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004450 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004451 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004452 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004453 } catch (ImsException e) {
4454 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 } finally {
4456 Binder.restoreCallingIdentity(identity);
4457 }
4458 }
4459
shilu366312e2019-12-17 09:28:10 -08004460 /**
4461 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4462 * @param subId The subscription to use to check the configuration.
4463 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 @Override
4465 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004466 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004467 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004468 final long identity = Binder.clearCallingIdentity();
4469 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004470 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004471 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004472 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004473 } catch (ImsException e) {
4474 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004475 } finally {
4476 Binder.restoreCallingIdentity(identity);
4477 }
4478 }
4479
4480 @Override
4481 public void setVoWiFiModeSetting(int subId, int mode) {
4482 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4483 "setVoWiFiModeSetting");
4484 final long identity = Binder.clearCallingIdentity();
4485 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004486 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004487 // This setting doesn't require an active ImsService connection, so do not verify. The
4488 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004489 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004490 } catch (ImsException e) {
4491 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 } finally {
4493 Binder.restoreCallingIdentity(identity);
4494 }
4495 }
4496
4497 @Override
4498 public int getVoWiFiRoamingModeSetting(int subId) {
4499 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4500 final long identity = Binder.clearCallingIdentity();
4501 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004502 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004503 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004504 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004505 } catch (ImsException e) {
4506 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004507 } finally {
4508 Binder.restoreCallingIdentity(identity);
4509 }
4510 }
4511
4512 @Override
4513 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4515 "setVoWiFiRoamingModeSetting");
4516 final long identity = Binder.clearCallingIdentity();
4517 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004518 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004519 // This setting doesn't require an active ImsService connection, so do not verify. The
4520 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004521 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004522 } catch (ImsException e) {
4523 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
4527 }
4528
4529 @Override
4530 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4532 "setRttCapabilityEnabled");
4533 final long identity = Binder.clearCallingIdentity();
4534 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004535 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004536 // This setting doesn't require an active ImsService connection, so do not verify. The
4537 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004538 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004539 } catch (ImsException e) {
4540 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004541 } finally {
4542 Binder.restoreCallingIdentity(identity);
4543 }
4544 }
4545
shilu366312e2019-12-17 09:28:10 -08004546 /**
4547 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4548 * @param subId The subscription to use to check the configuration.
4549 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004550 @Override
4551 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004552 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004553 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004554 final long identity = Binder.clearCallingIdentity();
4555 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004556 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004557 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004558 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004559 } catch (ImsException e) {
4560 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
4564 }
4565
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004566 @Override
4567 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4568 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4569 final long identity = Binder.clearCallingIdentity();
4570 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004571 if (!isImsAvailableOnDevice()) {
4572 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4573 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004574 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004575 int slotId = getSlotIndexOrException(subId);
4576 verifyImsMmTelConfiguredOrThrow(slotId);
4577 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004578 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004579 } catch (ImsException e) {
4580 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004581 } finally {
4582 Binder.restoreCallingIdentity(identity);
4583 }
4584 }
4585
4586 @Override
4587 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4588 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4589 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004590 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4591 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4592 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004593 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004594 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004595 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004596 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004597 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4598 + "is inactive, ignoring unregister.");
4599 // If the subscription is no longer active, just return, since the callback will already
4600 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004601 } finally {
4602 Binder.restoreCallingIdentity(identity);
4603 }
4604 }
4605
allenwtsu99c623b2020-01-03 18:24:23 +08004606
4607 private void checkModifyPhoneStatePermission(int subId, String message) {
4608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4609 message);
4610 }
4611
4612 private boolean isImsProvisioningRequired(int subId, int capability,
4613 boolean isMmtelCapability) {
4614 Phone phone = getPhone(subId);
4615 if (phone == null) {
4616 loge("phone instance null for subid " + subId);
4617 return false;
4618 }
4619 if (isMmtelCapability) {
4620 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4621 return false;
4622 }
4623 } else {
4624 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4625 return false;
4626 }
4627 }
4628 return true;
4629 }
4630
4631 @Override
4632 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4633 boolean isProvisioned) {
4634 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4635
4636 final long identity = Binder.clearCallingIdentity();
4637 try {
4638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4639 if (!isImsProvisioningRequired(subId, capability, false)) {
4640 return;
4641 }
4642
4643 // this capability requires provisioning, route to the correct API.
4644 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4645 switch (capability) {
4646 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4647 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4648 ims.setEabProvisioned(isProvisioned);
4649 break;
4650 default: {
4651 throw new IllegalArgumentException("Tried to set provisioning for "
4652 + "rcs capability '" + capability + "', which does not require "
4653 + "provisioning.");
4654 }
4655 }
4656 } finally {
4657 Binder.restoreCallingIdentity(identity);
4658 }
4659
4660 }
4661
4662
4663 @Override
4664 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4665 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4666 final long identity = Binder.clearCallingIdentity();
4667 try {
4668 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4669 if (!isImsProvisioningRequired(subId, capability, false)) {
4670 return true;
4671 }
4672
4673 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4674 switch (capability) {
4675 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4676 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4677 return ims.isEabProvisionedOnDevice();
4678
4679 default: {
4680 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4681 + "capability '" + capability + "', which does not require "
4682 + "provisioning.");
4683 }
4684 }
4685
4686 } finally {
4687 Binder.restoreCallingIdentity(identity);
4688 }
4689 }
4690
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004691 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004692 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4693 boolean isProvisioned) {
4694 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004695 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4696 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4697 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004698 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4699 }
allenwtsu99c623b2020-01-03 18:24:23 +08004700 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004701 final long identity = Binder.clearCallingIdentity();
4702 try {
4703 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004704 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004705 return;
4706 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004707 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4708 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4709 loge("setImsProvisioningStatusForCapability: called for technology that does "
4710 + "not support provisioning - " + tech);
4711 return;
4712 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004713
4714 // this capability requires provisioning, route to the correct API.
4715 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4716 switch (capability) {
4717 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4718 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4719 ims.setVolteProvisioned(isProvisioned);
4720 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4721 ims.setWfcProvisioned(isProvisioned);
4722 }
4723 break;
4724 }
4725 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4726 // There is currently no difference in VT provisioning type.
4727 ims.setVtProvisioned(isProvisioned);
4728 break;
4729 }
4730 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4731 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4732 // change the capability of the feature instead if needed.
4733 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4734 == isProvisioned) {
4735 // No change in provisioning.
4736 return;
4737 }
4738 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4739 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004740 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004741 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004742 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4743 + ", Exception" + e.getMessage());
4744 }
4745 break;
4746 }
4747 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004748 throw new IllegalArgumentException("Tried to set provisioning for "
4749 + "MmTel capability '" + capability + "', which does not require "
4750 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004751 }
4752 }
4753
4754 } finally {
4755 Binder.restoreCallingIdentity(identity);
4756 }
4757 }
4758
4759 @Override
4760 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4761 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004762 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4763 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4764 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004765 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4766 }
4767 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4768 final long identity = Binder.clearCallingIdentity();
4769 try {
4770 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004771 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004772 return true;
4773 }
4774
Brad Ebinger0d79c572021-04-17 15:20:49 -07004775 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4776 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4777 loge("getImsProvisioningStatusForCapability: called for technology that does "
4778 + "not support provisioning - " + tech);
4779 return true;
4780 }
4781
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004782 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4783 switch (capability) {
4784 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4785 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4786 return ims.isVolteProvisionedOnDevice();
4787 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4788 return ims.isWfcProvisionedOnDevice();
4789 }
4790 // This should never happen, since we are checking tech above to make sure it
4791 // is either LTE or IWLAN.
4792 throw new IllegalArgumentException("Invalid radio technology for voice "
4793 + "capability.");
4794 }
4795 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4796 // There is currently no difference in VT provisioning type.
4797 return ims.isVtProvisionedOnDevice();
4798 }
4799 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4800 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4801 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4802 }
4803 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004804 throw new IllegalArgumentException(
4805 "Tried to get provisioning for MmTel capability '" + capability
4806 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004807 }
4808 }
4809
4810 } finally {
4811 Binder.restoreCallingIdentity(identity);
4812 }
4813 }
4814
4815 @Override
4816 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4817 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4818 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4819 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4820 }
4821 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4822 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4823 return (provisionedBits & capability) > 0;
4824 }
4825
4826 @Override
4827 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4828 boolean isProvisioned) {
4829 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4830 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4831 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4832 }
4833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4834 "setProvisioningStatusForCapability");
4835 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4836 // If the current provisioning status for capability already matches isProvisioned,
4837 // do nothing.
4838 if (((provisionedBits & capability) > 0) == isProvisioned) {
4839 return;
4840 }
4841 if (isProvisioned) {
4842 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4843 } else {
4844 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4845 }
4846 }
4847
4848 /**
4849 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4850 * technology. The bitfield should mirror the bitfield defined by
4851 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4852 */
4853 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4854 String key = getMmTelProvisioningKey(subId, tech);
4855 // Default is no capabilities are provisioned.
4856 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4857 }
4858
4859 /**
4860 * Sets the MmTel capability provisioning bitfield (defined by
4861 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4862 * technology specified.
4863 *
4864 * Note: This is a synchronous command and should not be called on UI thread.
4865 */
4866 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4867 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4868 String key = getMmTelProvisioningKey(subId, tech);
4869 editor.putInt(key, newField);
4870 editor.commit();
4871 }
4872
4873 private static String getMmTelProvisioningKey(int subId, int tech) {
4874 // resulting key is provision_ims_mmtel_{subId}_{tech}
4875 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4876 }
4877
4878 /**
4879 * Query CarrierConfig to see if the specified capability requires provisioning for the
4880 * carrier associated with the subscription id.
4881 */
4882 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4883 int capability) {
4884 CarrierConfigManager configManager = new CarrierConfigManager(context);
4885 PersistableBundle c = configManager.getConfigForSubId(subId);
4886 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004887 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004888 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4889 false);
4890 boolean requireVoiceVtProvisioning = c.getBoolean(
4891 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4892
4893 // First check to make sure that the capability requires provisioning.
4894 switch (capability) {
4895 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4896 // intentional fallthrough
4897 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4898 if (requireVoiceVtProvisioning) {
4899 // Voice and Video requires provisioning
4900 return true;
4901 }
4902 break;
4903 }
4904 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4905 if (requireUtProvisioning) {
4906 // UT requires provisioning
4907 return true;
4908 }
4909 break;
4910 }
4911 }
4912 return false;
4913 }
4914
allenwtsu99c623b2020-01-03 18:24:23 +08004915 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4916 int capability) {
4917 CarrierConfigManager configManager = new CarrierConfigManager(context);
4918 PersistableBundle c = configManager.getConfigForSubId(subId);
4919
4920 boolean requireRcsProvisioning = c.getBoolean(
4921 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4922
4923 // First check to make sure that the capability requires provisioning.
4924 switch (capability) {
4925 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4926 // intentional fallthrough
4927 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4928 if (requireRcsProvisioning) {
4929 // OPTION or PRESENCE requires provisioning
4930 return true;
4931 }
4932 break;
4933 }
4934 }
4935 return false;
4936 }
4937
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004938 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004939 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004940 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4941 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4942 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004943 enforceReadPrivilegedPermission("getImsProvisioningInt");
4944 final long identity = Binder.clearCallingIdentity();
4945 try {
4946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004947 int slotId = getSlotIndex(subId);
4948 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4949 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4950 + subId + "' for key:" + key);
4951 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4952 }
calvinpanb5a34062021-02-08 19:59:36 +08004953 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004954 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004955 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4956 + subId + "' for key:" + key);
4957 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004958 } finally {
4959 Binder.restoreCallingIdentity(identity);
4960 }
4961 }
4962
4963 @Override
4964 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004965 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4966 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4967 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004968 enforceReadPrivilegedPermission("getImsProvisioningString");
4969 final long identity = Binder.clearCallingIdentity();
4970 try {
4971 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 int slotId = getSlotIndex(subId);
4973 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4974 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4975 + subId + "' for key:" + key);
4976 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4977 }
calvinpanb5a34062021-02-08 19:59:36 +08004978 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004979 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004980 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4981 + subId + "' for key:" + key);
4982 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
4986 }
4987
4988 @Override
4989 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004990 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4991 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4992 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4994 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004995 final long identity = Binder.clearCallingIdentity();
4996 try {
4997 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004998 int slotId = getSlotIndex(subId);
4999 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5000 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5001 + subId + "' for key:" + key);
5002 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5003 }
calvinpanb5a34062021-02-08 19:59:36 +08005004 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5005 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005006 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005007 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005008 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
5011 }
5012 }
5013
5014 @Override
5015 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005016 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5017 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5018 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5020 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005021 final long identity = Binder.clearCallingIdentity();
5022 try {
5023 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005024 int slotId = getSlotIndex(subId);
5025 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5026 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5027 + subId + "' for key:" + key);
5028 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5029 }
calvinpanb5a34062021-02-08 19:59:36 +08005030 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5031 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005032 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005033 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005034 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005035 } finally {
5036 Binder.restoreCallingIdentity(identity);
5037 }
5038 }
5039
Brad Ebinger919631e2021-06-02 17:46:35 -07005040 /**
5041 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5042 * for the given slot ID or no ImsResolver instance has been created.
5043 * @param slotId The slot ID that the IMS service is created for.
5044 * @throws ImsException If there is no ImsService configured for this slot.
5045 */
5046 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5047 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5048 ImsFeature.FEATURE_MMTEL)) {
5049 throw new ImsException("This subscription does not support MMTEL over IMS",
5050 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5051 }
5052 }
5053
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005054 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005055 int slotId = SubscriptionManager.getSlotIndex(subId);
5056 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005057 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5058 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005059 }
5060 return slotId;
5061 }
5062
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005063 private int getSlotIndex(int subId) {
5064 int slotId = SubscriptionManager.getSlotIndex(subId);
5065 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5066 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5067 }
5068 return slotId;
5069 }
5070
Wink Saville36469e72014-06-11 15:17:00 -07005071 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005072 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005073 */
5074 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005075 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5076 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005077 try {
5078 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5079 } catch (SecurityException se) {
5080 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5081 throw new SecurityException("Package " + callingPackage + " does not belong to "
5082 + Binder.getCallingUid());
5083 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005084 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005085 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005086 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005087 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005088 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005089 mApp, subId, callingPackage, callingFeatureId,
5090 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005091 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5092 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 final long identity = Binder.clearCallingIdentity();
5095 try {
5096 final Phone phone = getPhone(subId);
5097 if (phone != null) {
5098 return phone.getServiceState().getDataNetworkType();
5099 } else {
5100 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5101 }
5102 } finally {
5103 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005105 }
5106
5107 /**
5108 * Returns the data network type
5109 */
5110 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005111 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005112 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5113 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005114 }
5115
5116 /**
5117 * Returns the data network type for a subId
5118 */
5119 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005120 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5121 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005122 String functionName = "getDataNetworkTypeForSubscriber";
5123 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5124 mApp, functionName)) {
5125 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5126 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5127 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5128 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005129 }
5130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005131 final long identity = Binder.clearCallingIdentity();
5132 try {
5133 final Phone phone = getPhone(subId);
5134 if (phone != null) {
5135 return phone.getServiceState().getDataNetworkType();
5136 } else {
5137 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5138 }
5139 } finally {
5140 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005142 }
5143
5144 /**
Wink Saville36469e72014-06-11 15:17:00 -07005145 * Returns the Voice network type for a subId
5146 */
5147 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005148 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5149 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005150 String functionName = "getVoiceNetworkTypeForSubscriber";
5151 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5152 mApp, functionName)) {
5153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5154 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5155 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5156 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005157 }
5158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 final Phone phone = getPhone(subId);
5162 if (phone != null) {
5163 return phone.getServiceState().getVoiceNetworkType();
5164 } else {
5165 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5166 }
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005170 }
5171
5172 /**
5173 * @return true if a ICC card is present
5174 */
5175 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005176 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005177 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5178 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005179 }
5180
5181 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005182 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005183 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005184 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005185 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186 final long identity = Binder.clearCallingIdentity();
5187 try {
5188 final Phone phone = PhoneFactory.getPhone(slotIndex);
5189 if (phone != null) {
5190 return phone.getIccCard().hasIccCard();
5191 } else {
5192 return false;
5193 }
5194 } finally {
5195 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005197 }
5198
5199 /**
5200 * Return if the current radio is LTE on CDMA. This
5201 * is a tri-state return value as for a period of time
5202 * the mode may be unknown.
5203 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005204 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005205 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005206 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005207 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005208 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005209 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5210 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5211 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005212 }
5213
Sanket Padawe356d7632015-06-22 14:03:32 -07005214 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005215 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5216 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005217 try {
5218 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5219 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005220 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5221 }
5222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 final Phone phone = getPhone(subId);
5226 if (phone == null) {
5227 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5228 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005229 return TelephonyProperties.lte_on_cdma_device()
5230 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 }
5232 } finally {
5233 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005234 }
Wink Saville36469e72014-06-11 15:17:00 -07005235 }
5236
Wink Saville36469e72014-06-11 15:17:00 -07005237 /**
5238 * {@hide}
5239 * Returns Default subId, 0 in the case of single standby.
5240 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005241 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005242 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005243 }
5244
Shishir Agrawala9f32182016-04-12 12:00:16 -07005245 private int getSlotForDefaultSubscription() {
5246 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5247 }
5248
Wink Savilleb564aae2014-10-23 10:18:09 -07005249 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005250 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005251 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005252
Pengquan Menge92a50d2018-09-21 15:54:48 -07005253 private boolean isActiveSubscription(int subId) {
5254 return mSubscriptionController.isActiveSubId(subId);
5255 }
5256
Ihab Awadf2177b72013-11-25 13:33:23 -08005257 /**
5258 * @see android.telephony.TelephonyManager.WifiCallingChoices
5259 */
5260 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 final long identity = Binder.clearCallingIdentity();
5262 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005263 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5265 getWhenToMakeWifiCallsDefaultPreference());
5266 } finally {
5267 Binder.restoreCallingIdentity(identity);
5268 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005269 }
5270
5271 /**
5272 * @see android.telephony.TelephonyManager.WifiCallingChoices
5273 */
5274 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 final long identity = Binder.clearCallingIdentity();
5276 try {
5277 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005278 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005283 }
5284
Sailesh Nepald1e68152013-12-12 19:08:02 -08005285 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005286 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005287 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005288 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005289
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005290 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5291 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5292 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005293 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005294 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5295 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005296 }
5297 return PhoneFactory.getPhone(phoneId);
5298 }
5299
Shishir Agrawal566b7612013-10-28 14:41:00 -07005300 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005301 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005302 @NonNull IccLogicalChannelRequest request) {
5303 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5304 /*message=*/ "iccOpenLogicalChannel");
5305
5306 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5307 // Verify that the callingPackage in the request belongs to the calling UID
5308 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5309
5310 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005311 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005312
Rambo Wanga1782702021-11-10 20:15:19 -08005313 private Phone getPhoneFromValidIccLogicalChannelRequest(
5314 @NonNull IccLogicalChannelRequest request, String message) {
5315 Phone phone;
5316 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5318 mApp, request.subId, message);
5319 phone = getPhoneFromSubId(request.subId);
5320 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5321 enforceModifyPermission();
5322 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5323 } else {
5324 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005325 }
Rambo Wanga1782702021-11-10 20:15:19 -08005326 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005327 }
5328
5329 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005330 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 final long identity = Binder.clearCallingIdentity();
5332 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005333 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005335 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5336 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005337 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5338 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 loge("The calling package is not allowed to access ISD-R.");
5340 throw new SecurityException(
5341 "The calling package is not allowed to access ISD-R.");
5342 }
Derek Tan740e1672017-06-27 14:56:27 -07005343 }
Derek Tan740e1672017-06-27 14:56:27 -07005344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005346 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5347 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 return response;
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
5351 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005352 }
5353
5354 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005355 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5356 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5357 /*message=*/"iccCloseLogicalChannel");
5358
5359 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5360
5361 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005362 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005363
Rambo Wanga1782702021-11-10 20:15:19 -08005364 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5365 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 final long identity = Binder.clearCallingIdentity();
5367 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005368 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005369 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370 }
Rambo Wanga1782702021-11-10 20:15:19 -08005371 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005372 null /* workSource */);
Rambo Wanga1782702021-11-10 20:15:19 -08005373 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 return success;
5375 } finally {
5376 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005377 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005378 }
5379
5380 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005381 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005382 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5384 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005385 if (DBG) {
5386 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5387 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5388 + p3 + " data=" + data);
5389 }
5390 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5391 command, p1, p2, p3, data);
5392 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005393
Jordan Liu4c733742019-02-28 12:03:40 -08005394 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005395 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5396 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005397 enforceModifyPermission();
5398 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005399 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5400 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5401 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005402 }
5403 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005404 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5405 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005406 }
5407
5408 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5409 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 final long identity = Binder.clearCallingIdentity();
5411 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005412 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413 return "";
5414 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005417 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5418 null /* workSource */);
5419 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 // Append the returned status code to the end of the response payload.
5422 String s = Integer.toHexString(
5423 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5424 if (response.payload != null) {
5425 s = IccUtils.bytesToHexString(response.payload) + s;
5426 }
5427 return s;
5428 } finally {
5429 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005430 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005431 }
Jake Hambye994d462014-02-03 13:10:13 -08005432
Evan Charltonc66da362014-05-16 14:06:40 -07005433 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005434 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5435 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5437 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005439 if (DBG) {
5440 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5441 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5442 }
5443 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5444 cla, command, p1, p2, p3, data);
5445 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005446
Jordan Liu4c733742019-02-28 12:03:40 -08005447 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005448 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5449 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005450 enforceModifyPermission();
5451 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5452 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005453 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5454 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5455 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005456 }
5457
5458 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005459 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5460 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005461 }
5462
5463 // open APDU basic channel assuming the caller has sufficient permissions
5464 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5465 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5469 && TextUtils.equals(ISDR_AID, data)) {
5470 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005471 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5472 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 if (bestComponent == null
5474 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5475 loge("The calling package is not allowed to select ISD-R.");
5476 throw new SecurityException(
5477 "The calling package is not allowed to select ISD-R.");
5478 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005479 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005482 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5483 null /* workSource */);
5484 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 // Append the returned status code to the end of the response payload.
5487 String s = Integer.toHexString(
5488 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5489 if (response.payload != null) {
5490 s = IccUtils.bytesToHexString(response.payload) + s;
5491 }
5492 return s;
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005495 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005496 }
5497
5498 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005499 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005500 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5502 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005503
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 final long identity = Binder.clearCallingIdentity();
5505 try {
5506 if (DBG) {
5507 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5508 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5509 }
5510
5511 IccIoResult response =
5512 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5513 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5514 subId);
5515
5516 if (DBG) {
5517 log("Exchange SIM_IO [R]" + response);
5518 }
5519
5520 byte[] result = null;
5521 int length = 2;
5522 if (response.payload != null) {
5523 length = 2 + response.payload.length;
5524 result = new byte[length];
5525 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5526 } else {
5527 result = new byte[length];
5528 }
5529
5530 result[length - 1] = (byte) response.sw2;
5531 result[length - 2] = (byte) response.sw1;
5532 return result;
5533 } finally {
5534 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005535 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005536 }
5537
Nathan Haroldb3014052017-01-25 15:57:32 -08005538 /**
5539 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5540 * on a particular subscription
5541 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005542 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5543 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005545 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005546 return null;
5547 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548
5549 final long identity = Binder.clearCallingIdentity();
5550 try {
5551 if (appType != TelephonyManager.APPTYPE_USIM
5552 && appType != TelephonyManager.APPTYPE_SIM) {
5553 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5554 return null;
5555 }
5556 Object response = sendRequest(
5557 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5558 if (response instanceof String[]) {
5559 return (String[]) response;
5560 }
yincheng zhao2737e882019-09-06 17:06:54 -07005561 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005563 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 } finally {
5565 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005566 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005567 }
5568
yincheng zhao2737e882019-09-06 17:06:54 -07005569 /**
5570 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5571 * subscription.
5572 *
5573 * @param subId the id of the subscription.
5574 * @param appType the uicc app type, must be USIM or SIM.
5575 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5576 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005577 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005578 * @return number of fplmns that is successfully written to the SIM.
5579 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005580 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5581 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5583 mApp, subId, "setForbiddenPlmns");
5584
yincheng zhao2737e882019-09-06 17:06:54 -07005585 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5586 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5587 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5588 }
5589 if (fplmns == null) {
5590 throw new IllegalArgumentException("Fplmn List provided is null");
5591 }
5592 for (String fplmn : fplmns) {
5593 if (!CellIdentity.isValidPlmn(fplmn)) {
5594 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5595 }
5596 }
5597 final long identity = Binder.clearCallingIdentity();
5598 try {
5599 Object response = sendRequest(
5600 CMD_SET_FORBIDDEN_PLMNS,
5601 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5602 subId);
5603 return (int) response;
5604 } finally {
5605 Binder.restoreCallingIdentity(identity);
5606 }
5607 }
5608
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005609 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005610 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5612 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 final long identity = Binder.clearCallingIdentity();
5615 try {
5616 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5617 if (response.payload == null) {
5618 return "";
5619 }
Evan Charltonc66da362014-05-16 14:06:40 -07005620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 // Append the returned status code to the end of the response payload.
5622 String s = Integer.toHexString(
5623 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5624 s = IccUtils.bytesToHexString(response.payload) + s;
5625 return s;
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
5628 }
Evan Charltonc66da362014-05-16 14:06:40 -07005629 }
5630
Jake Hambye994d462014-02-03 13:10:13 -08005631 /**
5632 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5633 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5634 *
5635 * @param itemID the ID of the item to read
5636 * @return the NV item as a String, or null on error.
5637 */
5638 @Override
5639 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005640 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5642 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643
5644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005647 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5649 return value;
5650 } finally {
5651 Binder.restoreCallingIdentity(identity);
5652 }
Jake Hambye994d462014-02-03 13:10:13 -08005653 }
5654
5655 /**
5656 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5657 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5658 *
5659 * @param itemID the ID of the item to read
5660 * @param itemValue the value to write, as a String
5661 * @return true on success; false on any failure
5662 */
5663 @Override
5664 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005665 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5667 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668
5669 final long identity = Binder.clearCallingIdentity();
5670 try {
5671 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5672 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005673 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5675 return success;
5676 } finally {
5677 Binder.restoreCallingIdentity(identity);
5678 }
Jake Hambye994d462014-02-03 13:10:13 -08005679 }
5680
5681 /**
5682 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5683 * Used for device configuration by some CDMA operators.
5684 *
5685 * @param preferredRoamingList byte array containing the new PRL
5686 * @return true on success; false on any failure
5687 */
5688 @Override
5689 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5691 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692
5693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5696 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5697 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5698 return success;
5699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
Jake Hambye994d462014-02-03 13:10:13 -08005702 }
5703
5704 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005705 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005706 * Used for device configuration by some CDMA operators.
5707 *
chen xu6dac5ab2018-10-26 17:39:23 -07005708 * @param slotIndex - device slot.
5709 *
Jake Hambye994d462014-02-03 13:10:13 -08005710 * @return true on success; false on any failure
5711 */
5712 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005713 public boolean resetModemConfig(int slotIndex) {
5714 Phone phone = PhoneFactory.getPhone(slotIndex);
5715 if (phone != null) {
5716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5717 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718
chen xu6dac5ab2018-10-26 17:39:23 -07005719 final long identity = Binder.clearCallingIdentity();
5720 try {
5721 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5722 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5723 return success;
5724 } finally {
5725 Binder.restoreCallingIdentity(identity);
5726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 }
chen xu6dac5ab2018-10-26 17:39:23 -07005728 return false;
5729 }
5730
5731 /**
5732 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5733 *
5734 * @param slotIndex - device slot.
5735 *
5736 * @return true on success; false on any failure
5737 */
5738 @Override
5739 public boolean rebootModem(int slotIndex) {
5740 Phone phone = PhoneFactory.getPhone(slotIndex);
5741 if (phone != null) {
5742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5743 mApp, phone.getSubId(), "rebootModem");
5744
5745 final long identity = Binder.clearCallingIdentity();
5746 try {
5747 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5748 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5749 return success;
5750 } finally {
5751 Binder.restoreCallingIdentity(identity);
5752 }
5753 }
5754 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005755 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005756
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005757 public String[] getPcscfAddress(String apnType, String callingPackage,
5758 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005759 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5761 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005762 return new String[0];
5763 }
5764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 final long identity = Binder.clearCallingIdentity();
5766 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005767 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768 } finally {
5769 Binder.restoreCallingIdentity(identity);
5770 }
Wink Saville36469e72014-06-11 15:17:00 -07005771 }
5772
Brad Ebinger51f743a2017-01-23 13:50:20 -08005773 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005774 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5775 * {@link #disableIms(int)}.
5776 * @param slotIndex device slot.
5777 */
5778 public void resetIms(int slotIndex) {
5779 enforceModifyPermission();
5780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
5783 if (mImsResolver == null) {
5784 // may happen if the does not support IMS.
5785 return;
5786 }
5787 mImsResolver.disableIms(slotIndex);
5788 mImsResolver.enableIms(slotIndex);
5789 } finally {
5790 Binder.restoreCallingIdentity(identity);
5791 }
5792 }
5793
5794 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005795 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5796 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005797 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005798 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800
5801 final long identity = Binder.clearCallingIdentity();
5802 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005803 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005804 // may happen if the device does not support IMS.
5805 return;
5806 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005807 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 } finally {
5809 Binder.restoreCallingIdentity(identity);
5810 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005811 }
5812
5813 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005814 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5815 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005816 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005817 public void disableIms(int slotId) {
5818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819
5820 final long identity = Binder.clearCallingIdentity();
5821 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005822 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005823 // may happen if the device does not support IMS.
5824 return;
5825 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005826 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 } finally {
5828 Binder.restoreCallingIdentity(identity);
5829 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005830 }
5831
5832 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005833 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5834 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005835 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005836 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005837 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839
5840 final long identity = Binder.clearCallingIdentity();
5841 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005842 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005843 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5844 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005845 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005846 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847 } finally {
5848 Binder.restoreCallingIdentity(identity);
5849 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005850 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005851 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005852 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5853 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005854 @Override
5855 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005856 enforceModifyPermission();
5857
5858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005861 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
5865 }
5866
5867 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005868 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005869 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005870 */
5871 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5872 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873
5874 final long identity = Binder.clearCallingIdentity();
5875 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005876 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005877 // may happen if the device does not support IMS.
5878 return null;
5879 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005880 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005884 }
5885
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005886 /**
5887 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005888 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005889 */
5890 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5891 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892
5893 final long identity = Binder.clearCallingIdentity();
5894 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005895 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005896 // may happen if the device does not support IMS.
5897 return null;
5898 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005899 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005903 }
5904
Brad Ebinger884c07b2018-02-15 16:17:40 -08005905 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005906 * Sets the ImsService Package Name that Telephony will bind to.
5907 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005908 * @param slotIndex the slot ID that the ImsService should bind for.
5909 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005910 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005911 * @param featureTypes An integer array of feature types associated with a packageName.
5912 * @param packageName The name of the package that the current configuration will be replaced
5913 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005914 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005915 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005916 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5917 int[] featureTypes, String packageName) {
5918 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5921 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005922 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924 final long identity = Binder.clearCallingIdentity();
5925 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005926 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005927 // may happen if the device does not support IMS.
5928 return false;
5929 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 Map<Integer, String> featureConfig = new HashMap<>();
5931 for (int featureType : featureTypes) {
5932 featureConfig.put(featureType, packageName);
5933 }
5934 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5935 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 } finally {
5937 Binder.restoreCallingIdentity(identity);
5938 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005939 }
5940
5941 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005942 * Clears any carrier ImsService overrides for the slot index specified that were previously
5943 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5944 *
5945 * This should only be used for testing.
5946 *
5947 * @param slotIndex the slot ID that the ImsService should bind for.
5948 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5949 */
5950 @Override
5951 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5952 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5953 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5954 "clearCarrierImsServiceOverride");
5955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5956 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5957 "clearCarrierImsServiceOverride");
5958
5959 final long identity = Binder.clearCallingIdentity();
5960 try {
5961 if (mImsResolver == null) {
5962 // may happen if the device does not support IMS.
5963 return false;
5964 }
5965 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5966 } finally {
5967 Binder.restoreCallingIdentity(identity);
5968 }
5969 }
5970
5971 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005972 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005973 *
5974 * @param slotId The slot that the ImsService is associated with.
5975 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5976 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005977 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005978 * @return the package name of the ImsService configuration.
5979 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005980 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5981 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005982 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005983 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005984 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005985 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5986 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 final long identity = Binder.clearCallingIdentity();
5989 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005990 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005991 // may happen if the device does not support IMS.
5992 return "";
5993 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005994 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005995 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5996 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 } finally {
5998 Binder.restoreCallingIdentity(identity);
5999 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006000 }
6001
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006002 /**
6003 * Get the MmTelFeature state associated with the requested subscription id.
6004 * @param subId The subscription that the MmTelFeature is associated with.
6005 * @param callback A callback with an integer containing the
6006 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6007 */
6008 @Override
6009 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6010 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
6011 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6012 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6013 "IMS not available on device.");
6014 }
6015 final long token = Binder.clearCallingIdentity();
6016 try {
6017 int slotId = getSlotIndex(subId);
6018 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6019 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6020 + subId + "'");
6021 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6022 }
Brad Ebinger919631e2021-06-02 17:46:35 -07006023 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006024 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6025 try {
6026 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6027 } catch (RemoteException e) {
6028 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6029 + "Ignore");
6030 }
6031 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006032 } catch (ImsException e) {
6033 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006034 } finally {
6035 Binder.restoreCallingIdentity(token);
6036 }
6037 }
6038
Daniel Brightbb5840b2021-01-12 15:48:18 -08006039 /**
6040 * Sets the ims registration state on all valid {@link Phone}s.
6041 */
6042 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006043 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044
6045 final long identity = Binder.clearCallingIdentity();
6046 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006047 // NOTE: Before S, this method only set the default phone.
6048 for (final Phone phone : PhoneFactory.getPhones()) {
6049 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6050 phone.setImsRegistrationState(registered);
6051 }
6052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 } finally {
6054 Binder.restoreCallingIdentity(identity);
6055 }
Wink Saville36469e72014-06-11 15:17:00 -07006056 }
6057
6058 /**
Stuart Scott54788802015-03-30 13:18:01 -07006059 * Set the network selection mode to automatic.
6060 *
6061 */
6062 @Override
6063 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6065 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066
6067 final long identity = Binder.clearCallingIdentity();
6068 try {
shilufc958392020-01-20 11:36:01 -08006069 if (!isActiveSubscription(subId)) {
6070 return;
6071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006073 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6074 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075 } finally {
6076 Binder.restoreCallingIdentity(identity);
6077 }
Stuart Scott54788802015-03-30 13:18:01 -07006078 }
6079
Jack Yud10cdd42020-09-28 20:28:01 -07006080 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006081 * Ask the radio to connect to the input network and change selection mode to manual.
6082 *
6083 * @param subId the id of the subscription.
6084 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6085 * the operator to attach to.
6086 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6087 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6088 * normal network selection next time.
6089 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006090 */
6091 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006092 public boolean setNetworkSelectionModeManual(
6093 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6095 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006096
6097 if (!isActiveSubscription(subId)) {
6098 return false;
6099 }
6100
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101 final long identity = Binder.clearCallingIdentity();
6102 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006103 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006105 if (DBG) {
6106 log("setNetworkSelectionModeManual: subId: " + subId
6107 + " operator: " + operatorInfo);
6108 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6110 } finally {
6111 Binder.restoreCallingIdentity(identity);
6112 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006113 }
shilu84f6e8b2019-12-19 13:58:01 -08006114 /**
6115 * Get the manual network selection
6116 *
6117 * @param subId the id of the subscription.
6118 *
6119 * @return the previously saved user selected PLMN
6120 */
6121 @Override
6122 public String getManualNetworkSelectionPlmn(int subId) {
6123 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006124 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006125 mApp, subId, "getManualNetworkSelectionPlmn");
6126
6127 final long identity = Binder.clearCallingIdentity();
6128 try {
6129 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006130 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006131 }
6132
6133 final Phone phone = getPhone(subId);
6134 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006135 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006136 }
6137 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6138 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6139 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6140 } finally {
6141 Binder.restoreCallingIdentity(identity);
6142 }
6143 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006144
6145 /**
6146 * Scans for available networks.
6147 */
6148 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006149 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6150 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6152 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006153 LocationAccessPolicy.LocationPermissionResult locationResult =
6154 LocationAccessPolicy.checkLocationPermission(mApp,
6155 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6156 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006157 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006158 .setCallingPid(Binder.getCallingPid())
6159 .setCallingUid(Binder.getCallingUid())
6160 .setMethod("getCellNetworkScanResults")
6161 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006162 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6163 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006164 .build());
6165 switch (locationResult) {
6166 case DENIED_HARD:
6167 throw new SecurityException("Not allowed to access scan results -- location");
6168 case DENIED_SOFT:
6169 return null;
6170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171
Pengquan Menga1bb6272018-09-06 09:59:22 -07006172 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006173 try {
6174 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006175 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177 } finally {
6178 Binder.restoreCallingIdentity(identity);
6179 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006180 }
6181
6182 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006183 * Get the call forwarding info, given the call forwarding reason.
6184 */
6185 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006186 public void getCallForwarding(int subId, int callForwardingReason,
6187 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006188 enforceReadPrivilegedPermission("getCallForwarding");
6189 long identity = Binder.clearCallingIdentity();
6190 try {
6191 if (DBG) {
6192 log("getCallForwarding: subId " + subId
6193 + " callForwardingReason" + callForwardingReason);
6194 }
Hall Liu27d24262020-09-18 19:04:59 -07006195
6196 Phone phone = getPhone(subId);
6197 if (phone == null) {
6198 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006199 callback.onError(
6200 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006201 } catch (RemoteException e) {
6202 // ignore
6203 }
6204 return;
6205 }
6206
6207 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6208 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6209 @Override
6210 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6211 try {
6212 callback.onCallForwardingInfoAvailable(info);
6213 } catch (RemoteException e) {
6214 // ignore
6215 }
6216 }
6217
6218 @Override
6219 public void onError(int error) {
6220 try {
6221 callback.onError(error);
6222 } catch (RemoteException e) {
6223 // ignore
6224 }
6225 }
6226 });
6227 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006228 } finally {
6229 Binder.restoreCallingIdentity(identity);
6230 }
6231 }
6232
6233 /**
6234 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6235 * reason, the number to forward, and the timeout before the forwarding is attempted.
6236 */
6237 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006238 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6239 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006240 enforceModifyPermission();
6241 long identity = Binder.clearCallingIdentity();
6242 try {
6243 if (DBG) {
6244 log("setCallForwarding: subId " + subId
6245 + " callForwardingInfo" + callForwardingInfo);
6246 }
Hall Liu27d24262020-09-18 19:04:59 -07006247
6248 Phone phone = getPhone(subId);
6249 if (phone == null) {
6250 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006251 callback.accept(
6252 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006253 } catch (RemoteException e) {
6254 // ignore
6255 }
6256 return;
6257 }
6258
6259 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6260 FunctionalUtils.ignoreRemoteException(callback::accept));
6261
6262 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006263 } finally {
6264 Binder.restoreCallingIdentity(identity);
6265 }
6266 }
6267
6268 /**
Hall Liu27d24262020-09-18 19:04:59 -07006269 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006270 */
6271 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006272 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006273 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006274 long identity = Binder.clearCallingIdentity();
6275 try {
Hall Liu27d24262020-09-18 19:04:59 -07006276 Phone phone = getPhone(subId);
6277 if (phone == null) {
6278 try {
6279 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6280 } catch (RemoteException e) {
6281 // ignore
6282 }
6283 return;
6284 }
SongFerngWang0e767992021-03-31 22:08:45 +08006285 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6286 PersistableBundle c = configManager.getConfigForSubId(subId);
6287 boolean requireUssd = c.getBoolean(
6288 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006289
Shuo Qian4a594052020-01-23 11:59:30 -08006290 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006291 if (requireUssd) {
6292 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6293 getSubscriptionCarrierId(subId));
6294 String newUssdCommand = "";
6295 try {
6296 newUssdCommand = carrierXmlParser.getFeature(
6297 CarrierXmlParser.FEATURE_CALL_WAITING)
6298 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6299 } catch (NullPointerException e) {
6300 loge("Failed to generate USSD number" + e);
6301 }
6302 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6303 mMainThreadHandler, callback, carrierXmlParser,
6304 CarrierXmlParser.SsEntry.SSAction.QUERY);
6305 final String ussdCommand = newUssdCommand;
6306 Executors.newSingleThreadExecutor().execute(() -> {
6307 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6308 });
6309 } else {
6310 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6311 callback::accept);
6312 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6313 }
Shuo Qian4a594052020-01-23 11:59:30 -08006314 } finally {
6315 Binder.restoreCallingIdentity(identity);
6316 }
6317 }
6318
6319 /**
Hall Liu27d24262020-09-18 19:04:59 -07006320 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006321 */
6322 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006323 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006324 enforceModifyPermission();
6325 long identity = Binder.clearCallingIdentity();
6326 try {
Hall Liu27d24262020-09-18 19:04:59 -07006327 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6328
6329 Phone phone = getPhone(subId);
6330 if (phone == null) {
6331 try {
6332 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6333 } catch (RemoteException e) {
6334 // ignore
6335 }
6336 return;
6337 }
6338
SongFerngWang0e767992021-03-31 22:08:45 +08006339 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6340 PersistableBundle c = configManager.getConfigForSubId(subId);
6341 boolean requireUssd = c.getBoolean(
6342 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006343
SongFerngWang0e767992021-03-31 22:08:45 +08006344 if (DBG) log("getCallWaitingStatus: subId " + subId);
6345 if (requireUssd) {
6346 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6347 getSubscriptionCarrierId(subId));
6348 CarrierXmlParser.SsEntry.SSAction ssAction =
6349 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6350 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6351 String newUssdCommand = "";
6352 try {
6353 newUssdCommand = carrierXmlParser.getFeature(
6354 CarrierXmlParser.FEATURE_CALL_WAITING)
6355 .makeCommand(ssAction, null);
6356 } catch (NullPointerException e) {
6357 loge("Failed to generate USSD number" + e);
6358 }
6359 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6360 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6361 final String ussdCommand = newUssdCommand;
6362 Executors.newSingleThreadExecutor().execute(() -> {
6363 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6364 });
6365 } else {
6366 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6367 FunctionalUtils.ignoreRemoteException(callback::accept));
6368
6369 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6370 }
Shuo Qian4a594052020-01-23 11:59:30 -08006371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
6374 }
6375
6376 /**
yinxub1bed742017-04-17 11:45:04 -07006377 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006378 *
yinxub1bed742017-04-17 11:45:04 -07006379 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006380 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6381 * location related information which will be sent if the caller already possess
6382 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006383 * @param request contains the radio access networks with bands/channels to scan
6384 * @param messenger callback messenger for scan results or errors
6385 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006386 * @return the id of the requested scan which can be used to stop the scan.
6387 */
6388 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006389 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6390 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006391 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6393 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006394 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006395 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6396 if (!renounceFineLocationAccess) {
6397 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6398 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6399 .setCallingPackage(callingPackage)
6400 .setCallingFeatureId(callingFeatureId)
6401 .setCallingPid(Binder.getCallingPid())
6402 .setCallingUid(Binder.getCallingUid())
6403 .setMethod("requestNetworkScan")
6404 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6405 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6406 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6407 .build());
6408 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006409 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006410 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6411 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006412 if (e != null) {
6413 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6414 throw e;
6415 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006416 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006417 return TelephonyScanManager.INVALID_SCAN_ID;
6418 }
6419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420 }
Hall Liu912dfd32019-04-25 14:02:26 -07006421 int callingUid = Binder.getCallingUid();
6422 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006423 final long identity = Binder.clearCallingIdentity();
6424 try {
6425 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006426 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006427 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006428 } finally {
6429 Binder.restoreCallingIdentity(identity);
6430 }
yinxu504e1392017-04-12 16:03:22 -07006431 }
6432
Hall Liub2ac8ef2019-02-28 15:56:23 -08006433 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006434 NetworkScanRequest request, int subId, String callingPackage) {
6435 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006436 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6437 boolean hasNetworkScanPermission =
6438 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6439 == PERMISSION_GRANTED;
6440
6441 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6442 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6443 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006444 }
6445
6446 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6447 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006448 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6449 return new SecurityException("Specific channels must not be"
6450 + " scanned without location access.");
6451 }
6452 }
6453 }
6454
Hall Liub2ac8ef2019-02-28 15:56:23 -08006455 return null;
6456 }
6457
yinxu504e1392017-04-12 16:03:22 -07006458 /**
6459 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006460 *
6461 * @param subId id of the subscription
6462 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006463 */
6464 @Override
6465 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6467 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006468
Hall Liu912dfd32019-04-25 14:02:26 -07006469 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006470 final long identity = Binder.clearCallingIdentity();
6471 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006472 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006473 } finally {
6474 Binder.restoreCallingIdentity(identity);
6475 }
yinxu504e1392017-04-12 16:03:22 -07006476 }
6477
6478 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006479 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006480 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006481 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006482 */
6483 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006484 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006485 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006486 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006487 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488
6489 final long identity = Binder.clearCallingIdentity();
6490 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006491 if (DBG) log("getAllowedNetworkTypesBitmask");
6492 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6493 int networkTypesBitmask = (result != null ? result[0] : -1);
6494 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6495 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006499 }
6500
6501 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006502 * Get the allowed network types for certain reason.
6503 *
6504 * @param subId the id of the subscription.
6505 * @param reason the reason the allowed network type change is taking place
6506 * @return the allowed network types.
6507 */
6508 @Override
6509 public long getAllowedNetworkTypesForReason(int subId,
6510 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006511 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006512 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006513 final long identity = Binder.clearCallingIdentity();
6514 try {
6515 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6516 } finally {
6517 Binder.restoreCallingIdentity(identity);
6518 }
6519 }
6520
6521 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006522 * Enable/Disable E-UTRA-NR Dual Connectivity
6523 * @param subId subscription id of the sim card
6524 * @param nrDualConnectivityState expected NR dual connectivity state
6525 * This can be passed following states
6526 * <ol>
6527 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6528 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6529 * <li>Disable NR dual connectivity and force secondary cell to be released
6530 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6531 * </ol>
6532 * @return operation result.
6533 */
6534 @Override
6535 public int setNrDualConnectivityState(int subId,
6536 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6538 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006539 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006540 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6541 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6542 }
6543
Sooraj Sasindran37444802020-08-11 10:40:43 -07006544 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6545 final long identity = Binder.clearCallingIdentity();
6546 try {
6547 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6548 nrDualConnectivityState, subId,
6549 workSource);
6550 if (DBG) log("enableNRDualConnectivity result: " + result);
6551 return result;
6552 } finally {
6553 Binder.restoreCallingIdentity(identity);
6554 }
6555 }
6556
6557 /**
6558 * Is E-UTRA-NR Dual Connectivity enabled
6559 * @return true if dual connectivity is enabled else false
6560 */
6561 @Override
6562 public boolean isNrDualConnectivityEnabled(int subId) {
6563 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006564 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006565 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006566 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006567 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6568 return false;
6569 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006570 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6571 final long identity = Binder.clearCallingIdentity();
6572 try {
6573 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6574 null, subId, workSource);
6575 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6576 return isEnabled;
6577 } finally {
6578 Binder.restoreCallingIdentity(identity);
6579 }
6580 }
6581
6582 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006583 * Set the allowed network types of the device and
6584 * provide the reason triggering the allowed network change.
6585 *
6586 * @param subId the id of the subscription.
6587 * @param reason the reason the allowed network type change is taking place
6588 * @param allowedNetworkTypes the allowed network types.
6589 * @return true on success; false on any failure.
6590 */
6591 @Override
6592 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006593 @TelephonyManager.AllowedNetworkTypesReason int reason,
6594 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6596 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006597 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006598 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6599 return false;
6600 }
6601 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6602 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006603 return false;
6604 }
6605
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006606 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6607 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6608
6609
6610 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6611 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6612 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006613 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006614
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006615 final long identity = Binder.clearCallingIdentity();
6616 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006617 Boolean success = (Boolean) sendRequest(
6618 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6619 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6620
6621 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6622 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006623 } finally {
6624 Binder.restoreCallingIdentity(identity);
6625 }
6626 }
6627
6628 /**
Miaoa84611c2019-03-15 09:21:10 +08006629 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006630 *
Miaoa84611c2019-03-15 09:21:10 +08006631 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006632 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006633 * @hide
6634 */
6635 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006636 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006637 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006638 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006639 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006640 try {
Miaoa84611c2019-03-15 09:21:10 +08006641 if (phone != null) {
6642 return phone.hasMatchedTetherApnSetting();
6643 } else {
6644 return false;
6645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646 } finally {
6647 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006648 }
Junda Liu475951f2014-11-07 16:45:03 -08006649 }
6650
6651 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006652 * Get the user enabled state of Mobile Data.
6653 *
6654 * TODO: remove and use isUserDataEnabled.
6655 * This can't be removed now because some vendor codes
6656 * calls through ITelephony directly while they should
6657 * use TelephonyManager.
6658 *
6659 * @return true on enabled
6660 */
6661 @Override
6662 public boolean getDataEnabled(int subId) {
6663 return isUserDataEnabled(subId);
6664 }
6665
6666 /**
6667 * Get whether mobile data is enabled per user setting.
6668 *
6669 * There are other factors deciding whether mobile data is actually enabled, but they are
6670 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006671 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006672 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6673 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006674 *
6675 * @return {@code true} if data is enabled else {@code false}
6676 */
6677 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006678 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006679 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006680 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006681 try {
6682 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6683 functionName);
6684 } catch (Exception e) {
6685 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6686 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006687 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006689 mApp, subId, functionName);
6690
Robert Greenwalt646120a2014-05-23 11:54:03 -07006691 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692
6693 final long identity = Binder.clearCallingIdentity();
6694 try {
6695 int phoneId = mSubscriptionController.getPhoneId(subId);
6696 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6697 Phone phone = PhoneFactory.getPhone(phoneId);
6698 if (phone != null) {
6699 boolean retVal = phone.isUserDataEnabled();
6700 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6701 return retVal;
6702 } else {
6703 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6704 return false;
6705 }
6706 } finally {
6707 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006708 }
6709 }
6710
6711 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006712 * Checks if the device is capable of mobile data by considering whether whether the
6713 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6714 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006715 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006716 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006717 */
6718 @Override
6719 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006720 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006721 try {
6722 try {
6723 mApp.enforceCallingOrSelfPermission(
6724 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006725 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006726 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006727 try {
6728 mApp.enforceCallingOrSelfPermission(
6729 android.Manifest.permission.READ_PHONE_STATE,
6730 functionName);
6731 } catch (Exception e2) {
6732 mApp.enforceCallingOrSelfPermission(
6733 permission.READ_BASIC_PHONE_STATE, functionName);
6734 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006735 }
6736 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006737 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006738 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739
6740 final long identity = Binder.clearCallingIdentity();
6741 try {
6742 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 Phone phone = PhoneFactory.getPhone(phoneId);
6744 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006745 boolean retVal;
6746 if (phone.isUsingNewDataStack()) {
6747 retVal = phone.getDataNetworkController().getDataSettingsManager()
6748 .isDataEnabled();
6749 } else {
6750 retVal = phone.getDataEnabledSettings().isDataEnabled();
6751 }
6752 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753 return retVal;
6754 } else {
6755 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6756 return false;
6757 }
6758 } finally {
6759 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006760 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006761 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006762
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006763 /**
6764 * Check if data is enabled for a specific reason
6765 * @param subId Subscription index
6766 * @param reason the reason the data enable change is taking place
6767 * @return {@code true} if the overall data is enabled; {@code false} if not.
6768 */
6769 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006770 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006771 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006772 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006773 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006774 try {
6775 mApp.enforceCallingOrSelfPermission(
6776 android.Manifest.permission.ACCESS_NETWORK_STATE,
6777 functionName);
6778 } catch (Exception e) {
6779 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6780 functionName);
6781 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006782 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006783 try {
6784 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006785 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006786 } catch (Exception e2) {
6787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006788 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006789 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006790 }
6791
6792
6793 final long identity = Binder.clearCallingIdentity();
6794 try {
6795 int phoneId = mSubscriptionController.getPhoneId(subId);
6796 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006797 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006798 + " reason=" + reason);
6799 }
6800 Phone phone = PhoneFactory.getPhone(phoneId);
6801 if (phone != null) {
6802 boolean retVal;
6803 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6804 retVal = phone.isUserDataEnabled();
6805 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006806 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006807 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006808 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006809 return retVal;
6810 } else {
6811 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006812 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006813 + subId + " retVal=false");
6814 }
6815 return false;
6816 }
6817 } finally {
6818 Binder.restoreCallingIdentity(identity);
6819 }
6820 }
6821
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006822 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006823 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006824 if (uid == Process.PHONE_UID) {
6825 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6826 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006827 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6828 }
6829
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006830 //load access rules from carrier configs, and check those as well: b/139133814
6831 SubscriptionController subController = SubscriptionController.getInstance();
6832 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6833 || subController == null) return privilegeFromSim;
6834
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006835 PackageManager pkgMgr = phone.getContext().getPackageManager();
6836 String[] packages = pkgMgr.getPackagesForUid(uid);
6837
6838 final long identity = Binder.clearCallingIdentity();
6839 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006840 int subId = phone.getSubId();
6841 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6842 // A test override is in place for the privileges for this subId, so don't try to
6843 // read the subscription privileges.
6844 return privilegeFromSim;
6845 }
6846 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006847 SubscriptionManager subManager = (SubscriptionManager)
6848 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6849 for (String pkg : packages) {
6850 if (subManager.canManageSubscription(subInfo, pkg)) {
6851 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6852 }
6853 }
6854 return privilegeFromSim;
6855 } finally {
6856 Binder.restoreCallingIdentity(identity);
6857 }
6858 }
6859
6860 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6861 String pkgName) {
6862 //load access rules from carrier configs, and check those as well: b/139133814
6863 SubscriptionController subController = SubscriptionController.getInstance();
6864 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6865 || subController == null) return privilegeFromSim;
6866
6867 final long identity = Binder.clearCallingIdentity();
6868 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006869 int subId = phone.getSubId();
6870 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6871 // A test override is in place for the privileges for this subId, so don't try to
6872 // read the subscription privileges.
6873 return privilegeFromSim;
6874 }
6875 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006876 SubscriptionManager subManager = (SubscriptionManager)
6877 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6878 return subManager.canManageSubscription(subInfo, pkgName)
6879 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6880 } finally {
6881 Binder.restoreCallingIdentity(identity);
6882 }
6883 }
6884
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006885 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006886 public int getCarrierPrivilegeStatus(int subId) {
6887 final Phone phone = getPhone(subId);
6888 if (phone == null) {
6889 loge("getCarrierPrivilegeStatus: Invalid subId");
6890 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6891 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006892 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6893 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006894 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006895 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6896 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006897
6898 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006899 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006900 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006901 }
Junda Liu29340342014-07-10 15:23:27 -07006902
6903 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006904 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006905 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006906 final Phone phone = getPhone(subId);
6907 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006908 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006909 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6910 }
6911 UiccProfile profile =
6912 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6913 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006914 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006915 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6916 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006917 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006918 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006919 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006920 }
6921
6922 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006923 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006924 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006925 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006926 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006927 }
6928
6929 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006930 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6931 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006932 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006933 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6934 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006935 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006936 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006937 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006938 }
6939
6940 @Override
6941 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006942 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006943 if (TextUtils.isEmpty(pkgName))
6944 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006945 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6946 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006947 UiccPort port = UiccController.getInstance().getUiccPort(i);
6948 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006949 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006950 continue;
6951 }
6952
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006953 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006954 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006955 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006956 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6957 break;
6958 }
6959 }
6960
6961 return result;
Junda Liu29340342014-07-10 15:23:27 -07006962 }
Derek Tan89e89d42014-07-08 17:00:10 -07006963
6964 @Override
Junda Liue64de782015-04-16 17:19:16 -07006965 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006966 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006967 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6968 loge("phoneId " + phoneId + " is not valid.");
6969 return null;
6970 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006971 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6972 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006973 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006974 return null ;
6975 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006976 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006977 }
6978
Amith Yamasani6e118872016-02-19 12:53:51 -08006979 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006980 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006981 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006982 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006983 List<String> privilegedPackages = new ArrayList<>();
6984 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006985 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006986 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006987 if (port != null) {
6988 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006989 if (packages == null) {
6990 // Only check packages in user 0 for now
6991 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006992 PackageManager.MATCH_DISABLED_COMPONENTS
6993 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006994 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006995 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006996 }
6997 for (int p = packages.size() - 1; p >= 0; p--) {
6998 PackageInfo pkgInfo = packages.get(p);
6999 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00007000 && getCarrierPrivilegeStatusFromCarrierConfigRules(
7001 port.getCarrierPrivilegeStatus(pkgInfo),
7002 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07007003 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08007004 privilegedPackages.add(pkgInfo.packageName);
7005 }
7006 }
7007 }
7008 }
7009 return privilegedPackages;
7010 }
7011
chen xuf7e9fe82019-05-09 19:31:02 -07007012 @Override
7013 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007014 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
7015
7016 final long identity = Binder.clearCallingIdentity();
7017
chen xuf7e9fe82019-05-09 19:31:02 -07007018 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007019 try {
7020 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7021 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7022 }
7023 } finally {
7024 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007025 }
7026 return privilegedPackages;
7027 }
7028
Wink Savilleb564aae2014-10-23 10:18:09 -07007029 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007030 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007031 UiccPort port = phone == null ? null : phone.getUiccPort();
7032 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007033 return null;
7034 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007035 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007036 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007037 return null;
7038 }
7039 return iccId;
7040 }
7041
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007042 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007043 public void setCallComposerStatus(int subId, int status) {
7044 enforceModifyPermission();
7045
7046 final long identity = Binder.clearCallingIdentity();
7047 try {
7048 Phone phone = getPhone(subId);
7049 if (phone != null) {
7050 Phone defaultPhone = phone.getImsPhone();
7051 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7052 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7053 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007054 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7055 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007056 }
7057 }
Shuo Qian284ae752020-12-22 19:10:14 -08007058 } catch (ImsException e) {
7059 throw new ServiceSpecificException(e.getCode());
7060 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007061 Binder.restoreCallingIdentity(identity);
7062 }
7063 }
7064
7065 @Override
7066 public int getCallComposerStatus(int subId) {
7067 enforceReadPrivilegedPermission("getCallComposerStatus");
7068
7069 final long identity = Binder.clearCallingIdentity();
7070 try {
7071 Phone phone = getPhone(subId);
7072 if (phone != null) {
7073 Phone defaultPhone = phone.getImsPhone();
7074 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7075 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7076 return imsPhone.getCallComposerStatus();
7077 }
7078 }
7079 } finally {
7080 Binder.restoreCallingIdentity(identity);
7081 }
7082 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7083 }
7084
7085 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007086 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7087 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007088 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007089 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007091 final long identity = Binder.clearCallingIdentity();
7092 try {
7093 final String iccId = getIccId(subId);
7094 final Phone phone = getPhone(subId);
7095 if (phone == null) {
7096 return false;
7097 }
7098 final String subscriberId = phone.getSubscriberId();
7099
7100 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007101 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102 + subscriberId + " to " + number);
7103 }
7104
7105 if (TextUtils.isEmpty(iccId)) {
7106 return false;
7107 }
7108
7109 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7110
7111 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7112 if (alphaTag == null) {
7113 editor.remove(alphaTagPrefKey);
7114 } else {
7115 editor.putString(alphaTagPrefKey, alphaTag);
7116 }
7117
7118 // Record both the line number and IMSI for this ICCID, since we need to
7119 // track all merged IMSIs based on line number
7120 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7121 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7122 if (number == null) {
7123 editor.remove(numberPrefKey);
7124 editor.remove(subscriberPrefKey);
7125 } else {
7126 editor.putString(numberPrefKey, number);
7127 editor.putString(subscriberPrefKey, subscriberId);
7128 }
7129
7130 editor.commit();
7131 return true;
7132 } finally {
7133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007134 }
Derek Tan7226c842014-07-02 17:42:23 -07007135 }
7136
7137 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007138 public String getLine1NumberForDisplay(int subId, String callingPackage,
7139 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007140 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007142 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007143 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007144 return null;
7145 }
Derek Tan97ebb422014-09-05 16:55:38 -07007146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147 final long identity = Binder.clearCallingIdentity();
7148 try {
7149 String iccId = getIccId(subId);
7150 if (iccId != null) {
7151 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7152 if (DBG_MERGE) {
7153 log("getLine1NumberForDisplay returning "
7154 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7155 }
7156 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007157 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007158 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7159 return null;
7160 } finally {
7161 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007162 }
Derek Tan7226c842014-07-02 17:42:23 -07007163 }
7164
7165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007166 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7167 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007169 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007170 return null;
7171 }
Derek Tan97ebb422014-09-05 16:55:38 -07007172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 final long identity = Binder.clearCallingIdentity();
7174 try {
7175 String iccId = getIccId(subId);
7176 if (iccId != null) {
7177 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7178 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7179 }
7180 return null;
7181 } finally {
7182 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007183 }
Derek Tan7226c842014-07-02 17:42:23 -07007184 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007185
7186 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007187 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7188 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007189 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7190 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007192 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007193 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007194 return null;
7195 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007196
Jordan Liub49b04b2019-05-06 14:45:15 -07007197 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7198 // the process, where TelephonyManager was instantiated.
7199 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007200 final long identity = Binder.clearCallingIdentity();
7201 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007202 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 final TelephonyManager tele = TelephonyManager.from(context);
7204 final SubscriptionManager sub = SubscriptionManager.from(context);
7205
7206 // Figure out what subscribers are currently active
7207 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007208
Jordan Liub49b04b2019-05-06 14:45:15 -07007209 // Only consider subs which match the current subId
7210 // This logic can be simplified. See b/131189269 for progress.
7211 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007212 activeSubscriberIds.add(tele.getSubscriberId(subId));
7213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214
7215 // First pass, find a number override for an active subscriber
7216 String mergeNumber = null;
7217 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7218 for (String key : prefs.keySet()) {
7219 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7220 final String subscriberId = (String) prefs.get(key);
7221 if (activeSubscriberIds.contains(subscriberId)) {
7222 final String iccId = key.substring(
7223 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7224 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7225 mergeNumber = (String) prefs.get(numberKey);
7226 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007227 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228 + " for active subscriber " + subscriberId);
7229 }
7230 if (!TextUtils.isEmpty(mergeNumber)) {
7231 break;
7232 }
7233 }
7234 }
7235 }
7236
7237 // Shortcut when no active merged subscribers
7238 if (TextUtils.isEmpty(mergeNumber)) {
7239 return null;
7240 }
7241
7242 // Second pass, find all subscribers under that line override
7243 final ArraySet<String> result = new ArraySet<>();
7244 for (String key : prefs.keySet()) {
7245 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7246 final String number = (String) prefs.get(key);
7247 if (mergeNumber.equals(number)) {
7248 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7249 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7250 final String subscriberId = (String) prefs.get(subscriberKey);
7251 if (!TextUtils.isEmpty(subscriberId)) {
7252 result.add(subscriberId);
7253 }
7254 }
7255 }
7256 }
7257
7258 final String[] resultArray = result.toArray(new String[result.size()]);
7259 Arrays.sort(resultArray);
7260 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007261 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007262 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7263 }
7264 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007265 } finally {
7266 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007267 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007268 }
7269
7270 @Override
zoey chen38003472019-12-13 17:16:31 +08007271 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7272 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007273
7274 final long identity = Binder.clearCallingIdentity();
7275 try {
7276 final TelephonyManager telephonyManager = mApp.getSystemService(
7277 TelephonyManager.class);
7278 String subscriberId = telephonyManager.getSubscriberId(subId);
7279 if (subscriberId == null) {
7280 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007281 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007282 + subId);
7283 }
7284 return null;
7285 }
7286
7287 final SubscriptionInfo info = SubscriptionController.getInstance()
7288 .getSubscriptionInfo(subId);
7289 final ParcelUuid groupUuid = info.getGroupUuid();
7290 // If it doesn't belong to any group, return just subscriberId of itself.
7291 if (groupUuid == null) {
7292 return new String[]{subscriberId};
7293 }
7294
7295 // Get all subscriberIds from the group.
7296 final List<String> mergedSubscriberIds = new ArrayList<>();
7297 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007298 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007299 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007300 for (SubscriptionInfo subInfo : groupInfos) {
7301 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7302 if (subscriberId != null) {
7303 mergedSubscriberIds.add(subscriberId);
7304 }
7305 }
7306
7307 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7308 } finally {
7309 Binder.restoreCallingIdentity(identity);
7310
7311 }
7312 }
7313
7314 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007315 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007316 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007317 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 final Phone phone = getPhone(subId);
7322 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7323 } finally {
7324 Binder.restoreCallingIdentity(identity);
7325 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007326 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007327
7328 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007329 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007330 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7331 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007332 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7333 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007334
7335 final long identity = Binder.clearCallingIdentity();
7336 try {
7337 final Phone phone = getPhone(subId);
7338 if (phone == null) {
7339 return false;
7340 }
7341 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7342 cdmaNonRoamingList);
7343 } finally {
7344 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007345 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007346 }
7347
7348 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007349 @Deprecated
7350 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7351 enforceModifyPermission();
7352
7353 int returnValue = 0;
7354 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007355 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007356 if(result.exception == null) {
7357 if (result.result != null) {
7358 byte[] responseData = (byte[])(result.result);
7359 if(responseData.length > oemResp.length) {
7360 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7361 responseData.length + "bytes. Buffer Size is " +
7362 oemResp.length + "bytes.");
7363 }
7364 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7365 returnValue = responseData.length;
7366 }
7367 } else {
7368 CommandException ex = (CommandException) result.exception;
7369 returnValue = ex.getCommandError().ordinal();
7370 if(returnValue > 0) returnValue *= -1;
7371 }
7372 } catch (RuntimeException e) {
7373 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7374 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7375 if(returnValue > 0) returnValue *= -1;
7376 }
7377
7378 return returnValue;
7379 }
7380
7381 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007382 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007383 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007384 try {
7385 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007386 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007387 mApp, phone.getSubId(), "getRadioAccessFamily");
7388 } catch (SecurityException e) {
7389 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7390 throw e;
7391 }
chen xub97461a2018-10-26 14:17:57 -07007392 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007393 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007394 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396 final long identity = Binder.clearCallingIdentity();
7397 try {
chen xub97461a2018-10-26 14:17:57 -07007398 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007399 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007400 mApp, phone.getSubId(), "getRadioAccessFamily");
7401 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007402 } finally {
7403 Binder.restoreCallingIdentity(identity);
7404 }
chen xub97461a2018-10-26 14:17:57 -07007405 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007406 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007407
7408 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007409 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007410 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007411 try {
7412 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7413 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007414 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007415 }
7416 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007417 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007418 }
7419 RoleManager rm = mApp.getSystemService(RoleManager.class);
7420 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7421 if (!dialerRoleHolders.contains(callingPackage)) {
7422 throw new SecurityException("App must be the dialer role holder to"
7423 + " upload a call composer pic");
7424 }
7425
7426 Executors.newSingleThreadExecutor().execute(() -> {
7427 ByteArrayOutputStream output = new ByteArrayOutputStream(
7428 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7429 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7430 boolean readUntilEnd = false;
7431 int totalBytesRead = 0;
7432 byte[] buffer = new byte[16 * 1024];
7433 while (true) {
7434 int numRead;
7435 try {
7436 numRead = input.read(buffer);
7437 } catch (IOException e) {
7438 try {
7439 fd.checkError();
7440 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7441 null);
7442 } catch (IOException e1) {
7443 // This means that the other side closed explicitly with an error. If this
7444 // happens, log and ignore.
7445 loge("Remote end of call composer picture pipe closed: " + e1);
7446 }
7447 break;
7448 }
7449 if (numRead == -1) {
7450 readUntilEnd = true;
7451 break;
7452 }
7453 totalBytesRead += numRead;
7454 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7455 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7456 try {
7457 input.close();
7458 } catch (IOException e) {
7459 // ignore
7460 }
7461 break;
7462 }
7463 output.write(buffer, 0, numRead);
7464 }
7465 // Generally, the remote end will close the file descriptors. The only case where we
7466 // close is above, where the picture size is too big.
7467
7468 try {
7469 fd.checkError();
7470 } catch (IOException e) {
7471 loge("Remote end for call composer closed with an error: " + e);
7472 return;
7473 }
7474
Hall Liuaa4211e2021-01-20 15:43:39 -08007475 if (!readUntilEnd) {
7476 loge("Did not finish reading entire image; aborting");
7477 return;
7478 }
Hall Liu82694d52020-12-11 18:22:04 -08007479
Hall Liuaa4211e2021-01-20 15:43:39 -08007480 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7481 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7482 new CallComposerPictureTransfer.Factory() {},
7483 imageData,
7484 (result) -> {
7485 if (result.first != null) {
7486 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7487 Bundle outputResult = new Bundle();
7488 outputResult.putParcelable(
7489 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7490 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7491 outputResult);
7492 } else {
7493 callback.send(result.second, null);
7494 }
7495 }
7496 );
Hall Liu82694d52020-12-11 18:22:04 -08007497 });
7498 }
7499
7500 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007501 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007502 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007503 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504
7505 final long identity = Binder.clearCallingIdentity();
7506 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007507 ImsManager.getInstance(defaultPhone.getContext(),
7508 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007512 }
7513
7514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007515 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007516 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007517 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7518 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007519 return false;
7520 }
Svet Ganovb320e182015-04-16 12:30:10 -07007521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 final long identity = Binder.clearCallingIdentity();
7523 try {
7524 // Check the user preference and the system-level IMS setting. Even if the user has
7525 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7526 // In the long run, we may instead need to check if there exists a connection service
7527 // which can support video calling.
7528 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007529 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 return imsManager.isVtEnabledByPlatform()
7531 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7532 && imsManager.isVtEnabledByUser();
7533 } finally {
7534 Binder.restoreCallingIdentity(identity);
7535 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007536 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007537
Andrew Leea1239f22015-03-02 17:44:07 -08007538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007539 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7540 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007542 mApp, subId, callingPackage, callingFeatureId,
7543 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 return false;
7545 }
7546
7547 final long identity = Binder.clearCallingIdentity();
7548 try {
7549 CarrierConfigManager configManager =
7550 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007551 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7553 } finally {
7554 Binder.restoreCallingIdentity(identity);
7555 }
Andrew Leea1239f22015-03-02 17:44:07 -08007556 }
7557
7558 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007559 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007561 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 return false;
7563 }
7564
7565 final long identity = Binder.clearCallingIdentity();
7566 try {
7567 CarrierConfigManager configManager =
7568 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007569 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7571 } finally {
7572 Binder.restoreCallingIdentity(identity);
7573 }
Andrew Leea1239f22015-03-02 17:44:07 -08007574 }
7575
Andrew Lee9431b832015-03-09 18:46:45 -07007576 @Override
7577 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007578 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007579 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007580 }
7581
7582 @Override
7583 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007584 final long identity = Binder.clearCallingIdentity();
7585 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007586 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 } finally {
7588 Binder.restoreCallingIdentity(identity);
7589 }
Andrew Lee9431b832015-03-09 18:46:45 -07007590 }
7591
Hall Liuf6668912018-10-31 17:05:23 -07007592 /**
7593 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7594 * support for the feature and device firmware support.
7595 *
7596 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7597 */
7598 @Override
7599 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007601 final Phone phone = getPhone(subscriptionId);
7602 if (phone == null) {
7603 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7604 return false;
7605 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007606 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007607 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007608 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7609 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007610 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007611 return isCarrierSupported && isDeviceSupported;
7612 } finally {
7613 Binder.restoreCallingIdentity(identity);
7614 }
Hall Liu98187582018-01-22 19:15:32 -08007615 }
7616
Hall Liuf6668912018-10-31 17:05:23 -07007617 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007618 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7619 * RTT setting, will return true if the device and carrier both support RTT.
7620 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007621 */
7622 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007623 final long identity = Binder.clearCallingIdentity();
7624 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007625 boolean isRttSupported = isRttSupported(subscriptionId);
7626 boolean isUserRttSettingOn = Settings.Secure.getInt(
7627 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7628 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7629 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7630 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007631 } finally {
7632 Binder.restoreCallingIdentity(identity);
7633 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007634 }
7635
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007636 @Deprecated
7637 @Override
7638 public String getDeviceId(String callingPackage) {
7639 return getDeviceIdWithFeature(callingPackage, null);
7640 }
7641
Sanket Padawe7310cc72015-01-14 09:53:20 -08007642 /**
7643 * Returns the unique device ID of phone, for example, the IMEI for
7644 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7645 *
7646 * <p>Requires Permission:
7647 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7648 */
7649 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007650 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007651 try {
7652 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7653 } catch (SecurityException se) {
7654 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7655 throw new SecurityException("Package " + callingPackage + " does not belong to "
7656 + Binder.getCallingUid());
7657 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007658 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007659 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007660 return null;
7661 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007662 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007663 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007664 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007665 return null;
7666 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667
7668 final long identity = Binder.clearCallingIdentity();
7669 try {
7670 return phone.getDeviceId();
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
7673 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007674 }
7675
Ping Sunc67b7c22016-03-02 19:16:45 +08007676 /**
7677 * {@hide}
7678 * Returns the IMS Registration Status on a particular subid
7679 *
7680 * @param subId
7681 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007682 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007683 Phone phone = getPhone(subId);
7684 if (phone != null) {
7685 return phone.isImsRegistered();
7686 } else {
7687 return false;
7688 }
7689 }
7690
Santos Cordon7a1885b2015-02-03 11:15:19 -08007691 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007692 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007693 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007694 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007695 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007696 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7697 }
7698 final long identity = Binder.clearCallingIdentity();
7699 try {
7700 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7701 } finally {
7702 Binder.restoreCallingIdentity(identity);
7703 }
7704 }
7705
7706 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007707 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007708 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007709 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007710 mApp,
7711 subscriptionId,
7712 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007713 final long identity = Binder.clearCallingIdentity();
7714 try {
7715 Phone phone = getPhone(subscriptionId);
7716 if (phone == null) {
7717 return null;
7718 }
7719 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7720 } finally {
7721 Binder.restoreCallingIdentity(identity);
7722 }
7723 }
7724
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007725 /**
7726 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007727 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007728 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007729 final long identity = Binder.clearCallingIdentity();
7730 try {
7731 Phone phone = getPhone(subId);
7732 if (phone != null) {
7733 return phone.isWifiCallingEnabled();
7734 } else {
7735 return false;
7736 }
7737 } finally {
7738 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007739 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007740 }
7741
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007742 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007743 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007744 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007745 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 final long identity = Binder.clearCallingIdentity();
7747 try {
7748 Phone phone = getPhone(subId);
7749 if (phone != null) {
7750 return phone.isVideoEnabled();
7751 } else {
7752 return false;
7753 }
7754 } finally {
7755 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007756 }
7757 }
7758
7759 /**
7760 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7761 * defined in {@link ImsRegistrationImplBase}.
7762 */
7763 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007764 final long identity = Binder.clearCallingIdentity();
7765 try {
7766 Phone phone = getPhone(subId);
7767 if (phone != null) {
7768 return phone.getImsRegistrationTech();
7769 } else {
7770 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7771 }
7772 } finally {
7773 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007774 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007775 }
7776
Stuart Scott8eef64f2015-04-08 15:13:54 -07007777 @Override
7778 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007779 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007780 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7781 return;
7782 }
Kai Shif70f46f2021-03-03 13:59:46 -08007783 Phone defaultPhone = getDefaultPhone();
7784 if (defaultPhone != null) {
7785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7786 mApp, getDefaultPhone().getSubId(), "factoryReset");
7787 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007788 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007789
Svet Ganovcc087f82015-05-12 20:35:54 -07007790 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007791 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7792 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007793 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007794 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007795 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007796 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007797 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007798 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007799 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007800 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007801 // There has been issues when Sms raw table somehow stores orphan
7802 // fragments. They lead to garbled message when new fragments come
7803 // in and combined with those stale ones. In case this happens again,
7804 // user can reset all network settings which will clean up this table.
7805 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007806 // Clean up IMS settings as well here.
7807 int slotId = getSlotIndex(subId);
7808 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7809 ImsManager.getInstance(mApp, slotId).factoryReset();
7810 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007811
Kai Shif70f46f2021-03-03 13:59:46 -08007812 if (defaultPhone == null) {
7813 return;
7814 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007815 // Erase modem config if erase modem on network setting is enabled.
7816 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7817 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7818 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007819 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007820 }
Kai Shif70f46f2021-03-03 13:59:46 -08007821
7822 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007823 } finally {
7824 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007825 }
7826 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007827
SongFerngWangfd89b102021-05-27 22:44:54 +08007828 @VisibleForTesting
7829 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7830 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7831 return;
7832 }
7833 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7834 RILConstants.PREFERRED_NETWORK_MODE);
7835 SubscriptionManager.setSubscriptionProperty(subId,
7836 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7837 "user=" + defaultNetworkType);
7838 phone.loadAllowedNetworksFromSubscriptionDatabase();
7839 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7840 defaultNetworkType, null);
7841 }
7842
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007843 private void cleanUpSmsRawTable(Context context) {
7844 ContentResolver resolver = context.getContentResolver();
7845 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7846 resolver.delete(uri, null, null);
7847 }
7848
Narayan Kamath1c496c22015-04-16 14:40:19 +01007849 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007850 public String getSimLocaleForSubscriber(int subId) {
7851 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7852 final Phone phone = getPhone(subId);
7853 if (phone == null) {
7854 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007855 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857 final long identity = Binder.clearCallingIdentity();
7858 try {
chen xu5d3637b2019-01-21 23:31:38 -08007859 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007860 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007861 if (info == null) {
7862 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7863 return null;
7864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 // Try and fetch the locale from the carrier properties or from the SIM language
7866 // preferences (EF-PL and EF-LI)...
7867 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007869 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7870 if (localeFromDefaultSim != null) {
7871 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7872 if (DBG) log("Using locale from subId: " + subId + " locale: "
7873 + localeFromDefaultSim);
7874 return localeFromDefaultSim.toLanguageTag();
7875 } else {
7876 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007877 }
7878 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007880 // The SIM language preferences only store a language (e.g. fr = French), not an
7881 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7882 // the SIM and carrier preferences does not include a country we add the country
7883 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007884 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007886 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007887 return mccLocale.toLanguageTag();
7888 }
7889
7890 if (DBG) log("No locale found - returning null");
7891 return null;
7892 } finally {
7893 Binder.restoreCallingIdentity(identity);
7894 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007895 }
7896
7897 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007898 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007899 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007900 }
7901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007902 /**
7903 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7904 */
7905 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007906 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007907 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007908 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007909
Chenjie Yu1ba97252018-01-11 18:16:20 -08007910 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007911 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007912
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007913 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007914 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7915 * representing the state of the modem.
7916 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007917 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7918 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007919 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007920 */
7921 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007922 public void requestModemActivityInfo(ResultReceiver result) {
7923 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007924 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925
7926 final long identity = Binder.clearCallingIdentity();
7927 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007928 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007929 } finally {
7930 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007931 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007932 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007933
Siddharth Rayb8114062018-06-17 15:02:38 -07007934 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7935 // less than total activity duration.
7936 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7937 if (info == null) {
7938 return false;
7939 }
7940 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007941 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7942 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7943
Siddharth Rayb8114062018-06-17 15:02:38 -07007944 return (info.isValid()
7945 && (info.getSleepTimeMillis() <= activityDurationMs)
7946 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007947 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007948 && (totalTxTimeMs <= activityDurationMs));
7949 }
7950
Jack Yu85bd38a2015-11-09 11:34:32 -08007951 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007952 * Returns the service state information on specified subscription.
7953 */
7954 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007955 public ServiceState getServiceStateForSubscriber(int subId,
7956 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7957 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007958 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007959 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007960 return null;
7961 }
7962
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007963 boolean hasFinePermission = false;
7964 boolean hasCoarsePermission = false;
7965 if (!renounceFineLocationAccess) {
7966 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7967 LocationAccessPolicy.checkLocationPermission(mApp,
7968 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7969 .setCallingPackage(callingPackage)
7970 .setCallingFeatureId(callingFeatureId)
7971 .setCallingPid(Binder.getCallingPid())
7972 .setCallingUid(Binder.getCallingUid())
7973 .setMethod("getServiceStateForSubscriber")
7974 .setLogAsInfo(true)
7975 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7976 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7977 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7978 .build());
7979 hasFinePermission =
7980 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7981 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007982
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007983 if (!renounceCoarseLocationAccess) {
7984 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7985 LocationAccessPolicy.checkLocationPermission(mApp,
7986 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7987 .setCallingPackage(callingPackage)
7988 .setCallingFeatureId(callingFeatureId)
7989 .setCallingPid(Binder.getCallingPid())
7990 .setCallingUid(Binder.getCallingUid())
7991 .setMethod("getServiceStateForSubscriber")
7992 .setLogAsInfo(true)
7993 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7994 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7995 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7996 .build());
7997 hasCoarsePermission =
7998 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7999 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008000
Jack Yu479f40e2020-10-27 21:29:25 -07008001 final Phone phone = getPhone(subId);
8002 if (phone == null) {
8003 return null;
8004 }
8005
Jordan Liu0f2bc442020-11-18 16:47:37 -08008006 final long identity = Binder.clearCallingIdentity();
8007
Jack Yu479f40e2020-10-27 21:29:25 -07008008 boolean isCallingPackageDataService = phone.getDataServicePackages()
8009 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008011 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8012 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8013 Rlog.d(LOG_TAG,
8014 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8015 return null;
8016 }
8017
Hall Liuf19c44f2018-11-27 14:38:17 -08008018 ServiceState ss = phone.getServiceState();
8019
8020 // Scrub out the location info in ServiceState depending on what level of access
8021 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008022 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008023 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8024 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008025 } finally {
8026 Binder.restoreCallingIdentity(identity);
8027 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008028 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008029
8030 /**
8031 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8032 *
8033 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8034 * voicemail ringtone.
8035 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8036 * PhoneAccount.
8037 */
8038 @Override
8039 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008040 final long identity = Binder.clearCallingIdentity();
8041 try {
8042 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8043 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008044 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008045 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8048 } finally {
8049 Binder.restoreCallingIdentity(identity);
8050 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008051 }
8052
8053 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008054 * Sets the per-account voicemail ringtone.
8055 *
8056 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8057 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8058 *
8059 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8060 * voicemail ringtone.
8061 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8062 * PhoneAccount.
8063 */
8064 @Override
8065 public void setVoicemailRingtoneUri(String callingPackage,
8066 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008067 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008068 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008069 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8070 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8072 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8073 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075
8076 final long identity = Binder.clearCallingIdentity();
8077 try {
8078 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8079 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008080 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 }
8082 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8083 } finally {
8084 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008085 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008086 }
8087
8088 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008089 * Returns whether vibration is set for voicemail notification in Phone settings.
8090 *
8091 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8092 * voicemail vibration setting.
8093 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8094 */
8095 @Override
8096 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 final long identity = Binder.clearCallingIdentity();
8098 try {
8099 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8100 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008101 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008102 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8105 } finally {
8106 Binder.restoreCallingIdentity(identity);
8107 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008108 }
8109
Youhan Wange64578a2016-05-02 15:32:42 -07008110 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008111 * Sets the per-account voicemail vibration.
8112 *
8113 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8114 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8115 *
8116 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8117 * voicemail vibration setting.
8118 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8119 * specific PhoneAccount.
8120 */
8121 @Override
8122 public void setVoicemailVibrationEnabled(String callingPackage,
8123 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008124 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008125 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008126 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8127 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8129 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8130 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008131 }
8132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133 final long identity = Binder.clearCallingIdentity();
8134 try {
8135 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8136 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008137 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008138 }
8139 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8140 } finally {
8141 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008142 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008143 }
8144
8145 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008146 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8147 *
8148 * @throws SecurityException if the caller does not have the required permission
8149 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008150 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008151 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008152 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008153 }
8154
8155 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008156 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8157 * permission.
8158 *
8159 * @throws SecurityException if the caller does not have the required permission
8160 */
8161 private void enforceSendSmsPermission() {
8162 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8163 }
8164
8165 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008166 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008167 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008168 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008169 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008170 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008171 final long identity = Binder.clearCallingIdentity();
8172 try {
8173 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008174 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008175 if (componentName == null) {
8176 throw new SecurityException(
8177 "Caller not current active visual voicemail package[null]");
8178 }
8179 String vvmPackage = componentName.getPackageName();
8180 if (!callingPackage.equals(vvmPackage)) {
8181 throw new SecurityException("Caller not current active visual voicemail package["
8182 + vvmPackage + "]");
8183 }
8184 } finally {
8185 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008186 }
8187 }
8188
8189 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008190 * Return the application ID for the app type.
8191 *
8192 * @param subId the subscription ID that this request applies to.
8193 * @param appType the uicc app type.
8194 * @return Application ID for specificied app type, or null if no uicc.
8195 */
8196 @Override
8197 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008198 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008199 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200
8201 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008202 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008203 if (phone == null) {
8204 return null;
8205 }
8206 String aid = null;
8207 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008208 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209 .getApplicationByType(appType).getAid();
8210 } catch (Exception e) {
8211 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8212 }
8213 return aid;
8214 } finally {
8215 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008216 }
Youhan Wange64578a2016-05-02 15:32:42 -07008217 }
8218
Youhan Wang4001d252016-05-11 10:29:41 -07008219 /**
8220 * Return the Electronic Serial Number.
8221 *
8222 * @param subId the subscription ID that this request applies to.
8223 * @return ESN or null if error.
8224 */
8225 @Override
8226 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008227 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008228 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008229
8230 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008231 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232 if (phone == null) {
8233 return null;
8234 }
8235 String esn = null;
8236 try {
8237 esn = phone.getEsn();
8238 } catch (Exception e) {
8239 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8240 }
8241 return esn;
8242 } finally {
8243 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008244 }
Youhan Wang4001d252016-05-11 10:29:41 -07008245 }
8246
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008247 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008248 * Return the Preferred Roaming List Version.
8249 *
8250 * @param subId the subscription ID that this request applies to.
8251 * @return PRLVersion or null if error.
8252 */
8253 @Override
8254 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008255 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008256 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257
8258 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008259 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008260 if (phone == null) {
8261 return null;
8262 }
8263 String cdmaPrlVersion = null;
8264 try {
8265 cdmaPrlVersion = phone.getCdmaPrlVersion();
8266 } catch (Exception e) {
8267 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8268 }
8269 return cdmaPrlVersion;
8270 } finally {
8271 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008272 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008273 }
8274
8275 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008276 * Get snapshot of Telephony histograms
8277 * @return List of Telephony histograms
8278 * @hide
8279 */
8280 @Override
8281 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8283 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008284
8285 final long identity = Binder.clearCallingIdentity();
8286 try {
8287 return RIL.getTelephonyRILTimingHistograms();
8288 } finally {
8289 Binder.restoreCallingIdentity(identity);
8290 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008291 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008292
8293 /**
8294 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008295 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8296 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008297 * Require system privileges. In the future we may add this to carrier APIs.
8298 *
Michele Berionne482f8202018-11-27 18:57:59 -08008299 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008300 */
8301 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008302 @TelephonyManager.SetCarrierRestrictionResult
8303 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008304 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008305 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008306
Michele Berionne482f8202018-11-27 18:57:59 -08008307 if (carrierRestrictionRules == null) {
8308 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008309 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008311 final long identity = Binder.clearCallingIdentity();
8312 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008313 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008314 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315 } finally {
8316 Binder.restoreCallingIdentity(identity);
8317 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008318 }
8319
8320 /**
8321 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008322 * Get the allowed carrier list and the excluded carrier list, including the priority between
8323 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008324 * Require system privileges. In the future we may add this to carrier APIs.
8325 *
Michele Berionne482f8202018-11-27 18:57:59 -08008326 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008327 */
8328 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008329 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008330 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008331 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008332
8333 final long identity = Binder.clearCallingIdentity();
8334 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008335 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8336 if (response instanceof CarrierRestrictionRules) {
8337 return (CarrierRestrictionRules) response;
8338 }
8339 // Response is an Exception of some kind,
8340 // which is signalled to the user as a NULL retval
8341 return null;
8342 } catch (Exception e) {
8343 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8344 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008345 } finally {
8346 Binder.restoreCallingIdentity(identity);
8347 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008348 }
8349
fionaxu59545b42016-05-25 15:53:37 -07008350 /**
fionaxu59545b42016-05-25 15:53:37 -07008351 * Action set from carrier signalling broadcast receivers to enable/disable radio
8352 * @param subId the subscription ID that this action applies to.
8353 * @param enabled control enable or disable radio.
8354 * {@hide}
8355 */
8356 @Override
8357 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8358 enforceModifyPermission();
8359 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008360
8361 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008362 if (phone == null) {
8363 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8364 return;
8365 }
8366 try {
8367 phone.carrierActionSetRadioEnabled(enabled);
8368 } catch (Exception e) {
8369 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008370 } finally {
8371 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008372 }
8373 }
8374
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008375 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008376 * Enable or disable Voice over NR (VoNR)
8377 * @param subId the subscription ID that this action applies to.
8378 * @param enabled enable or disable VoNR.
8379 * @return operation result.
8380 */
8381 @Override
8382 public int setVoNrEnabled(int subId, boolean enabled) {
8383 enforceModifyPermission();
8384 final Phone phone = getPhone(subId);
8385
8386 final long identity = Binder.clearCallingIdentity();
8387 if (phone == null) {
8388 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8389 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8390 }
8391
8392 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8393 try {
8394 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8395 workSource);
8396 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008397
8398 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8399 if (DBG) {
8400 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8401 }
8402 SubscriptionManager.setSubscriptionProperty(
8403 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8404 (enabled ? "1" : "0"));
8405 }
8406
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008407 return result;
8408 } finally {
8409 Binder.restoreCallingIdentity(identity);
8410 }
8411 }
8412
8413 /**
8414 * Is voice over NR enabled
8415 * @return true if VoNR is enabled else false
8416 */
8417 @Override
8418 public boolean isVoNrEnabled(int subId) {
8419 enforceReadPrivilegedPermission("isVoNrEnabled");
8420 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8421 final long identity = Binder.clearCallingIdentity();
8422 try {
8423 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8424 null, subId, workSource);
8425 if (DBG) log("isVoNrEnabled: " + isEnabled);
8426 return isEnabled;
8427 } finally {
8428 Binder.restoreCallingIdentity(identity);
8429 }
8430 }
8431
8432 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008433 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8434 * network status based on which carrier apps could apply actions accordingly,
8435 * enable/disable default url handler for example.
8436 *
8437 * @param subId the subscription ID that this action applies to.
8438 * @param report control start/stop reporting the default network status.
8439 * {@hide}
8440 */
8441 @Override
8442 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8443 enforceModifyPermission();
8444 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008445
8446 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008447 if (phone == null) {
8448 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8449 return;
8450 }
8451 try {
8452 phone.carrierActionReportDefaultNetworkStatus(report);
8453 } catch (Exception e) {
8454 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008455 } finally {
8456 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008457 }
8458 }
8459
8460 /**
fionaxud9622282017-07-17 17:51:30 -07008461 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8462 * @param subId the subscription ID that this action applies to.
8463 * {@hide}
8464 */
8465 @Override
8466 public void carrierActionResetAll(int subId) {
8467 enforceModifyPermission();
8468 final Phone phone = getPhone(subId);
8469 if (phone == null) {
8470 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8471 return;
8472 }
8473 try {
8474 phone.carrierActionResetAll();
8475 } catch (Exception e) {
8476 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8477 }
8478 }
8479
8480 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008481 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8482 * bug report is being generated.
8483 */
8484 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008485 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008486 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8487 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008488 writer.println("Permission Denial: can't dump Phone from pid="
8489 + Binder.getCallingPid()
8490 + ", uid=" + Binder.getCallingUid()
8491 + "without permission "
8492 + android.Manifest.permission.DUMP);
8493 return;
8494 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008495 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008496 }
Jack Yueb89b242016-06-22 13:27:47 -07008497
Brad Ebingerdac2f002018-04-03 15:17:52 -07008498 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008499 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8500 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8501 @NonNull String[] args) {
8502 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8503 this, in.getFileDescriptor(), out.getFileDescriptor(),
8504 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008505 }
8506
Jack Yueb89b242016-06-22 13:27:47 -07008507 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008508 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008509 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008510 * @param reason the reason the data enable change is taking place
8511 * @param enabled True if enabling the data, otherwise disabling.
8512 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008513 */
8514 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008515 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008516 boolean enabled) {
8517 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8518 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8519 try {
8520 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008521 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008522 } catch (SecurityException se) {
8523 enforceModifyPermission();
8524 }
8525 } else {
8526 enforceModifyPermission();
8527 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008528
8529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 Phone phone = getPhone(subId);
8532 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008533 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8534 phone.carrierActionSetMeteredApnsEnabled(enabled);
8535 } else {
8536 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008538 }
8539 } finally {
8540 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008541 }
8542 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008543
8544 /**
8545 * Get Client request stats
8546 * @return List of Client Request Stats
8547 * @hide
8548 */
8549 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008550 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8551 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008552 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008553 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008554 return null;
8555 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008556 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008558 final long identity = Binder.clearCallingIdentity();
8559 try {
8560 if (phone != null) {
8561 return phone.getClientRequestStats();
8562 }
8563
8564 return null;
8565 } finally {
8566 Binder.restoreCallingIdentity(identity);
8567 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008568 }
8569
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008570 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008571 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008572 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008573 }
Jack Yueb4124c2017-02-16 15:32:43 -08008574
8575 /**
Grace Chen70990072017-03-24 17:21:30 -07008576 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008577 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008578 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008579 * @param state State of SIM (power down, power up, pass through)
8580 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8581 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8582 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008583 *
8584 **/
8585 @Override
Grace Chen70990072017-03-24 17:21:30 -07008586 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008587 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008588 Phone phone = PhoneFactory.getPhone(slotIndex);
8589
vagdeviaf9a5b92018-08-15 16:01:53 -07008590 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008592 final long identity = Binder.clearCallingIdentity();
8593 try {
8594 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008595 phone.setSimPowerState(state, null, workSource);
8596 }
8597 } finally {
8598 Binder.restoreCallingIdentity(identity);
8599 }
8600 }
8601
8602 /**
8603 * Set SIM card power state.
8604 *
8605 * @param slotIndex SIM slot id.
8606 * @param state State of SIM (power down, power up, pass through)
8607 * @param callback callback to trigger after success or failure
8608 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8609 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8610 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8611 *
8612 **/
8613 @Override
8614 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8615 IIntegerConsumer callback) {
8616 enforceModifyPermission();
8617 Phone phone = PhoneFactory.getPhone(slotIndex);
8618
8619 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8620
8621 final long identity = Binder.clearCallingIdentity();
8622 try {
8623 if (phone != null) {
8624 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8625 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008626 }
8627 } finally {
8628 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008629 }
8630 }
Shuo Qiandd210312017-04-12 22:11:33 +00008631
Tyler Gunn65d45c22017-06-05 11:22:26 -07008632 private boolean isUssdApiAllowed(int subId) {
8633 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008634 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008635 if (configManager == null) {
8636 return false;
8637 }
8638 PersistableBundle pb = configManager.getConfigForSubId(subId);
8639 if (pb == null) {
8640 return false;
8641 }
8642 return pb.getBoolean(
8643 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8644 }
8645
Shuo Qiandd210312017-04-12 22:11:33 +00008646 /**
8647 * Check if phone is in emergency callback mode
8648 * @return true if phone is in emergency callback mode
8649 * @param subId sub id
8650 */
goneil9c5f4872017-12-05 14:07:56 -08008651 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008652 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008653 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008654 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008655
8656 final long identity = Binder.clearCallingIdentity();
8657 try {
8658 if (phone != null) {
8659 return phone.isInEcm();
8660 } else {
8661 return false;
8662 }
8663 } finally {
8664 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008665 }
8666 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008667
8668 /**
8669 * Get the current signal strength information for the given subscription.
8670 * Because this information is not updated when the device is in a low power state
8671 * it should not be relied-upon to be current.
8672 * @param subId Subscription index
8673 * @return the most recent cached signal strength info from the modem
8674 */
8675 @Override
8676 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008677 final long identity = Binder.clearCallingIdentity();
8678 try {
8679 Phone p = getPhone(subId);
8680 if (p == null) {
8681 return null;
8682 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008684 return p.getSignalStrength();
8685 } finally {
8686 Binder.restoreCallingIdentity(identity);
8687 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008688 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008689
Pengquan Meng77b7f132018-08-22 14:49:57 -07008690 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008691 * Get the current modem radio state for the given slot.
8692 * @param slotIndex slot index.
8693 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008694 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008695 * @return the current radio power state from the modem
8696 */
8697 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008698 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008699 Phone phone = PhoneFactory.getPhone(slotIndex);
8700 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8702 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008703 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8704 }
8705
8706 final long identity = Binder.clearCallingIdentity();
8707 try {
8708 return phone.getRadioPowerState();
8709 } finally {
8710 Binder.restoreCallingIdentity(identity);
8711 }
8712 }
8713 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8714 }
8715
8716 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008717 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8718 *
8719 * <p>Requires one of the following permissions:
8720 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008721 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008722 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8723 * privileges.
8724 *
8725 * @param subId subscription id
8726 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8727 * {@code false}.
8728 */
8729 @Override
8730 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008731 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008732 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008733 try {
8734 mApp.enforceCallingOrSelfPermission(
8735 android.Manifest.permission.ACCESS_NETWORK_STATE,
8736 functionName);
8737 } catch (Exception e) {
8738 mApp.enforceCallingOrSelfPermission(
8739 permission.READ_BASIC_PHONE_STATE, functionName);
8740 }
Shuo Qian093013d2020-08-13 15:42:55 -07008741 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008742 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008743 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008744 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008745
Pengquan Menga1bb6272018-09-06 09:59:22 -07008746 boolean isEnabled = false;
8747 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008748 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008749 Phone phone = getPhone(subId);
8750 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008751 } finally {
8752 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008753 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008754 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008755 }
8756
8757
8758 /**
8759 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8760 *
8761 * <p> Requires permission:
8762 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8763 * privileges.
8764 *
8765 * @param subId subscription id
8766 * @param isEnabled {@code true} means enable, {@code false} means disable.
8767 */
8768 @Override
8769 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8771 mApp, subId, "setDataRoamingEnabled");
8772
Pengquan Menga1bb6272018-09-06 09:59:22 -07008773 final long identity = Binder.clearCallingIdentity();
8774 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008775 Phone phone = getPhone(subId);
8776 if (phone != null) {
8777 phone.setDataRoamingEnabled(isEnabled);
8778 }
8779 } finally {
8780 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008781 }
8782 }
8783
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008784 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008785 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008786 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008787 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008788 mApp, subId, "isManualNetworkSelectionAllowed");
8789
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008790 boolean isAllowed = true;
8791 final long identity = Binder.clearCallingIdentity();
8792 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008793 Phone phone = getPhone(subId);
8794 if (phone != null) {
8795 isAllowed = phone.isCspPlmnEnabled();
8796 }
8797 } finally {
8798 Binder.restoreCallingIdentity(identity);
8799 }
8800 return isAllowed;
8801 }
8802
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008803 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8804 UiccProfile profile = port.getUiccProfile();
8805 if (profile == null ||
8806 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8807 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8808 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008809 }
8810 return true;
8811 }
8812
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008813 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008814 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008815 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008816 mApp.getSystemService(AppOpsManager.class)
8817 .checkPackage(Binder.getCallingUid(), callingPackage);
8818
Jordan Liu1e142fc2019-04-22 15:10:43 -07008819 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008820 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008821 try {
8822 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008823 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008824 } catch (SecurityException e) {
8825 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8826 // has carrier privileges on an active UICC
8827 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8828 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008829 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008830 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008831 }
sandeepjsb6c87872021-09-27 15:34:44 +00008832 // checking compatibility, if calling app's target SDK is T and beyond.
8833 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8834 Binder.getCallingUid())) {
8835 isIccIdAccessRestricted = true;
8836 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008837 final long identity = Binder.clearCallingIdentity();
8838 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008839 UiccController uiccController = UiccController.getInstance();
8840 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008841 if (hasReadPermission) {
8842 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008843 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008844
8845 // Remove private info if the caller doesn't have access
8846 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8847 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008848 //setting the value after compatibility check
8849 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008850 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8851 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008852 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008853 if (card == null) {
8854 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008855 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008856 continue;
8857 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008858 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8859 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008860 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008861 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008862 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008863 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8864 for (UiccPortInfo portInfo : portInfos) {
8865 UiccPort port = uiccController.getUiccPortForSlot(
8866 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8867 if (port == null) {
8868 // assume no access if port is null
8869 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8870 continue;
8871 }
8872 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8873 uiccPortInfos.add(portInfo);
8874 } else {
8875 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8876 }
8877 }
8878 filteredInfos.add(new UiccCardInfo(
8879 cardInfo.isEuicc(),
8880 cardInfo.getCardId(),
8881 null,
8882 cardInfo.getPhysicalSlotIndex(),
8883 cardInfo.isRemovable(),
8884 cardInfo.isMultipleEnabledProfilesSupported(),
8885 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008886 }
8887 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008888 } finally {
8889 Binder.restoreCallingIdentity(identity);
8890 }
8891 }
8892
sandeepjsb6c87872021-09-27 15:34:44 +00008893 /**
8894 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8895 * generally private and require carrier privileges to view.
8896 *
8897 * @hide
8898 */
8899 @NonNull
8900 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8901 List<UiccPortInfo> portinfo = new ArrayList<>();
8902 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8903 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8904 }
8905 return new UiccCardInfo(
8906 cardInfo.isEuicc(),
8907 cardInfo.getCardId(),
8908 null,
8909 cardInfo.getPhysicalSlotIndex(),
8910 cardInfo.isRemovable(),
8911 cardInfo.isMultipleEnabledProfilesSupported(),
8912 portinfo
8913 );
8914 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008915
sandeepjsb6c87872021-09-27 15:34:44 +00008916 /**
8917 * @hide
8918 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8919 * These values are generally private and require carrier privileges to view.
8920 */
8921 @NonNull
8922 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8923 return new UiccPortInfo(
8924 UiccPortInfo.ICCID_REDACTED,
8925 portInfo.getPortIndex(),
8926 portInfo.getLogicalSlotIndex(),
8927 portInfo.isActive()
8928 );
8929 }
8930 @Override
8931 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008932 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008933 mApp.getSystemService(AppOpsManager.class)
8934 .checkPackage(Binder.getCallingUid(), callingPackage);
8935
8936 boolean hasReadPermission = false;
8937 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008938
8939 try {
8940 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8941 hasReadPermission = true;
8942 } catch (SecurityException e) {
8943 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8944 // has carrier privileges on an active UICC
8945 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8946 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8947 hasReadPermission = true;
8948 }
8949 }
8950
8951 // checking compatibility, if calling app's target SDK is T and beyond.
8952 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8953 Binder.getCallingUid())) {
8954 isLogicalSlotAccessRestricted = true;
8955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008956 final long identity = Binder.clearCallingIdentity();
8957 try {
8958 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8959 if (slots == null) {
8960 Rlog.i(LOG_TAG, "slots is null.");
8961 return null;
8962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008963 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8964 for (int i = 0; i < slots.length; i++) {
8965 UiccSlot slot = slots[i];
8966 if (slot == null) {
8967 continue;
8968 }
8969
Jordan Liu7be7e652019-05-06 18:55:02 +00008970 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008971 UiccCard card = slot.getUiccCard();
8972 if (card != null) {
8973 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008974 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008975 cardId = slot.getEid();
8976 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008977 // If cardId is null, use iccId of default port as cardId. Check if has
8978 // read permission otherwise set to null.(card is null which means no
8979 // carrier permission)
8980 cardId = hasReadPermission ? slot.getIccId(
8981 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008983 }
8984
Jordan Liu857451f2019-05-09 16:35:35 -07008985 if (cardId != null) {
8986 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8987 // if cardId is an EID, it's all digits so this is fine
8988 cardId = IccUtils.stripTrailingFs(cardId);
8989 }
8990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008991 int cardState = 0;
8992 switch (slot.getCardState()) {
8993 case CARDSTATE_ABSENT:
8994 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8995 break;
8996 case CARDSTATE_PRESENT:
8997 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8998 break;
8999 case CARDSTATE_ERROR:
9000 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9001 break;
9002 case CARDSTATE_RESTRICTED:
9003 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9004 break;
9005 default:
9006 break;
9007
9008 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009009 List<UiccPortInfo> portInfos = new ArrayList<>();
9010 int[] portIndexes = slot.getPortList();
9011 for (int portIdx : portIndexes) {
9012 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
9013 callingPackage, hasReadPermission));
9014 if (slot.isPortActive(portIdx)) {
9015 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
9016 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
9017 port.getPhoneId(), true));
9018 } else {
9019 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
9020 }
9021 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009022 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009023 slot.isEuicc(),
9024 cardId,
9025 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009026 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009027 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009028 //setting the value after compatibility check
9029 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009030 }
9031 return infos;
9032 } finally {
9033 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009034 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009035 }
9036
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009037 /* Returns null if doesn't have read permission or carrier privilege access. */
9038 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9039 boolean hasReadPermission) {
9040 String iccId = slot.getIccId(portIndex);
9041 if (hasReadPermission) { // if has read permission
9042 return iccId;
9043 } else {
9044 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9045 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9046 // if no read permission, checking carrier privilege access
9047 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9048 return iccId;
9049 }
9050 }
9051 }
9052 // No read permission or carrier privilege access.
9053 return UiccPortInfo.ICCID_REDACTED;
9054 }
9055
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009056 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009057 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009058 public boolean switchSlots(int[] physicalSlots) {
9059 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009060
9061 final long identity = Binder.clearCallingIdentity();
9062 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009063 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9064 for (int i = 0; i < physicalSlots.length; i++) {
9065 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9066 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9067 physicalSlots[i], i));
9068 }
9069 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009070 } finally {
9071 Binder.restoreCallingIdentity(identity);
9072 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009073 }
Jack Yu4c988042018-02-27 15:30:01 -08009074
9075 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009076 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9077 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9078 enforceModifyPermission();
9079
9080 final long identity = Binder.clearCallingIdentity();
9081 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009082 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009083 } finally {
9084 Binder.restoreCallingIdentity(identity);
9085 }
9086 }
9087
9088 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009089 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009090 final long identity = Binder.clearCallingIdentity();
9091 try {
9092 return UiccController.getInstance().getCardIdForDefaultEuicc();
9093 } finally {
9094 Binder.restoreCallingIdentity(identity);
9095 }
9096 }
9097
Pengquan Meng85728fb2018-03-12 16:31:21 -07009098 /**
goneil47ffb6e2018-04-06 15:40:58 -07009099 * A test API to reload the UICC profile.
9100 *
9101 * <p>Requires that the calling app has permission
9102 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9103 * @hide
9104 */
9105 @Override
9106 public void refreshUiccProfile(int subId) {
9107 enforceModifyPermission();
9108
9109 final long identity = Binder.clearCallingIdentity();
9110 try {
9111 Phone phone = getPhone(subId);
9112 if (phone == null) {
9113 return;
9114 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009115 UiccPort uiccPort = phone.getUiccPort();
9116 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009117 return;
9118 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009119 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009120 if (uiccProfile == null) {
9121 return;
9122 }
9123 uiccProfile.refresh();
9124 } finally {
9125 Binder.restoreCallingIdentity(identity);
9126 }
9127 }
9128
9129 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009130 * Returns false if the mobile data is disabled by default, otherwise return true.
9131 */
9132 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009133 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009134 }
9135
9136 /**
9137 * Returns true if the data roaming is enabled by default, i.e the system property
9138 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9139 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9140 */
9141 private boolean getDefaultDataRoamingEnabled(int subId) {
9142 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009143 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009144 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009145 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9146 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9147 return isDataRoamingEnabled;
9148 }
9149
9150 /**
9151 * Returns the default network type for the given {@code subId}, if the default network type is
9152 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9153 */
9154 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009155 List<Integer> list = TelephonyProperties.default_network();
9156 int phoneId = mSubscriptionController.getPhoneId(subId);
9157 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9158 return list.get(phoneId);
9159 }
9160 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009161 }
fionaxua13278b2018-03-21 00:08:13 -07009162
9163 @Override
9164 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009165 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009166 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009167
9168 final long identity = Binder.clearCallingIdentity();
9169 try {
9170 final Phone phone = getPhone(subId);
9171 if (phone == null) {
9172 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9173 return;
9174 }
chen xueaba88a2019-03-15 13:15:10 -07009175 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9176 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009177 if (carrierPrivilegeRules == null) {
9178 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9179 } else {
9180 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9181 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009182 } finally {
9183 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009184 }
fionaxua13278b2018-03-21 00:08:13 -07009185 }
9186
9187 @Override
9188 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009189 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009190
9191 final long identity = Binder.clearCallingIdentity();
9192 try {
9193 final Phone phone = getPhone(subId);
9194 if (phone == null) {
9195 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9196 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9197 }
9198 return phone.getCarrierIdListVersion();
9199 } finally {
9200 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009201 }
fionaxua13278b2018-03-21 00:08:13 -07009202 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009203
9204 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009205 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9206 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009208 mApp, subId, callingPackage, callingFeatureId,
9209 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009210 return -1;
9211 }
9212
9213 final long identity = Binder.clearCallingIdentity();
9214 try {
9215 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9216 } finally {
9217 Binder.restoreCallingIdentity(identity);
9218 }
9219 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009220
9221 @Override
9222 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009223 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009224 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009225 mApp, subId, "getCdmaRoamingMode");
9226
9227 final long identity = Binder.clearCallingIdentity();
9228 try {
9229 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9230 } finally {
9231 Binder.restoreCallingIdentity(identity);
9232 }
9233 }
9234
9235 @Override
9236 public boolean setCdmaRoamingMode(int subId, int mode) {
9237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9238 mApp, subId, "setCdmaRoamingMode");
9239
9240 final long identity = Binder.clearCallingIdentity();
9241 try {
9242 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9243 } finally {
9244 Binder.restoreCallingIdentity(identity);
9245 }
9246 }
9247
9248 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009249 public int getCdmaSubscriptionMode(int subId) {
9250 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009251 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009252 mApp, subId, "getCdmaSubscriptionMode");
9253
9254 final long identity = Binder.clearCallingIdentity();
9255 try {
9256 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9257 } finally {
9258 Binder.restoreCallingIdentity(identity);
9259 }
9260 }
9261
9262 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009263 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9265 mApp, subId, "setCdmaSubscriptionMode");
9266
9267 final long identity = Binder.clearCallingIdentity();
9268 try {
9269 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9270 } finally {
9271 Binder.restoreCallingIdentity(identity);
9272 }
9273 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009274
sqianc5eccab2018-10-19 18:46:41 -07009275 @Override
sqian8c685422019-02-22 15:55:18 -08009276 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009277 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009279 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9280 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009281 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9282 }
9283 final long identity = Binder.clearCallingIdentity();
9284 try {
sqian854d44b2018-12-12 16:48:18 -08009285 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9286 for (Phone phone: PhoneFactory.getPhones()) {
9287 if (phone.getEmergencyNumberTracker() != null
9288 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9289 emergencyNumberListInternal.put(
9290 phone.getSubId(),
9291 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9292 }
sqian11b7a0e2018-12-05 18:48:28 -08009293 }
sqian854d44b2018-12-12 16:48:18 -08009294 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009295 } finally {
9296 Binder.restoreCallingIdentity(identity);
9297 }
sqianc5eccab2018-10-19 18:46:41 -07009298 }
9299
9300 @Override
sqian8c685422019-02-22 15:55:18 -08009301 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009302 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009303 if (!exactMatch) {
9304 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009305 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009306 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009307 }
9308 final long identity = Binder.clearCallingIdentity();
9309 try {
sqian854d44b2018-12-12 16:48:18 -08009310 for (Phone phone: PhoneFactory.getPhones()) {
9311 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009312 && phone.getEmergencyNumberTracker()
9313 .isEmergencyNumber(number, exactMatch)) {
9314 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009315 }
sqian11b7a0e2018-12-05 18:48:28 -08009316 }
9317 return false;
9318 } finally {
9319 Binder.restoreCallingIdentity(identity);
9320 }
9321 }
9322
sqianf4ca7ed2019-01-15 18:32:07 -08009323 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009324 * Start emergency callback mode for GsmCdmaPhone for testing.
9325 */
9326 @Override
9327 public void startEmergencyCallbackMode() {
9328 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9329 "startEmergencyCallbackMode");
9330 enforceModifyPermission();
9331 final long identity = Binder.clearCallingIdentity();
9332 try {
9333 for (Phone phone : PhoneFactory.getPhones()) {
9334 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9335 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9336 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9337 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9338 gsmCdmaPhone.obtainMessage(
9339 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9340 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9341 }
9342 }
9343 } finally {
9344 Binder.restoreCallingIdentity(identity);
9345 }
9346 }
9347
9348 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009349 * Update emergency number list for test mode.
9350 */
9351 @Override
9352 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9353 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9354 "updateEmergencyNumberListTestMode");
9355
9356 final long identity = Binder.clearCallingIdentity();
9357 try {
9358 for (Phone phone: PhoneFactory.getPhones()) {
9359 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9360 if (tracker != null) {
9361 tracker.executeEmergencyNumberTestModeCommand(action, num);
9362 }
9363 }
9364 } finally {
9365 Binder.restoreCallingIdentity(identity);
9366 }
9367 }
9368
9369 /**
9370 * Get the full emergency number list for test mode.
9371 */
9372 @Override
9373 public List<String> getEmergencyNumberListTestMode() {
9374 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9375 "getEmergencyNumberListTestMode");
9376
9377 final long identity = Binder.clearCallingIdentity();
9378 try {
9379 Set<String> emergencyNumbers = new HashSet<>();
9380 for (Phone phone: PhoneFactory.getPhones()) {
9381 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9382 if (tracker != null) {
9383 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9384 emergencyNumbers.add(num.getNumber());
9385 }
9386 }
9387 }
9388 return new ArrayList<>(emergencyNumbers);
9389 } finally {
9390 Binder.restoreCallingIdentity(identity);
9391 }
9392 }
9393
chen xud6b45bd2018-10-30 22:27:10 -07009394 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009395 public int getEmergencyNumberDbVersion(int subId) {
9396 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9397
9398 final long identity = Binder.clearCallingIdentity();
9399 try {
9400 final Phone phone = getPhone(subId);
9401 if (phone == null) {
9402 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9403 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9404 }
9405 return phone.getEmergencyNumberDbVersion();
9406 } finally {
9407 Binder.restoreCallingIdentity(identity);
9408 }
9409 }
9410
9411 @Override
9412 public void notifyOtaEmergencyNumberDbInstalled() {
9413 enforceModifyPermission();
9414
9415 final long identity = Binder.clearCallingIdentity();
9416 try {
9417 for (Phone phone: PhoneFactory.getPhones()) {
9418 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9419 if (tracker != null) {
9420 tracker.updateOtaEmergencyNumberDatabase();
9421 }
9422 }
9423 } finally {
9424 Binder.restoreCallingIdentity(identity);
9425 }
9426 }
9427
9428 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009429 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009430 enforceActiveEmergencySessionPermission();
9431
9432 final long identity = Binder.clearCallingIdentity();
9433 try {
9434 for (Phone phone: PhoneFactory.getPhones()) {
9435 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9436 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009437 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9438 }
9439 }
9440 } finally {
9441 Binder.restoreCallingIdentity(identity);
9442 }
9443 }
9444
9445 @Override
9446 public void resetOtaEmergencyNumberDbFilePath() {
9447 enforceActiveEmergencySessionPermission();
9448
9449 final long identity = Binder.clearCallingIdentity();
9450 try {
9451 for (Phone phone: PhoneFactory.getPhones()) {
9452 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9453 if (tracker != null) {
9454 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009455 }
9456 }
9457 } finally {
9458 Binder.restoreCallingIdentity(identity);
9459 }
9460 }
9461
9462 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009463 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9464 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9465 Phone phone = getPhone(subId);
9466 if (phone == null) {
9467 return null;
9468 }
9469 final long identity = Binder.clearCallingIdentity();
9470 try {
9471 UiccProfile profile = UiccController.getInstance()
9472 .getUiccProfileForPhone(phone.getPhoneId());
9473 if (profile != null) {
9474 return profile.getCertsFromCarrierPrivilegeAccessRules();
9475 }
9476 } finally {
9477 Binder.restoreCallingIdentity(identity);
9478 }
9479 return null;
9480 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009481
9482 /**
9483 * Enable or disable a modem stack.
9484 */
9485 @Override
9486 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9487 enforceModifyPermission();
9488
9489 final long identity = Binder.clearCallingIdentity();
9490 try {
9491 Phone phone = PhoneFactory.getPhone(slotIndex);
9492 if (phone == null) {
9493 return false;
9494 } else {
9495 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9496 }
9497 } finally {
9498 Binder.restoreCallingIdentity(identity);
9499 }
9500 }
Michelecea4cf22018-12-21 15:00:11 -08009501
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009502 /**
9503 * Whether a modem stack is enabled or not.
9504 */
9505 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009506 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9507 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009508 Phone phone = PhoneFactory.getPhone(slotIndex);
9509 if (phone == null) return false;
9510
9511 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009512 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9513 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009514 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9515 }
9516
9517 final long identity = Binder.clearCallingIdentity();
9518 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009519 try {
9520 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9521 } catch (NoSuchElementException ex) {
9522 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9523 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009524 } finally {
9525 Binder.restoreCallingIdentity(identity);
9526 }
9527 }
9528
Michelecea4cf22018-12-21 15:00:11 -08009529 @Override
Michele0ea7d782019-03-19 14:58:42 -07009530 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009531 enforceModifyPermission();
9532
9533 final long identity = Binder.clearCallingIdentity();
9534 try {
9535 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009536 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009537 .commit();
9538 } finally {
9539 Binder.restoreCallingIdentity(identity);
9540 }
9541 }
9542
9543 @Override
Michele0ea7d782019-03-19 14:58:42 -07009544 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009545 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009546 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009547 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9548 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009549 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009550 }
Michelecea4cf22018-12-21 15:00:11 -08009551
9552 final long identity = Binder.clearCallingIdentity();
9553 try {
Michele0ea7d782019-03-19 14:58:42 -07009554 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009555 } finally {
9556 Binder.restoreCallingIdentity(identity);
9557 }
9558 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009559
Michele0ea7d782019-03-19 14:58:42 -07009560 @TelephonyManager.IsMultiSimSupportedResult
9561 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009562 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9563 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9564 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009565 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9566 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009567 }
9568 // Check if the hardware supports multisim functionality. If usage of multisim is not
9569 // supported by the modem, indicate that it is restricted.
9570 PhoneCapability staticCapability =
9571 mPhoneConfigurationManager.getStaticPhoneCapability();
9572 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009573 loge("isMultiSimSupportedInternal: no static configuration available");
9574 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009575 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009576 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009577 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9578 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009579 }
9580 // Check if support of multiple SIMs is restricted by carrier
9581 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009582 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009583 }
9584
Michele0ea7d782019-03-19 14:58:42 -07009585 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009586 }
9587
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009588 /**
9589 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009590 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9591 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9592 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009593 * @param numOfSims number of active sims we want to switch to
9594 */
9595 @Override
9596 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009597 if (numOfSims == 1) {
9598 enforceModifyPermission();
9599 } else {
9600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9601 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9602 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009603 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009604
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009605 try {
Michele30b57b22019-03-01 12:01:14 -08009606 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009607 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009608 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9609 return;
9610 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009611 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9612 } finally {
9613 Binder.restoreCallingIdentity(identity);
9614 }
9615 }
9616
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009617 @Override
9618 public boolean isApplicationOnUicc(int subId, int appType) {
9619 enforceReadPrivilegedPermission("isApplicationOnUicc");
9620 Phone phone = getPhone(subId);
9621 if (phone == null) {
9622 return false;
9623 }
9624 final long identity = Binder.clearCallingIdentity();
9625 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009626 UiccPort uiccPort = phone.getUiccPort();
9627 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009628 return false;
9629 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009630 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009631 if (uiccProfile == null) {
9632 return false;
9633 }
9634 if (TelephonyManager.APPTYPE_SIM <= appType
9635 && appType <= TelephonyManager.APPTYPE_ISIM) {
9636 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9637 }
9638 return false;
9639 } finally {
9640 Binder.restoreCallingIdentity(identity);
9641 }
9642 }
9643
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009644 /**
chen xub4baa772019-04-03 10:23:41 -07009645 * Get whether making changes to modem configurations will trigger reboot.
9646 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009647 */
9648 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009649 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9650 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009652 mApp, subId, callingPackage, callingFeatureId,
9653 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009654 return false;
9655 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009656 final long identity = Binder.clearCallingIdentity();
9657 try {
9658 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9659 } finally {
9660 Binder.restoreCallingIdentity(identity);
9661 }
9662 }
9663
Nathan Harold29f5f052019-02-15 13:41:57 -08009664 private void updateModemStateMetrics() {
9665 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9666 // TODO: check the state for each modem if the api is ready.
9667 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9668 }
9669
Pengquan Meng3889a572019-01-23 11:16:29 -08009670 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009671 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009672 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009673 // Verify that the callingPackage belongs to the calling UID
9674 mApp.getSystemService(AppOpsManager.class)
9675 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009676 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009677 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009678 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009679 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9680 if (slotInfos != null) {
9681 for (int i = 0; i < slotInfos.length; i++) {
9682 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9683 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9684 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9685 portInfo.getLogicalSlotIndex()));
9686 }
9687 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009688 }
9689 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009690 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009691 } finally {
9692 Binder.restoreCallingIdentity(identity);
9693 }
9694 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009695
9696 /**
9697 * Get the IRadio HAL Version
9698 */
9699 @Override
9700 public int getRadioHalVersion() {
9701 Phone phone = getDefaultPhone();
9702 if (phone == null) return -1;
9703 HalVersion hv = phone.getHalVersion();
9704 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9705 return hv.major * 100 + hv.minor;
9706 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009707
9708 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009709 * Get the current calling package name.
9710 * @return the current calling package name
9711 */
9712 @Override
9713 public String getCurrentPackageName() {
9714 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9715 }
9716
9717 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009718 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9719 * corresponding network requests on a subId.
9720 *
9721 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009722 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009723 * 2) APN is un-metered for this subscription, or
9724 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009725 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009726 *
9727 * @return whether data is allowed for a apn type.
9728 *
9729 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009730 */
9731 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009732 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009733 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9734 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009735
9736 // Now that all security checks passes, perform the operation as ourselves.
9737 final long identity = Binder.clearCallingIdentity();
9738 try {
9739 Phone phone = getPhone(subId);
9740 if (phone == null) return false;
9741
Jack Yu41407ee2019-05-13 16:54:09 -07009742 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009743 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9744 } finally {
9745 Binder.restoreCallingIdentity(identity);
9746 }
9747 }
9748
9749 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009750 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009751 enforceReadPrivilegedPermission("isApnMetered");
9752
9753 // Now that all security checks passes, perform the operation as ourselves.
9754 final long identity = Binder.clearCallingIdentity();
9755 try {
9756 Phone phone = getPhone(subId);
9757 if (phone == null) return true; // By default return true.
9758
Jack Yu41407ee2019-05-13 16:54:09 -07009759 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009760 } finally {
9761 Binder.restoreCallingIdentity(identity);
9762 }
9763 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009764
9765 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009766 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9767 int subscriptionId, IBooleanConsumer resultCallback) {
9768 enforceModifyPermission();
9769 long token = Binder.clearCallingIdentity();
9770 try {
9771 Phone phone = getPhone(subscriptionId);
9772 if (phone == null) {
9773 try {
9774 if (resultCallback != null) {
9775 resultCallback.accept(false);
9776 }
9777 } catch (RemoteException e) {
9778 // ignore
9779 }
9780 return;
9781 }
9782 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9783 Pair.create(specifiers, (x) -> {
9784 try {
9785 if (resultCallback != null) {
9786 resultCallback.accept(x);
9787 }
9788 } catch (RemoteException e) {
9789 // ignore
9790 }
9791 });
9792 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9793 } finally {
9794 Binder.restoreCallingIdentity(token);
9795 }
9796 }
9797
9798 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009799 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9800 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009801 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009802 mApp, subId, "getSystemSelectionChannels");
9803 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9804 final long identity = Binder.clearCallingIdentity();
9805 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009806 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9807 if (result instanceof IllegalStateException) {
9808 throw (IllegalStateException) result;
9809 }
9810 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009811 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9812 return specifiers;
9813 } finally {
9814 Binder.restoreCallingIdentity(identity);
9815 }
9816 }
9817
9818 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009819 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009820 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009821 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9822 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9823 if (iccRecords == null) {
9824 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9825 return false;
9826 }
9827 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9828 }
9829
9830 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009831 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9832 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009833 if (callingPackage == null) {
9834 callingPackage = getCurrentPackageName();
9835 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009836 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9837 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009838 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9839 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009840 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9841 }
9842 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9843 Intent intent = new Intent();
9844 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9845 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9846 // Bring up choose default SMS subscription dialog right now
9847 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9848 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9849 mApp.startActivity(intent);
9850 }
chen xud5ca2d52019-05-28 15:20:57 -07009851
9852 @Override
9853 public String getMmsUAProfUrl(int subId) {
9854 //TODO investigate if this API should require proper permission check in R b/133791609
9855 final long identity = Binder.clearCallingIdentity();
9856 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009857 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9858 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9859 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9860 return carrierUAProfUrl;
9861 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009862 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9863 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009864 } finally {
9865 Binder.restoreCallingIdentity(identity);
9866 }
9867 }
9868
9869 @Override
9870 public String getMmsUserAgent(int subId) {
9871 //TODO investigate if this API should require proper permission check in R b/133791609
9872 final long identity = Binder.clearCallingIdentity();
9873 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009874 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9875 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9876 if (!TextUtils.isEmpty(carrierUserAgent)) {
9877 return carrierUserAgent;
9878 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009879 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9880 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009881 } finally {
9882 Binder.restoreCallingIdentity(identity);
9883 }
9884 }
Jack Yub07d4972019-05-28 16:12:25 -07009885
9886 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009887 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9888 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009889
Jack Yub07d4972019-05-28 16:12:25 -07009890 final long identity = Binder.clearCallingIdentity();
9891 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009892 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009893 if (phone == null) return false;
9894
Hall Liua62f5da2020-09-25 10:42:19 -07009895 switch (policy) {
9896 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9897 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9898 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9899 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9900 default:
9901 throw new IllegalArgumentException(policy + " is not a valid policy");
9902 }
Jack Yub07d4972019-05-28 16:12:25 -07009903 } finally {
9904 Binder.restoreCallingIdentity(identity);
9905 }
9906 }
9907
9908 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009909 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009910 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009911 enforceModifyPermission();
9912
changbettyd5c246e2019-12-24 15:40:37 +08009913 final long identity = Binder.clearCallingIdentity();
9914 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009915 Phone phone = getPhone(subscriptionId);
9916 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009917
Hall Liua62f5da2020-09-25 10:42:19 -07009918 switch (policy) {
9919 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9920 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9921 break;
9922 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9923 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9924 break;
9925 default:
9926 throw new IllegalArgumentException(policy + " is not a valid policy");
9927 }
changbettyd5c246e2019-12-24 15:40:37 +08009928 } finally {
9929 Binder.restoreCallingIdentity(identity);
9930 }
9931 }
9932
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009933 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009934 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009935 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9936 * otherwise.
9937 */
9938 @Override
9939 public void setCepEnabled(boolean isCepEnabled) {
9940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9941
9942 final long identity = Binder.clearCallingIdentity();
9943 try {
9944 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9945 for (Phone phone : PhoneFactory.getPhones()) {
9946 Phone defaultPhone = phone.getImsPhone();
9947 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9948 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9949 ImsPhoneCallTracker imsPhoneCallTracker =
9950 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9951 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9952 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9953 + imsPhone.getMsisdn());
9954 }
9955 }
9956 } finally {
9957 Binder.restoreCallingIdentity(identity);
9958 }
9959 }
allenwtsu46dcc572020-01-08 18:24:03 +08009960
9961 /**
9962 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9963 *
9964 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9965 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9966 * before being read.
9967 */
9968 @Override
9969 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9970 isCompressed) {
9971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9972 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009973 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9974 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9975 }
9976 if (!isImsAvailableOnDevice()) {
9977 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9978 "IMS not available on device.");
9979 }
9980
9981 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009982 try {
Hui Wang761a6682020-10-31 05:12:53 +00009983 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9984 } finally {
9985 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009986 }
9987 }
zoey chene02881a2019-12-30 16:11:23 +08009988
9989 @Override
9990 public boolean isIccLockEnabled(int subId) {
9991 enforceReadPrivilegedPermission("isIccLockEnabled");
9992
9993 // Now that all security checks passes, perform the operation as ourselves.
9994 final long identity = Binder.clearCallingIdentity();
9995 try {
9996 Phone phone = getPhone(subId);
9997 if (phone != null && phone.getIccCard() != null) {
9998 return phone.getIccCard().getIccLockEnabled();
9999 } else {
10000 return false;
10001 }
10002 } finally {
10003 Binder.restoreCallingIdentity(identity);
10004 }
10005 }
10006
10007 /**
10008 * Set the ICC pin lock enabled or disabled.
10009 *
10010 * @return an integer representing the status of IccLock enabled or disabled in the following
10011 * three cases:
10012 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10013 * successfully.
10014 * - Positive number and zero for remaining password attempts.
10015 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10016 *
10017 */
10018 @Override
10019 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10020 enforceModifyPermission();
10021
10022 Phone phone = getPhone(subId);
10023 if (phone == null) {
10024 return 0;
10025 }
10026 // Now that all security checks passes, perform the operation as ourselves.
10027 final long identity = Binder.clearCallingIdentity();
10028 try {
10029 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10030 new Pair<Boolean, String>(enabled, password), phone, null);
10031 return attemptsRemaining;
10032
10033 } catch (Exception e) {
10034 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10035 } finally {
10036 Binder.restoreCallingIdentity(identity);
10037 }
10038 return 0;
10039 }
10040
10041 /**
10042 * Change the ICC password used in ICC pin lock.
10043 *
10044 * @return an integer representing the status of IccLock changed in the following three cases:
10045 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10046 * - Positive number and zero for remaining password attempts.
10047 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10048 *
10049 */
10050 @Override
10051 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10052 enforceModifyPermission();
10053
10054 Phone phone = getPhone(subId);
10055 if (phone == null) {
10056 return 0;
10057 }
10058 // Now that all security checks passes, perform the operation as ourselves.
10059 final long identity = Binder.clearCallingIdentity();
10060 try {
10061 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10062 new Pair<String, String>(oldPassword, newPassword), phone, null);
10063 return attemptsRemaining;
10064
10065 } catch (Exception e) {
10066 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10067 } finally {
10068 Binder.restoreCallingIdentity(identity);
10069 }
10070 return 0;
10071 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010072
10073 /**
10074 * Request for receiving user activity notification
10075 */
10076 @Override
10077 public void requestUserActivityNotification() {
10078 if (!mNotifyUserActivity.get()
10079 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10080 mNotifyUserActivity.set(true);
10081 }
10082 }
10083
10084 /**
10085 * Called when userActivity is signalled in the power manager.
10086 * This is safe to call from any thread, with any window manager locks held or not.
10087 */
10088 @Override
10089 public void userActivity() {
10090 // ***************************************
10091 // * Inherited from PhoneWindowManager *
10092 // ***************************************
10093 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10094 // WITH ITS LOCKS HELD.
10095 //
10096 // This code must be VERY careful about the locks
10097 // it acquires.
10098 // In fact, the current code acquires way too many,
10099 // and probably has lurking deadlocks.
10100
10101 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10102 throw new SecurityException("Only the OS may call notifyUserActivity()");
10103 }
10104
10105 if (mNotifyUserActivity.getAndSet(false)) {
10106 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10107 USER_ACTIVITY_NOTIFICATION_DELAY);
10108 }
10109 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010110
10111 @Override
10112 public boolean canConnectTo5GInDsdsMode() {
10113 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10114 }
Jack Yud10cdd42020-09-28 20:28:01 -070010115
10116 @Override
10117 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10118 String callingFeatureId) {
10119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10120 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10121 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10122 }
10123
10124 Phone phone = getPhone(subId);
10125 if (phone == null) {
10126 throw new RuntimeException("phone is not available");
10127 }
10128 // Now that all security checks passes, perform the operation as ourselves.
10129 final long identity = Binder.clearCallingIdentity();
10130 try {
10131 return phone.getEquivalentHomePlmns();
10132 } finally {
10133 Binder.restoreCallingIdentity(identity);
10134 }
10135 }
Daniel Bright59e67312020-11-13 11:49:37 -080010136
10137 @Override
10138 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010139 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10140 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010141 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010142 if (radioInterfaceCapabilities == null) {
10143 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010144 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010145 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010146 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010147
Hui Wang641e81c2020-10-12 12:14:23 -070010148 @Override
10149 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10150 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010151 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10152 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10153 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10154 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10155 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010156 if (DBG) {
10157 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10158 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10159 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10160 }
10161
10162 if (!SubscriptionManager.isValidSubscriptionId(subId)
10163 || appType < TelephonyManager.APPTYPE_UNKNOWN
10164 || appType > TelephonyManager.APPTYPE_ISIM
10165 || nafUrl == null || securityProtocol == null || callback == null) {
10166 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10167 if (callback != null) {
10168 try {
10169 callback.onAuthenticationFailure(
10170 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10171 } catch (RemoteException exception) {
10172 log("Fail to notify onAuthenticationFailure due to " + exception);
10173 }
10174 return;
10175 }
10176 }
10177
10178 final long token = Binder.clearCallingIdentity();
10179 try {
10180 getGbaManager(subId).bootstrapAuthenticationRequest(
10181 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10182 forceBootStrapping, callback));
10183 } finally {
10184 Binder.restoreCallingIdentity(token);
10185 }
10186 }
10187
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010188 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010189 * Attempts to set the radio power state for all phones for thermal reason.
10190 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010191 * requested radio power state will actually be set. See {@link
10192 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10193 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010194 * @param enable {@code true} if trying to turn radio on.
10195 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10196 * false}.
10197 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010198 private boolean setRadioPowerForThermal(boolean enable) {
10199 boolean isPhoneAvailable = false;
10200 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10201 Phone phone = PhoneFactory.getPhone(i);
10202 if (phone != null) {
10203 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10204 isPhoneAvailable = true;
10205 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010206 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010207
10208 // return true if successfully informed the phone object about the thermal radio power
10209 // request.
10210 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010211 }
10212
10213 private int handleDataThrottlingRequest(int subId,
10214 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010215 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10216 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10217 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10218 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10219 throw new IllegalArgumentException("modem does not support data throttling");
10220 }
10221
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010222 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10223 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010224 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010225 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10226 }
10227
10228 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10229
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010230 if (isDataThrottlingSupported) {
10231 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010232 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010233 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10234 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10235 } else if (thermalMitigationResult
10236 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010237 log("Modem likely does not support data throttling on secondary carrier. Data " +
10238 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10239 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010240 }
10241 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010242 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010243
10244 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010245 }
10246
Jack Nudelman644b91a2021-03-12 14:09:48 -080010247 private static List<String> getThermalMitigationAllowlist(Context context) {
10248 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10249 for (String pckg : context.getResources()
10250 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10251 sThermalMitigationAllowlistedPackages.add(pckg);
10252 }
10253 }
10254
10255 return sThermalMitigationAllowlistedPackages;
10256 }
10257
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010258 private boolean isAnyPhoneInEmergencyState() {
10259 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10260 if (tm.isInEmergencyCall()) {
10261 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10262 return true;
10263 }
10264 for (Phone phone : PhoneFactory.getPhones()) {
10265 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10266 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10267 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10268 + phone.isInEcm());
10269 return true;
10270 }
10271 }
10272
10273 return false;
10274 }
10275
Jack Nudelman644b91a2021-03-12 14:09:48 -080010276 /**
10277 * Used by shell commands to add an authorized package name for thermal mitigation.
10278 * @param packageName name of package to be allowlisted
10279 * @param context
10280 */
10281 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10282 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10283 sThermalMitigationAllowlistedPackages.add(packageName);
10284 }
10285
10286 /**
10287 * Used by shell commands to remove an authorized package name for thermal mitigation.
10288 * @param packageName name of package to remove from allowlist
10289 * @param context
10290 */
10291 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10292 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10293 sThermalMitigationAllowlistedPackages.remove(packageName);
10294 }
10295
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010296 /**
10297 * Thermal mitigation request to control functionalities at modem.
10298 *
10299 * @param subId the id of the subscription.
10300 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010301 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010302 *
10303 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10304 */
10305 @Override
10306 @ThermalMitigationResult
10307 public int sendThermalMitigationRequest(
10308 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010309 ThermalMitigationRequest thermalMitigationRequest,
10310 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010311 enforceModifyPermission();
10312
Jack Nudelman644b91a2021-03-12 14:09:48 -080010313 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10314 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10315 .contains(callingPackage)) {
10316 throw new SecurityException("Calling package must be configured in the device config. "
10317 + "calling package: " + callingPackage);
10318 }
10319
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010320 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10321 final long identity = Binder.clearCallingIdentity();
10322
10323 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10324 try {
10325 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10326 switch (thermalMitigationAction) {
10327 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10328 thermalMitigationResult =
10329 handleDataThrottlingRequest(subId,
10330 thermalMitigationRequest.getDataThrottlingRequest());
10331 break;
10332 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10333 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10334 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10335 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10336 }
10337
10338 // Ensure that radio is on. If not able to power on due to phone being
10339 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010340 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010341 thermalMitigationResult =
10342 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10343 break;
10344 }
10345
10346 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10347 false);
10348 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10349 break;
10350 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10351 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10352 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10353 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10354 }
10355
10356 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10357 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010358 Phone phone = getPhone(subId);
10359 if (phone == null) {
10360 thermalMitigationResult =
10361 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10362 break;
10363 }
10364
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010365 TelephonyConnectionService service =
10366 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010367 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010368 Log.e(LOG_TAG, "An emergency call is pending");
10369 thermalMitigationResult =
10370 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10371 break;
10372 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010373 thermalMitigationResult =
10374 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10375 break;
10376 }
10377 } else {
10378 thermalMitigationResult =
10379 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10380 break;
10381 }
10382
10383 // Turn radio off. If not able to power off due to phone being unavailable,
10384 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010385 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010386 thermalMitigationResult =
10387 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10388 break;
10389 }
10390 thermalMitigationResult =
10391 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10392 break;
10393 default:
10394 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10395 + "not exist. Requested action: " + thermalMitigationAction);
10396 }
10397 } catch (IllegalArgumentException e) {
10398 throw e;
10399 } catch (Exception e) {
10400 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10401 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10402 } finally {
10403 Binder.restoreCallingIdentity(identity);
10404 }
10405
10406 if (DBG) {
10407 log("thermalMitigationRequest returning with thermalMitigationResult: "
10408 + thermalMitigationResult);
10409 }
10410
10411 return thermalMitigationResult;
10412 }
Hui Wang641e81c2020-10-12 12:14:23 -070010413
10414 /**
10415 * Set the GbaService Package Name that Telephony will bind to.
10416 *
10417 * @param subId The sim that the GbaService is associated with.
10418 * @param packageName The name of the package to be replaced with.
10419 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10420 */
10421 @Override
10422 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10423 enforceModifyPermission();
10424
10425 final long identity = Binder.clearCallingIdentity();
10426 try {
10427 return getGbaManager(subId).overrideServicePackage(packageName);
10428 } finally {
10429 Binder.restoreCallingIdentity(identity);
10430 }
10431 }
10432
10433 /**
10434 * Return the package name of the currently bound GbaService.
10435 *
10436 * @param subId The sim that the GbaService is associated with.
10437 * @return the package name of the GbaService configuration, null if GBA is not supported.
10438 */
10439 @Override
10440 public String getBoundGbaService(int subId) {
10441 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10442
10443 final long identity = Binder.clearCallingIdentity();
10444 try {
10445 return getGbaManager(subId).getServicePackage();
10446 } finally {
10447 Binder.restoreCallingIdentity(identity);
10448 }
10449 }
10450
10451 /**
10452 * Set the release time for telephony to unbind GbaService.
10453 *
10454 * @param subId The sim that the GbaService is associated with.
10455 * @param interval The release time to unbind GbaService by millisecond.
10456 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10457 */
10458 @Override
10459 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10460 enforceModifyPermission();
10461
10462 final long identity = Binder.clearCallingIdentity();
10463 try {
10464 return getGbaManager(subId).overrideReleaseTime(interval);
10465 } finally {
10466 Binder.restoreCallingIdentity(identity);
10467 }
10468 }
10469
10470 /**
10471 * Return the release time for telephony to unbind GbaService.
10472 *
10473 * @param subId The sim that the GbaService is associated with.
10474 * @return The release time to unbind GbaService by millisecond.
10475 */
10476 @Override
10477 public int getGbaReleaseTime(int subId) {
10478 enforceReadPrivilegedPermission("getGbaReleaseTime");
10479
10480 final long identity = Binder.clearCallingIdentity();
10481 try {
10482 return getGbaManager(subId).getReleaseTime();
10483 } finally {
10484 Binder.restoreCallingIdentity(identity);
10485 }
10486 }
10487
10488 private GbaManager getGbaManager(int subId) {
10489 GbaManager instance = GbaManager.getInstance(subId);
10490 if (instance == null) {
10491 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10492 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10493 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10494 }
10495 return instance;
10496 }
Hui Wang761a6682020-10-31 05:12:53 +000010497
10498 /**
10499 * indicate whether the device and the carrier can support
10500 * RCS VoLTE single registration.
10501 */
10502 @Override
10503 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010504 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10505 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10506 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10507 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010508
10509 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10510 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10511 }
10512
10513 final long identity = Binder.clearCallingIdentity();
10514 try {
10515 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10516 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010517 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10518 if (isCapable != null) {
10519 return isCapable;
10520 }
Hui Wang761a6682020-10-31 05:12:53 +000010521 }
Hui Wang67af90e2021-06-04 16:57:15 -070010522 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10523 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010524 } finally {
10525 Binder.restoreCallingIdentity(identity);
10526 }
10527 }
10528
10529 /**
10530 * Register RCS provisioning callback.
10531 */
10532 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010533 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010534 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010535 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010536 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010537 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10538 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010539
10540 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10541 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10542 }
10543 if (!isImsAvailableOnDevice()) {
10544 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10545 "IMS not available on device.");
10546 }
10547
10548 final long identity = Binder.clearCallingIdentity();
10549 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010550 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010551 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010552 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10553 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010554 }
Hui Wang761a6682020-10-31 05:12:53 +000010555 } finally {
10556 Binder.restoreCallingIdentity(identity);
10557 }
10558 }
10559
10560 /**
10561 * Unregister RCS provisioning callback.
10562 */
10563 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010564 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010565 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010566 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010567 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010568 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10569 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010570
10571 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10572 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10573 }
10574 if (!isImsAvailableOnDevice()) {
10575 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10576 "IMS not available on device.");
10577 }
10578
10579 final long identity = Binder.clearCallingIdentity();
10580 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010581 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010582 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010583 } finally {
10584 Binder.restoreCallingIdentity(identity);
10585 }
10586 }
10587
10588 /**
10589 * trigger RCS reconfiguration.
10590 */
10591 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010592 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10593 "triggerRcsReconfiguration",
10594 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010595
10596 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10597 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10598 }
10599 if (!isImsAvailableOnDevice()) {
10600 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10601 "IMS not available on device.");
10602 }
10603
10604 final long identity = Binder.clearCallingIdentity();
10605 try {
10606 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10607 } finally {
10608 Binder.restoreCallingIdentity(identity);
10609 }
10610 }
10611
10612 /**
10613 * Provide the client configuration parameters of the RCS application.
10614 */
10615 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010616 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10617 "setRcsClientConfiguration",
10618 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010619
10620 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10621 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10622 }
10623 if (!isImsAvailableOnDevice()) {
10624 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10625 "IMS not available on device.");
10626 }
10627
10628 final long identity = Binder.clearCallingIdentity();
10629
10630 try {
10631 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10632 if (configBinder == null) {
10633 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010634 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10635 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010636 } else {
10637 configBinder.setRcsClientConfiguration(rcc);
10638 }
joonhunshin3e154242021-09-17 06:33:39 +000010639
10640 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10641 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010642 } catch (RemoteException e) {
10643 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010644 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10645 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010646 } finally {
10647 Binder.restoreCallingIdentity(identity);
10648 }
10649 }
10650
10651 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010652 * Enables or disables the test mode for RCS VoLTE single registration.
10653 */
10654 @Override
10655 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10656 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10657 "setRcsSingleRegistrationTestModeEnabled");
10658
10659 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10660 }
10661
10662 /**
10663 * Gets the test mode for RCS VoLTE single registration.
10664 */
10665 @Override
10666 public boolean getRcsSingleRegistrationTestModeEnabled() {
10667 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10668 "getRcsSingleRegistrationTestModeEnabled");
10669
10670 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10671 }
10672
10673 /**
Hui Wang761a6682020-10-31 05:12:53 +000010674 * Overrides the config of RCS VoLTE single registration enabled for the device.
10675 */
10676 @Override
10677 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10678 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10679 "setDeviceSingleRegistrationEnabledOverride");
10680 enforceModifyPermission();
10681
10682 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10683 : Boolean.parseBoolean(enabledStr);
10684 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010685 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010686 }
10687
10688 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010689 * Sends a device to device communication message. Only usable via shell.
10690 * @param message message to send.
10691 * @param value message value.
10692 */
10693 @Override
10694 public void sendDeviceToDeviceMessage(int message, int value) {
10695 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010696 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010697 enforceModifyPermission();
10698
10699 final long identity = Binder.clearCallingIdentity();
10700 try {
10701 TelephonyConnectionService service =
10702 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10703 if (service == null) {
10704 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10705 return;
10706 }
10707 service.sendTestDeviceToDeviceMessage(message, value);
10708 } finally {
10709 Binder.restoreCallingIdentity(identity);
10710 }
10711 }
10712
Tyler Gunnbabbda02021-02-10 11:05:02 -080010713 /**
10714 * Sets the specified device to device transport active.
10715 * @param transport The transport to set active.
10716 */
10717 @Override
10718 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10719 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10720 "setActiveDeviceToDeviceTransport");
10721 enforceModifyPermission();
10722
10723 final long identity = Binder.clearCallingIdentity();
10724 try {
10725 TelephonyConnectionService service =
10726 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10727 if (service == null) {
10728 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10729 return;
10730 }
10731 service.setActiveDeviceToDeviceTransport(transport);
10732 } finally {
10733 Binder.restoreCallingIdentity(identity);
10734 }
10735 }
Tyler Gunn92479152021-01-20 16:30:10 -080010736
Tyler Gunnd4339262021-05-03 14:46:49 -070010737 @Override
10738 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10739 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10740 "setDeviceToDeviceForceEnabled");
10741
10742 final long identity = Binder.clearCallingIdentity();
10743 try {
10744 Arrays.stream(PhoneFactory.getPhones()).forEach(
10745 p -> {
10746 Phone thePhone = p.getImsPhone();
10747 if (thePhone != null && thePhone instanceof ImsPhone) {
10748 ImsPhone imsPhone = (ImsPhone) thePhone;
10749 CallTracker tracker = imsPhone.getCallTracker();
10750 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10751 ImsPhoneCallTracker imsPhoneCallTracker =
10752 (ImsPhoneCallTracker) tracker;
10753 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10754 }
10755 }
10756 }
10757 );
10758 } finally {
10759 Binder.restoreCallingIdentity(identity);
10760 }
10761 }
10762
Tyler Gunn92479152021-01-20 16:30:10 -080010763 /**
Hui Wang761a6682020-10-31 05:12:53 +000010764 * Gets the config of RCS VoLTE single registration enabled for the device.
10765 */
10766 @Override
10767 public boolean getDeviceSingleRegistrationEnabled() {
10768 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10769 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10770 }
10771
10772 /**
10773 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10774 */
10775 @Override
10776 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10777 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10778 "setCarrierSingleRegistrationEnabledOverride");
10779 enforceModifyPermission();
10780
10781 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10782 : Boolean.parseBoolean(enabledStr);
10783 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10784 subId, enabled);
10785 }
10786
10787 /**
10788 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10789 */
10790 @Override
10791 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10792 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10793 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10794 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010795
10796 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010797 * Overrides the ims feature validation result
10798 */
10799 @Override
10800 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10801 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10802 "setImsFeatureValidationOverride");
10803
10804 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10805 : Boolean.parseBoolean(enabledStr);
10806 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10807 subId, enabled);
10808 }
10809
10810 /**
10811 * Gets the ims feature validation override value
10812 */
10813 @Override
10814 public boolean getImsFeatureValidationOverride(int subId) {
10815 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10816 "getImsFeatureValidationOverride");
10817 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10818 }
10819
10820 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010821 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10822 * their mobile plan.
10823 */
10824 @Override
10825 public String getMobileProvisioningUrl() {
10826 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10827 final long identity = Binder.clearCallingIdentity();
10828 try {
10829 return getDefaultPhone().getMobileProvisioningUrl();
10830 } finally {
10831 Binder.restoreCallingIdentity(identity);
10832 }
10833 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010834
James.cf Linbcdf8b32021-01-14 16:44:13 +080010835 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010836 * Get the EAB contact from the EAB database.
10837 */
10838 @Override
10839 public String getContactFromEab(String contact) {
10840 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10841 enforceModifyPermission();
10842 final long identity = Binder.clearCallingIdentity();
10843 try {
10844 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10845 } finally {
10846 Binder.restoreCallingIdentity(identity);
10847 }
10848 }
10849
10850 /**
Calvin Pana1434322021-07-01 19:27:01 +080010851 * Get the EAB capability from the EAB database.
10852 */
10853 @Override
10854 public String getCapabilityFromEab(String contact) {
10855 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10856 enforceModifyPermission();
10857 final long identity = Binder.clearCallingIdentity();
10858 try {
10859 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10860 } finally {
10861 Binder.restoreCallingIdentity(identity);
10862 }
10863 }
10864
10865 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010866 * Remove the EAB contacts from the EAB database.
10867 */
10868 @Override
10869 public int removeContactFromEab(int subId, String contacts) {
10870 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10871 enforceModifyPermission();
10872 final long identity = Binder.clearCallingIdentity();
10873 try {
10874 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10875 } finally {
10876 Binder.restoreCallingIdentity(identity);
10877 }
10878 }
10879
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010880 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010881 public boolean getDeviceUceEnabled() {
10882 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10883 final long identity = Binder.clearCallingIdentity();
10884 try {
10885 return mApp.getDeviceUceEnabled();
10886 } finally {
10887 Binder.restoreCallingIdentity(identity);
10888 }
10889 }
10890
10891 @Override
10892 public void setDeviceUceEnabled(boolean isEnabled) {
10893 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10894 final long identity = Binder.clearCallingIdentity();
10895 try {
10896 mApp.setDeviceUceEnabled(isEnabled);
10897 } finally {
10898 Binder.restoreCallingIdentity(identity);
10899 }
10900 }
10901
Brad Ebinger14d467f2021-02-12 06:18:28 +000010902 /**
10903 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10904 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10905 */
10906 // Used for SHELL command only right now.
10907 @Override
10908 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10909 List<String> featureTags) {
10910 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10911 "addUceRegistrationOverrideShell");
10912 final long identity = Binder.clearCallingIdentity();
10913 try {
10914 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10915 new ArraySet<>(featureTags));
10916 } catch (ImsException e) {
10917 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10918 } finally {
10919 Binder.restoreCallingIdentity(identity);
10920 }
10921 }
10922
10923 /**
10924 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10925 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10926 */
10927 // Used for SHELL command only right now.
10928 @Override
10929 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10930 List<String> featureTags) {
10931 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10932 "removeUceRegistrationOverrideShell");
10933 final long identity = Binder.clearCallingIdentity();
10934 try {
10935 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10936 new ArraySet<>(featureTags));
10937 } catch (ImsException e) {
10938 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10939 } finally {
10940 Binder.restoreCallingIdentity(identity);
10941 }
10942 }
10943
10944 /**
10945 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10946 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10947 */
10948 // Used for SHELL command only right now.
10949 @Override
10950 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10951 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10952 "clearUceRegistrationOverrideShell");
10953 final long identity = Binder.clearCallingIdentity();
10954 try {
10955 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10956 } catch (ImsException e) {
10957 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10958 } finally {
10959 Binder.restoreCallingIdentity(identity);
10960 }
10961 }
10962
10963 /**
10964 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10965 */
10966 // Used for SHELL command only right now.
10967 @Override
10968 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10969 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10970 "getLatestRcsContactUceCapabilityShell");
10971 final long identity = Binder.clearCallingIdentity();
10972 try {
10973 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10974 } catch (ImsException e) {
10975 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10976 } finally {
10977 Binder.restoreCallingIdentity(identity);
10978 }
10979 }
10980
10981 /**
10982 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10983 * device does not have an active PUBLISH.
10984 */
10985 // Used for SHELL command only right now.
10986 @Override
10987 public String getLastUcePidfXmlShell(int subId) {
10988 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10989 final long identity = Binder.clearCallingIdentity();
10990 try {
10991 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10992 } catch (ImsException e) {
10993 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10994 } finally {
10995 Binder.restoreCallingIdentity(identity);
10996 }
10997 }
10998
James.cf Line8713a42021-04-29 16:04:26 +080010999 /**
11000 * Remove UCE requests cannot be sent to the network status.
11001 */
11002 // Used for SHELL command only right now.
11003 @Override
11004 public boolean removeUceRequestDisallowedStatus(int subId) {
11005 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11006 final long identity = Binder.clearCallingIdentity();
11007 try {
11008 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11009 } catch (ImsException e) {
11010 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11011 } finally {
11012 Binder.restoreCallingIdentity(identity);
11013 }
11014 }
11015
James.cf Lin18bb9002021-05-25 01:37:38 +080011016 /**
11017 * Remove UCE requests cannot be sent to the network status.
11018 */
11019 // Used for SHELL command only.
11020 @Override
11021 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11022 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11023 final long identity = Binder.clearCallingIdentity();
11024 try {
11025 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11026 } catch (ImsException e) {
11027 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11028 } finally {
11029 Binder.restoreCallingIdentity(identity);
11030 }
11031 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011032
James.cf Lin4b784aa2021-01-31 03:25:15 +080011033 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011034 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11035 String callingPackage) {
11036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11037 mApp, subId, "setSignalStrengthUpdateRequest");
11038
11039 final int callingUid = Binder.getCallingUid();
11040 // Verify that tha callingPackage belongs to the calling UID
11041 mApp.getSystemService(AppOpsManager.class)
11042 .checkPackage(callingUid, callingPackage);
11043
Rambo Wang3607f502021-02-01 21:51:40 -080011044 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011045
11046 final long identity = Binder.clearCallingIdentity();
11047 try {
11048 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11049 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11050
11051 if (result instanceof IllegalStateException) {
11052 throw (IllegalStateException) result;
11053 }
11054 } finally {
11055 Binder.restoreCallingIdentity(identity);
11056 }
11057 }
11058
11059 @Override
11060 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11061 String callingPackage) {
11062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11063 mApp, subId, "clearSignalStrengthUpdateRequest");
11064
11065 final int callingUid = Binder.getCallingUid();
11066 // Verify that tha callingPackage belongs to the calling UID
11067 mApp.getSystemService(AppOpsManager.class)
11068 .checkPackage(callingUid, callingPackage);
11069
11070 final long identity = Binder.clearCallingIdentity();
11071 try {
11072 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11073 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11074
11075 if (result instanceof IllegalStateException) {
11076 throw (IllegalStateException) result;
11077 }
11078 } finally {
11079 Binder.restoreCallingIdentity(identity);
11080 }
11081 }
11082
Rambo Wang3607f502021-02-01 21:51:40 -080011083 private static void validateSignalStrengthUpdateRequest(Context context,
11084 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011085 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11086 // phone/system process do not have further restriction on request
11087 return;
11088 }
11089
11090 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011091 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011092 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011093 context.enforceCallingOrSelfPermission(
11094 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11095 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011096 }
11097
11098 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11099 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11100 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11101 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11102 || info.isEnabled()) {
11103 throw new IllegalArgumentException(
11104 "Only system can set hide fields in SignalThresholdInfo");
11105 }
11106
11107 // Thresholds length for each RAN need in range. This has been validated in
11108 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11109 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11110 final int[] thresholds = info.getThresholds();
11111 Objects.requireNonNull(thresholds);
11112 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11113 || thresholds.length
11114 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11115 throw new IllegalArgumentException(
11116 "thresholds length is out of range: " + thresholds.length);
11117 }
11118 }
11119 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011120
11121 /**
11122 * Gets the current phone capability.
11123 *
11124 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11125 * @return the PhoneCapability which describes the data connection capability of modem.
11126 * It's used to evaluate possible phone config change, for example from single
11127 * SIM device to multi-SIM device.
11128 */
11129 @Override
11130 public PhoneCapability getPhoneCapability() {
11131 enforceReadPrivilegedPermission("getPhoneCapability");
11132 final long identity = Binder.clearCallingIdentity();
11133 try {
11134 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11135 } finally {
11136 Binder.restoreCallingIdentity(identity);
11137 }
11138 }
Michele Berionne5e411512020-11-13 02:36:59 +000011139
11140 /**
11141 * Prepare TelephonyManager for an unattended reboot. The reboot is
11142 * required to be done shortly after the API is invoked.
11143 */
11144 @Override
11145 @TelephonyManager.PrepareUnattendedRebootResult
11146 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011147 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011148 enforceRebootPermission();
11149
11150 final long identity = Binder.clearCallingIdentity();
11151 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011152 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011153 } finally {
11154 Binder.restoreCallingIdentity(identity);
11155 }
11156 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011157
11158 /**
11159 * Request to get the current slicing configuration including URSP rules and
11160 * NSSAIs (configured, allowed and rejected).
11161 *
11162 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11163 */
11164 @Override
11165 public void getSlicingConfig(ResultReceiver callback) {
11166 enforceReadPrivilegedPermission("getSlicingConfig");
11167
11168 final long identity = Binder.clearCallingIdentity();
11169 try {
11170 Phone phone = getDefaultPhone();
11171 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11172 } finally {
11173 Binder.restoreCallingIdentity(identity);
11174 }
11175 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011176
11177 /**
11178 * Register an IMS connection state callback
11179 */
11180 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011181 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11182 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011183 if (feature == ImsFeature.FEATURE_MMTEL) {
11184 // ImsMmTelManager
11185 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11186 TelephonyPermissions
11187 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11188 mApp, subId, "registerImsStateCallback");
11189 } else if (feature == ImsFeature.FEATURE_RCS) {
11190 // ImsRcsManager or SipDelegateManager
11191 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11192 Binder.getCallingUid(), "registerImsStateCallback",
11193 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11194 Manifest.permission.READ_PRECISE_PHONE_STATE,
11195 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11196 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11197 }
11198
11199 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11200 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11201 "IMS not available on device.");
11202 }
11203
11204 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11205 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11206 }
11207
11208 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11209 if (controller == null) {
11210 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11211 "IMS not available on device.");
11212 }
11213
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011214 if (callingPackage == null) {
11215 callingPackage = getCurrentPackageName();
11216 }
11217
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011218 final long token = Binder.clearCallingIdentity();
11219 try {
11220 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011221 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011222 } catch (ImsException e) {
11223 throw new ServiceSpecificException(e.getCode());
11224 } finally {
11225 Binder.restoreCallingIdentity(token);
11226 }
11227 }
11228
11229 /**
11230 * Unregister an IMS connection state callback
11231 */
11232 @Override
11233 public void unregisterImsStateCallback(IImsStateCallback cb) {
11234 final long token = Binder.clearCallingIdentity();
11235 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11236 if (controller == null) {
11237 return;
11238 }
11239 try {
11240 controller.unregisterImsStateCallback(cb);
11241 } finally {
11242 Binder.restoreCallingIdentity(token);
11243 }
11244 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011245
11246 /**
11247 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11248 *
11249 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11250 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11251 * SecurityException.
11252 * If there is current registered network this value will be same as the registered cell
11253 * identity. If the device goes out of service the previous cell identity is cached and
11254 * will be returned. If the cache age of the Cell identity is more than 24 hours
11255 * it will be cleared and null will be returned.
11256 *
11257 */
11258 @Override
11259 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11260 String callingFeatureId) {
11261 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11262 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11263 LocationAccessPolicy.checkLocationPermission(mApp,
11264 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11265 .setCallingPackage(callingPackage)
11266 .setCallingFeatureId(callingFeatureId)
11267 .setCallingPid(Binder.getCallingPid())
11268 .setCallingUid(Binder.getCallingUid())
11269 .setMethod("getLastKnownCellIdentity")
11270 .setLogAsInfo(true)
11271 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11272 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11273 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11274 .build());
11275
11276 boolean hasFinePermission =
11277 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11278 if (!hasFinePermission
11279 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11280 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11281 + "and BIND_CONNECTION_SERVICE permission.");
11282 }
11283
11284 final long identity = Binder.clearCallingIdentity();
11285 try {
11286 Phone phone = getPhone(subId);
11287 if (phone == null) return null;
11288 ServiceStateTracker sst = phone.getServiceStateTracker();
11289 if (sst == null) return null;
11290 return sst.getLastKnownCellIdentity();
11291 } finally {
11292 Binder.restoreCallingIdentity(identity);
11293 }
11294 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011295
11296 @Override
11297 public boolean isUsingNewDataStack() {
11298 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11299 return getDefaultPhone().isUsingNewDataStack();
11300 }
jimsun3b9ccac2021-10-26 15:01:23 +080011301
11302 /**
11303 * Sets the modem service class Name that Telephony will bind to.
11304 *
11305 * @param serviceName The class name of the modem service.
11306 * @return true if the operation is succeed, otherwise false.
11307 */
11308 public boolean setModemService(String serviceName) {
11309 Log.d(LOG_TAG, "setModemService - " + serviceName);
11310 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11312 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11313 "setModemService");
11314 return mPhoneConfigurationManager.setModemService(serviceName);
11315 }
11316
11317 /**
11318 * Return the class name of the currently bounded modem service.
11319 *
11320 * @return the class name of the modem service.
11321 */
11322 public String getModemService() {
11323 String result;
11324 Log.d(LOG_TAG, "getModemService");
11325 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11326 TelephonyPermissions
11327 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11328 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11329 "getModemService");
11330 result = mPhoneConfigurationManager.getModemService();
11331 Log.d(LOG_TAG, "result = " + result);
11332 return result;
11333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011334}