blob: d605bdd035332c6b6e1831089af6f1bdac9e0ca5 [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;
sandeepjsb6c87872021-09-27 15:34:44 +000036import android.compat.annotation.ChangeId;
37import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070038import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070039import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.content.Context;
41import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070042import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070043import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080044import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070075import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080076import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080077import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070078import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080079import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070080import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080081import android.telephony.CellIdentityCdma;
82import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070084import android.telephony.CellInfoGsm;
85import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070086import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080087import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070088import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070089import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070090import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080091import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070092import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080093import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070094import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080095import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080096import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070097import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080098import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800100import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800101import android.telephony.SignalStrengthUpdateRequest;
102import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800103import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800104import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800105import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700106import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700107import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800108import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800109import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800110import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000111import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000112import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000113import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700114import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700115import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800116import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800117import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800118import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700119import android.telephony.gba.GbaAuthRequest;
120import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700121import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000123import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000124import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700125import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700126import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800127import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700128import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800129import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700130import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000131import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700132import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800133import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800134import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800135import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800136import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800138import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700139import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800141import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800142
Andrew Lee312e8172014-10-23 17:01:36 -0700143import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800144import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800145import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800146import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800147import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700149import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700150import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800151import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700152import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800154import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700156import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800157import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800158import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800159import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700160import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000161import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700162import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800163import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800165import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700166import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700167import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700168import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700170import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800171import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700172import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700173import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700174import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700175import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800176import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800177import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700178import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700179import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700180import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800181import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800182import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800183import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700184import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700186import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800187import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700188import com.android.internal.telephony.imsphone.ImsPhone;
189import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000190import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800191import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700192import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700193import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800194import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800196import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700197import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800198import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700199import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000200import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800201import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000202import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800203import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700204import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700205import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800206import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800207import com.android.phone.callcomposer.CallComposerPictureManager;
208import com.android.phone.callcomposer.CallComposerPictureTransfer;
209import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700210import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700211import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800212import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700213import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700214import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800215import com.android.services.telephony.TelecomAccountRegistry;
216import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800217import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800218
Hall Liu82694d52020-12-11 18:22:04 -0800219import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700220import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.io.IOException;
222import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700223import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800225import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000226import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800227import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800228import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800229import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100230import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800231import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700232import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800233import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800234import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800235import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800236import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800237import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238
239/**
240 * Implementation of the ITelephony interface.
241 */
Santos Cordon117fee72014-05-16 17:56:12 -0700242public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243 private static final String LOG_TAG = "PhoneInterfaceManager";
244 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
245 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800246 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247
248 // Message codes used with mMainThreadHandler
249 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700250 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
251 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700252 private static final int CMD_OPEN_CHANNEL = 9;
253 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
254 private static final int CMD_CLOSE_CHANNEL = 11;
255 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800256 private static final int CMD_NV_READ_ITEM = 13;
257 private static final int EVENT_NV_READ_ITEM_DONE = 14;
258 private static final int CMD_NV_WRITE_ITEM = 15;
259 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
260 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
261 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700262 private static final int CMD_RESET_MODEM_CONFIG = 19;
263 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800264 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
265 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800266 private static final int CMD_SEND_ENVELOPE = 25;
267 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000268 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
269 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700270 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
271 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
272 private static final int CMD_EXCHANGE_SIM_IO = 31;
273 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800274 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
275 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700276 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
277 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700278 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
279 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700280 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
281 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
282 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
283 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700284 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
285 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
286 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
287 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700288 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800289 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
290 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000291 private static final int CMD_SWITCH_SLOTS = 50;
292 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700293 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
294 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
295 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
296 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
297 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
298 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
299 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
300 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700301 private static final int CMD_GET_ALL_CELL_INFO = 60;
302 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
303 private static final int CMD_GET_CELL_LOCATION = 62;
304 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700305 private static final int CMD_MODEM_REBOOT = 64;
306 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700307 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
308 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800309 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
310 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700311 private static final int CMD_GET_MODEM_STATUS = 70;
312 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700313 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
314 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700315 private static final int CMD_ERASE_MODEM_CONFIG = 74;
316 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800317 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
318 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
319 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
320 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800321 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
322 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800323 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800324 private static final int CMD_GET_CALL_FORWARDING = 83;
325 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
326 private static final int CMD_SET_CALL_FORWARDING = 85;
327 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
328 private static final int CMD_GET_CALL_WAITING = 87;
329 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
330 private static final int CMD_SET_CALL_WAITING = 89;
331 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700332 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
333 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
334 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
335 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700336 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
337 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800338 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
339 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800340 private static final int CMD_SET_DATA_THROTTLING = 99;
341 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800342 private static final int CMD_SET_SIM_POWER = 101;
343 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800344 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
345 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
346 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
347 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800348 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
349 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000350 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800351 private static final int CMD_GET_SLICING_CONFIG = 110;
352 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800353 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700354 private static final int CMD_ENABLE_VONR = 113;
355 private static final int EVENT_ENABLE_VONR_DONE = 114;
356 private static final int CMD_IS_VONR_ENABLED = 115;
357 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800359 // Parameters of select command.
360 private static final int SELECT_COMMAND = 0xA4;
361 private static final int SELECT_P1 = 0x04;
362 private static final int SELECT_P2 = 0;
363 private static final int SELECT_P3 = 0x10;
364
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 /** The singleton instance. */
366 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800367 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368
Wink Saville3ab207e2014-11-20 13:07:20 -0800369 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800370 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800371 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700372 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700374 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800376 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700378 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800379 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380
Peter Wangdafb9ac2020-01-15 14:13:38 -0800381 /** User Activity */
382 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800383 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
384
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700385 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
386
Derek Tan97ebb422014-09-05 16:55:38 -0700387 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
388 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800389 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800390 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700391
Michelecea4cf22018-12-21 15:00:11 -0800392 // String to store multi SIM allowed
393 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
394
Derek Tan740e1672017-06-27 14:56:27 -0700395 // The AID of ISD-R.
396 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
397
yinxub1bed742017-04-17 11:45:04 -0700398 private NetworkScanRequestTracker mNetworkScanRequestTracker;
399
David Kelly5e06a7f2018-03-12 14:10:59 +0000400 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
401 private static final int MANUFACTURER_CODE_LENGTH = 8;
402
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800403 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800404 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800405
Derek Tan89e89d42014-07-08 17:00:10 -0700406 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700407 * Experiment flag to enable erase modem config on reset network, default value is false
408 */
409 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
410 "reset_network_erase_modem_config_enabled";
411
Rambo Wang0f050d82021-02-12 11:43:36 -0800412 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjsb6c87872021-09-27 15:34:44 +0000413 /**
414 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
415 * one ICCID active at the same time.
416 * Apps should use below API signatures if targeting SDK is T and beyond.
417 *
418 * @hide
419 */
420 @ChangeId
421 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
422 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800423
Naina Nallurid63128d2019-09-17 14:10:30 -0700424 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700425 * A request object to use for transmitting data to an ICC.
426 */
427 private static final class IccAPDUArgument {
428 public int channel, cla, command, p1, p2, p3;
429 public String data;
430
431 public IccAPDUArgument(int channel, int cla, int command,
432 int p1, int p2, int p3, String data) {
433 this.channel = channel;
434 this.cla = cla;
435 this.command = command;
436 this.p1 = p1;
437 this.p2 = p2;
438 this.p3 = p3;
439 this.data = data;
440 }
441 }
442
443 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700444 * A request object to use for transmitting data to an ICC.
445 */
446 private static final class ManualNetworkSelectionArgument {
447 public OperatorInfo operatorInfo;
448 public boolean persistSelection;
449
450 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
451 this.operatorInfo = operatorInfo;
452 this.persistSelection = persistSelection;
453 }
454 }
455
456 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
458 * request after sending. The main thread will notify the request when it is complete.
459 */
460 private static final class MainThreadRequest {
461 /** The argument to use for the request */
462 public Object argument;
463 /** The result of the request that is run on the main thread */
464 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800465 // The subscriber id that this request applies to. Defaults to
466 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
467 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468
Nathan Harold92bed182018-10-12 18:16:49 -0700469 // In cases where subId is unavailable, the caller needs to specify the phone.
470 public Phone phone;
471
vagdeviaf9a5b92018-08-15 16:01:53 -0700472 public WorkSource workSource;
473
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 public MainThreadRequest(Object argument) {
475 this.argument = argument;
476 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800477
Nathan Harold92bed182018-10-12 18:16:49 -0700478 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
479 this.argument = argument;
480 if (phone != null) {
481 this.phone = phone;
482 }
483 this.workSource = workSource;
484 }
485
vagdeviaf9a5b92018-08-15 16:01:53 -0700486 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800487 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800488 if (subId != null) {
489 this.subId = subId;
490 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700491 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700493 }
494
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800495 private static final class IncomingThirdPartyCallArgs {
496 public final ComponentName component;
497 public final String callId;
498 public final String callerDisplayName;
499
500 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
501 String callerDisplayName) {
502 this.component = component;
503 this.callId = callId;
504 this.callerDisplayName = callerDisplayName;
505 }
506 }
507
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700508 /**
509 * A handler that processes messages on the main thread in the phone process. Since many
510 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
511 * inbound binder threads to the main thread in the phone process. The Binder thread
512 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
513 * on, which will be notified when the operation completes and will contain the result of the
514 * request.
515 *
516 * <p>If a MainThreadRequest object is provided in the msg.obj field,
517 * note that request.result must be set to something non-null for the calling thread to
518 * unblock.
519 */
520 private final class MainThreadHandler extends Handler {
521 @Override
522 public void handleMessage(Message msg) {
523 MainThreadRequest request;
524 Message onCompleted;
525 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000526 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800528 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529
530 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 case CMD_HANDLE_USSD_REQUEST: {
532 request = (MainThreadRequest) msg.obj;
533 final Phone phone = getPhoneFromRequest(request);
534 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
535 String ussdRequest = ussdObject.first;
536 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700537
Pengquan Menga1bb6272018-09-06 09:59:22 -0700538 if (!isUssdApiAllowed(request.subId)) {
539 // Carrier does not support use of this API, return failure.
540 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
541 UssdResponse response = new UssdResponse(ussdRequest, null);
542 Bundle returnData = new Bundle();
543 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
544 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700545
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 request.result = true;
547 notifyRequester(request);
548 return;
549 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700550
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 try {
552 request.result = phone != null
553 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
554 } catch (CallStateException cse) {
555 request.result = false;
556 }
557 // Wake up the requesting thread
558 notifyRequester(request);
559 break;
pkanwar32d516d2016-10-14 19:37:38 -0700560 }
561
Yorke Lee716f67e2015-06-17 15:39:16 -0700562 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700563 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700564 final Phone phone = getPhoneFromRequest(request);
565 request.result = phone != null ?
566 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
567 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700568 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700570 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700572
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000576 uiccPort = getUiccPortFromRequest(request);
577 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700578 loge("iccTransmitApduLogicalChannel: No UICC");
579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
583 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000584 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 iccArgument.channel, iccArgument.cla, iccArgument.command,
586 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 ar = (AsyncResult) msg.obj;
593 request = (MainThreadRequest) ar.userObj;
594 if (ar.exception == null && ar.result != null) {
595 request.result = ar.result;
596 } else {
597 request.result = new IccIoResult(0x6F, 0, (byte[])null);
598 if (ar.result == null) {
599 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800600 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800602 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 } else {
604 loge("iccTransmitApduLogicalChannel: Unknown exception");
605 }
606 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700607 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 break;
609
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
611 request = (MainThreadRequest) msg.obj;
612 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000613 uiccPort = getUiccPortFromRequest(request);
614 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 loge("iccTransmitApduBasicChannel: No UICC");
616 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 } else {
619 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
620 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000621 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
623 iccArgument.p3, iccArgument.data, onCompleted);
624 }
625 break;
626
627 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
628 ar = (AsyncResult) msg.obj;
629 request = (MainThreadRequest) ar.userObj;
630 if (ar.exception == null && ar.result != null) {
631 request.result = ar.result;
632 } else {
633 request.result = new IccIoResult(0x6F, 0, (byte[])null);
634 if (ar.result == null) {
635 loge("iccTransmitApduBasicChannel: Empty response");
636 } else if (ar.exception instanceof CommandException) {
637 loge("iccTransmitApduBasicChannel: CommandException: " +
638 ar.exception);
639 } else {
640 loge("iccTransmitApduBasicChannel: Unknown exception");
641 }
642 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 break;
645
646 case CMD_EXCHANGE_SIM_IO:
647 request = (MainThreadRequest) msg.obj;
648 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000649 uiccPort = getUiccPortFromRequest(request);
650 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 loge("iccExchangeSimIO: No UICC");
652 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 } else {
655 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
656 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000657 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
659 iccArgument.data, onCompleted);
660 }
661 break;
662
663 case EVENT_EXCHANGE_SIM_IO_DONE:
664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
666 if (ar.exception == null && ar.result != null) {
667 request.result = ar.result;
668 } else {
669 request.result = new IccIoResult(0x6f, 0, (byte[])null);
670 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 break;
673
Derek Tan4d5e5c12014-02-04 11:54:58 -0800674 case CMD_SEND_ENVELOPE:
675 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000676 uiccPort = getUiccPortFromRequest(request);
677 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700678 loge("sendEnvelopeWithStatus: No UICC");
679 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700680 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 } else {
682 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000683 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800685 break;
686
687 case EVENT_SEND_ENVELOPE_DONE:
688 ar = (AsyncResult) msg.obj;
689 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700690 if (ar.exception == null && ar.result != null) {
691 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800692 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700693 request.result = new IccIoResult(0x6F, 0, (byte[])null);
694 if (ar.result == null) {
695 loge("sendEnvelopeWithStatus: Empty response");
696 } else if (ar.exception instanceof CommandException) {
697 loge("sendEnvelopeWithStatus: CommandException: " +
698 ar.exception);
699 } else {
700 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
701 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800702 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700703 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800704 break;
705
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 case CMD_OPEN_CHANNEL:
707 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000708 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800709 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000710 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700711 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800712 request.result = new IccOpenLogicalChannelResponse(-1,
713 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700715 } else {
716 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000717 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800718 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 break;
721
722 case EVENT_OPEN_CHANNEL_DONE:
723 ar = (AsyncResult) msg.obj;
724 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700725 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700726 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700727 int[] result = (int[]) ar.result;
728 int channelId = result[0];
729 byte[] selectResponse = null;
730 if (result.length > 1) {
731 selectResponse = new byte[result.length - 1];
732 for (int i = 1; i < result.length; ++i) {
733 selectResponse[i - 1] = (byte) result[i];
734 }
735 }
736 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700737 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 if (ar.result == null) {
740 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 if (ar.exception != null) {
743 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
744 }
745
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700746 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700747 if (ar.exception instanceof CommandException) {
748 CommandException.Error error =
749 ((CommandException) (ar.exception)).getCommandError();
750 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700751 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700752 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700753 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700754 }
755 }
756 openChannelResp = new IccOpenLogicalChannelResponse(
757 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700759 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 break;
762
763 case CMD_CLOSE_CHANNEL:
764 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000765 uiccPort = getUiccPortFromRequest(request);
766 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700767 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900768 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700770 } else {
771 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000772 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700773 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700774 break;
775
776 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800777 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
778 break;
779
780 case CMD_NV_READ_ITEM:
781 request = (MainThreadRequest) msg.obj;
782 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800783 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
784 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800785 break;
786
787 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 ar = (AsyncResult) msg.obj;
789 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800790 if (ar.exception == null && ar.result != null) {
791 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700792 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800793 request.result = "";
794 if (ar.result == null) {
795 loge("nvReadItem: Empty response");
796 } else if (ar.exception instanceof CommandException) {
797 loge("nvReadItem: CommandException: " +
798 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800800 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700801 }
802 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700803 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700804 break;
805
Jake Hambye994d462014-02-03 13:10:13 -0800806 case CMD_NV_WRITE_ITEM:
807 request = (MainThreadRequest) msg.obj;
808 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
809 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800810 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700811 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800812 break;
813
814 case EVENT_NV_WRITE_ITEM_DONE:
815 handleNullReturnEvent(msg, "nvWriteItem");
816 break;
817
818 case CMD_NV_WRITE_CDMA_PRL:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800821 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800822 break;
823
824 case EVENT_NV_WRITE_CDMA_PRL_DONE:
825 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
826 break;
827
chen xu6dac5ab2018-10-26 17:39:23 -0700828 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800829 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700830 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800831 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800832 break;
833
chen xu6dac5ab2018-10-26 17:39:23 -0700834 case EVENT_RESET_MODEM_CONFIG_DONE:
835 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800836 break;
837
Sooraj Sasindran37444802020-08-11 10:40:43 -0700838 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
839 request = (MainThreadRequest) msg.obj;
840 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
841 request);
842 Phone phone = getPhoneFromRequest(request);
843 if (phone != null) {
844 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
845 } else {
846 loge("isNRDualConnectivityEnabled: No phone object");
847 request.result = false;
848 notifyRequester(request);
849 }
850 break;
851 }
852
853 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
854 ar = (AsyncResult) msg.obj;
855 request = (MainThreadRequest) ar.userObj;
856 if (ar.exception == null && ar.result != null) {
857 request.result = ar.result;
858 } else {
859 // request.result must be set to something non-null
860 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700861 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700862 request.result = ar.result;
863 } else {
864 request.result = false;
865 }
866 if (ar.result == null) {
867 loge("isNRDualConnectivityEnabled: Empty response");
868 } else if (ar.exception instanceof CommandException) {
869 loge("isNRDualConnectivityEnabled: CommandException: "
870 + ar.exception);
871 } else {
872 loge("isNRDualConnectivityEnabled: Unknown exception");
873 }
874 }
875 notifyRequester(request);
876 break;
877
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700878 case CMD_IS_VONR_ENABLED: {
879 request = (MainThreadRequest) msg.obj;
880 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
881 request);
882 Phone phone = getPhoneFromRequest(request);
883 if (phone != null) {
884 phone.isVoNrEnabled(onCompleted, request.workSource);
885 } else {
886 loge("isVoNrEnabled: No phone object");
887 request.result = false;
888 notifyRequester(request);
889 }
890 break;
891 }
892
893 case EVENT_IS_VONR_ENABLED_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
899 // request.result must be set to something non-null
900 // for the calling thread to unblock
901 if (ar.result != null) {
902 request.result = ar.result;
903 } else {
904 request.result = false;
905 }
906 if (ar.result == null) {
907 loge("isVoNrEnabled: Empty response");
908 } else if (ar.exception instanceof CommandException) {
909 loge("isVoNrEnabled: CommandException: "
910 + ar.exception);
911 } else {
912 loge("isVoNrEnabled: Unknown exception");
913 }
914 }
915 notifyRequester(request);
916 break;
917
Sooraj Sasindran37444802020-08-11 10:40:43 -0700918 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
919 request = (MainThreadRequest) msg.obj;
920 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
921 Phone phone = getPhoneFromRequest(request);
922 if (phone != null) {
923 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
924 request.workSource);
925 } else {
926 loge("enableNrDualConnectivity: No phone object");
927 request.result =
928 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
929 notifyRequester(request);
930 }
931 break;
932 }
933
934 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
935 ar = (AsyncResult) msg.obj;
936 request = (MainThreadRequest) ar.userObj;
937 if (ar.exception == null) {
938 request.result =
939 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
940 } else {
941 request.result =
942 TelephonyManager
943 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
944 if (ar.exception instanceof CommandException) {
945 CommandException.Error error =
946 ((CommandException) (ar.exception)).getCommandError();
947 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
948 request.result =
949 TelephonyManager
950 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000951 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
952 request.result =
953 TelephonyManager
954 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700955 }
956 loge("enableNrDualConnectivity" + ": CommandException: "
957 + ar.exception);
958 } else {
959 loge("enableNrDualConnectivity" + ": Unknown exception");
960 }
961 }
962 notifyRequester(request);
963 break;
964 }
965
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700966 case CMD_ENABLE_VONR: {
967 request = (MainThreadRequest) msg.obj;
968 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
969 Phone phone = getPhoneFromRequest(request);
970 if (phone != null) {
971 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
972 request.workSource);
973 } else {
974 loge("setVoNrEnabled: No phone object");
975 request.result =
976 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
977 notifyRequester(request);
978 }
979 break;
980 }
981
982 case EVENT_ENABLE_VONR_DONE: {
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 if (ar.exception == null) {
986 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
987 } else {
988 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
989 if (ar.exception instanceof CommandException) {
990 CommandException.Error error =
991 ((CommandException) (ar.exception)).getCommandError();
992 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
993 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
994 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
995 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
996 } else {
997 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
998 }
999 loge("setVoNrEnabled" + ": CommandException: "
1000 + ar.exception);
1001 } else {
1002 loge("setVoNrEnabled" + ": Unknown exception");
1003 }
1004 }
1005 notifyRequester(request);
1006 break;
1007 }
1008
SongFerngWang3ef3e072020-12-21 16:41:52 +08001009 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001010 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001011 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1012 request);
1013 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001014 break;
1015
SongFerngWang3ef3e072020-12-21 16:41:52 +08001016 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001017 ar = (AsyncResult) msg.obj;
1018 request = (MainThreadRequest) ar.userObj;
1019 if (ar.exception == null && ar.result != null) {
1020 request.result = ar.result; // Integer
1021 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301022 // request.result must be set to something non-null
1023 // for the calling thread to unblock
1024 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001025 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001026 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001027 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001028 loge("getAllowedNetworkTypesBitmask: CommandException: "
1029 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001030 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001031 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001032 }
1033 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001034 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001035 break;
1036
SongFerngWang3ef3e072020-12-21 16:41:52 +08001037 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001038 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001039 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1040 request);
1041 Pair<Integer, Long> reasonWithNetworkTypes =
1042 (Pair<Integer, Long>) request.argument;
1043 getPhoneFromRequest(request).setAllowedNetworkTypes(
1044 reasonWithNetworkTypes.first,
1045 reasonWithNetworkTypes.second,
1046 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001047 break;
1048
SongFerngWang3ef3e072020-12-21 16:41:52 +08001049 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1050 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001051 break;
1052
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001053 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1054 request = (MainThreadRequest)msg.obj;
1055 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001056 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001057 break;
1058
1059 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1060 ar = (AsyncResult)msg.obj;
1061 request = (MainThreadRequest)ar.userObj;
1062 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001063 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001064 break;
1065
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001066 case CMD_SET_VOICEMAIL_NUMBER:
1067 request = (MainThreadRequest) msg.obj;
1068 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1069 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001070 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1071 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001072 break;
1073
1074 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1075 handleNullReturnEvent(msg, "setVoicemailNumber");
1076 break;
1077
Stuart Scott54788802015-03-30 13:18:01 -07001078 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1079 request = (MainThreadRequest) msg.obj;
1080 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1081 request);
1082 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1083 break;
1084
1085 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1086 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1087 break;
1088
Shishir Agrawal302c8692015-06-19 13:49:39 -07001089 case CMD_PERFORM_NETWORK_SCAN:
1090 request = (MainThreadRequest) msg.obj;
1091 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1092 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1093 break;
1094
Hall Liu27d24262020-09-18 19:04:59 -07001095 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001096 request = (MainThreadRequest) msg.obj;
1097 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001098 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1099 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1100 request.argument;
1101 int callForwardingReason = args.first;
1102 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001103 break;
Hall Liu27d24262020-09-18 19:04:59 -07001104 }
1105 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001106 ar = (AsyncResult) msg.obj;
1107 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001108 TelephonyManager.CallForwardingInfoCallback callback =
1109 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1110 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001111 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001112 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001113 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1114 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1115 // Service Class is a bit mask per 3gpp 27.007. Search for
1116 // any service for voice call.
1117 if ((callForwardInfo.serviceClass
1118 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001119 callForwardingInfo = new CallForwardingInfo(
1120 callForwardInfo.status
1121 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001122 callForwardInfo.reason,
1123 callForwardInfo.number,
1124 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001125 break;
1126 }
1127 }
1128 // Didn't find a call forward info for voice call.
1129 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001130 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1131 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001132 }
Hall Liu27d24262020-09-18 19:04:59 -07001133 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001134 } else {
1135 if (ar.result == null) {
1136 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1137 }
1138 if (ar.exception != null) {
1139 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1140 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001141 int errorCode = TelephonyManager
1142 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001143 if (ar.exception instanceof CommandException) {
1144 CommandException.Error error =
1145 ((CommandException) (ar.exception)).getCommandError();
1146 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001147 errorCode = TelephonyManager
1148 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001149 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001150 errorCode = TelephonyManager
1151 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001152 }
1153 }
Hall Liu27d24262020-09-18 19:04:59 -07001154 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001155 }
Shuo Qian4a594052020-01-23 11:59:30 -08001156 break;
Hall Liu27d24262020-09-18 19:04:59 -07001157 }
Shuo Qian4a594052020-01-23 11:59:30 -08001158
Hall Liu27d24262020-09-18 19:04:59 -07001159 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001160 request = (MainThreadRequest) msg.obj;
1161 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001162 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001163 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001164 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1165 request.argument).first;
1166 request.phone.setCallForwardingOption(
1167 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001168 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001169 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001170 callForwardingInfoToSet.getReason(),
1171 callForwardingInfoToSet.getNumber(),
1172 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1173 break;
Hall Liu27d24262020-09-18 19:04:59 -07001174 }
Shuo Qian4a594052020-01-23 11:59:30 -08001175
Hall Liu27d24262020-09-18 19:04:59 -07001176 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001177 ar = (AsyncResult) msg.obj;
1178 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001179 Consumer<Integer> callback =
1180 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1181 request.argument).second;
1182 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001183 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001184 int errorCode = TelephonyManager.CallForwardingInfoCallback
1185 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001186 if (ar.exception instanceof CommandException) {
1187 CommandException.Error error =
1188 ((CommandException) (ar.exception)).getCommandError();
1189 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001190 errorCode = TelephonyManager.CallForwardingInfoCallback
1191 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001192 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001193 errorCode = TelephonyManager.CallForwardingInfoCallback
1194 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001195 }
1196 }
1197 callback.accept(errorCode);
1198 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001199 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001200 }
Shuo Qian4a594052020-01-23 11:59:30 -08001201 break;
Hall Liu27d24262020-09-18 19:04:59 -07001202 }
Shuo Qian4a594052020-01-23 11:59:30 -08001203
Hall Liu27d24262020-09-18 19:04:59 -07001204 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001205 request = (MainThreadRequest) msg.obj;
1206 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1207 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1208 break;
Hall Liu27d24262020-09-18 19:04:59 -07001209 }
Shuo Qian4a594052020-01-23 11:59:30 -08001210
Hall Liu27d24262020-09-18 19:04:59 -07001211 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001212 ar = (AsyncResult) msg.obj;
1213 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001214 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001215 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1216 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001217 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001218 // Service Class is a bit mask per 3gpp 27.007.
1219 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001220 if (callForwardResults.length > 1
1221 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001222 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001223 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001224 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1225 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001226 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001227 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001228 }
1229 } else {
1230 if (ar.result == null) {
1231 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1232 }
1233 if (ar.exception != null) {
1234 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1235 }
1236 if (ar.exception instanceof CommandException) {
1237 CommandException.Error error =
1238 ((CommandException) (ar.exception)).getCommandError();
1239 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1240 callForwardingStatus =
1241 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1242 }
1243 }
1244 }
Hall Liu27d24262020-09-18 19:04:59 -07001245 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001246 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 CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001252 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1253 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001254 break;
Hall Liu27d24262020-09-18 19:04:59 -07001255 }
Shuo Qian4a594052020-01-23 11:59:30 -08001256
Hall Liu27d24262020-09-18 19:04:59 -07001257 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001258 ar = (AsyncResult) msg.obj;
1259 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001260 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1261 Consumer<Integer> callback =
1262 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1263 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001264 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001265 if (ar.exception instanceof CommandException) {
1266 CommandException.Error error =
1267 ((CommandException) (ar.exception)).getCommandError();
1268 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1269 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1270 } else {
1271 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1272 }
1273 } else {
1274 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1275 }
1276 } else {
1277 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1278 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001279 }
Shuo Qian4a594052020-01-23 11:59:30 -08001280 break;
Hall Liu27d24262020-09-18 19:04:59 -07001281 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001282 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1283 ar = (AsyncResult) msg.obj;
1284 request = (MainThreadRequest) ar.userObj;
1285 CellNetworkScanResult cellScanResult;
1286 if (ar.exception == null && ar.result != null) {
1287 cellScanResult = new CellNetworkScanResult(
1288 CellNetworkScanResult.STATUS_SUCCESS,
1289 (List<OperatorInfo>) ar.result);
1290 } else {
1291 if (ar.result == null) {
1292 loge("getCellNetworkScanResults: Empty response");
1293 }
1294 if (ar.exception != null) {
1295 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1296 }
1297 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1298 if (ar.exception instanceof CommandException) {
1299 CommandException.Error error =
1300 ((CommandException) (ar.exception)).getCommandError();
1301 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1302 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1303 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1304 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1305 }
1306 }
1307 cellScanResult = new CellNetworkScanResult(errorCode, null);
1308 }
1309 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001310 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001311 break;
1312
1313 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1314 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001315 ManualNetworkSelectionArgument selArg =
1316 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001317 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1318 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001319 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1320 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001321 break;
1322
1323 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001324 ar = (AsyncResult) msg.obj;
1325 request = (MainThreadRequest) ar.userObj;
1326 if (ar.exception == null) {
1327 request.result = true;
1328 } else {
1329 request.result = false;
1330 loge("setNetworkSelectionModeManual " + ar.exception);
1331 }
1332 notifyRequester(request);
1333 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001334 break;
1335
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001336 case CMD_GET_MODEM_ACTIVITY_INFO:
1337 request = (MainThreadRequest) msg.obj;
1338 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001339 if (defaultPhone != null) {
1340 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001341 } else {
1342 ResultReceiver result = (ResultReceiver) request.argument;
1343 Bundle bundle = new Bundle();
1344 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001345 new ModemActivityInfo(0, 0, 0,
1346 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001347 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001348 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001349 break;
1350
Hall Liud0f208c2020-10-14 16:54:44 -07001351 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001352 ar = (AsyncResult) msg.obj;
1353 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001354 ResultReceiver result = (ResultReceiver) request.argument;
1355
Hall Liud0f208c2020-10-14 16:54:44 -07001356 ModemActivityInfo ret = null;
1357 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001358 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001359 // Update the last modem activity info and the result of the request.
1360 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1361 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001362 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001363 int[] txTimeMs = info.getTransmitTimeMillis();
1364 int[] lastModemTxTimeMs = mLastModemActivityInfo
1365 .getTransmitTimeMillis();
1366 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1367 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1368 }
Hall Liu49656c02020-10-09 19:00:11 -07001369 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001370 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1371 + mLastModemActivityInfo.getSleepTimeMillis());
1372 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1373 + mLastModemActivityInfo.getIdleTimeMillis());
1374 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1375 mLastModemActivityInfo.setReceiveTimeMillis(
1376 info.getReceiveTimeMillis()
1377 + mLastModemActivityInfo.getReceiveTimeMillis());
1378 }
Hall Liu49656c02020-10-09 19:00:11 -07001379 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001380 mLastModemActivityInfo.getSleepTimeMillis(),
1381 mLastModemActivityInfo.getIdleTimeMillis(),
1382 mLastModemActivityInfo.getTransmitTimeMillis(),
1383 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001384 } else {
1385 if (ar.result == null) {
1386 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001387 error = TelephonyManager.ModemActivityInfoException
1388 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001389 } else if (ar.exception instanceof CommandException) {
1390 loge("queryModemActivityInfo: CommandException: " +
1391 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001392 error = TelephonyManager.ModemActivityInfoException
1393 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001394 } else {
1395 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001396 error = TelephonyManager.ModemActivityInfoException
1397 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001398 }
1399 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001400 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001401 if (ret != null) {
1402 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1403 } else {
1404 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1405 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001406 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001407 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001408 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001409 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001410
Meng Wang1a7c35a2016-05-05 20:56:15 -07001411 case CMD_SET_ALLOWED_CARRIERS:
1412 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001413 CarrierRestrictionRules argument =
1414 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001415 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001416 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001417 break;
1418
1419 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1420 ar = (AsyncResult) msg.obj;
1421 request = (MainThreadRequest) ar.userObj;
1422 if (ar.exception == null && ar.result != null) {
1423 request.result = ar.result;
1424 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001425 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1426 if (ar.exception instanceof CommandException) {
1427 loge("setAllowedCarriers: CommandException: " + ar.exception);
1428 CommandException.Error error =
1429 ((CommandException) (ar.exception)).getCommandError();
1430 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1431 request.result =
1432 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1433 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001434 } else {
1435 loge("setAllowedCarriers: Unknown exception");
1436 }
1437 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001438 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001439 break;
1440
1441 case CMD_GET_ALLOWED_CARRIERS:
1442 request = (MainThreadRequest) msg.obj;
1443 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001444 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001445 break;
1446
1447 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null && ar.result != null) {
1451 request.result = ar.result;
1452 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001453 request.result = new IllegalStateException(
1454 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001455 if (ar.result == null) {
1456 loge("getAllowedCarriers: Empty response");
1457 } else if (ar.exception instanceof CommandException) {
1458 loge("getAllowedCarriers: CommandException: " +
1459 ar.exception);
1460 } else {
1461 loge("getAllowedCarriers: Unknown exception");
1462 }
1463 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001464 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001465 break;
1466
Nathan Haroldb3014052017-01-25 15:57:32 -08001467 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1468 ar = (AsyncResult) msg.obj;
1469 request = (MainThreadRequest) ar.userObj;
1470 if (ar.exception == null && ar.result != null) {
1471 request.result = ar.result;
1472 } else {
1473 request.result = new IllegalArgumentException(
1474 "Failed to retrieve Forbidden Plmns");
1475 if (ar.result == null) {
1476 loge("getForbiddenPlmns: Empty response");
1477 } else {
1478 loge("getForbiddenPlmns: Unknown exception");
1479 }
1480 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001481 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001482 break;
1483
1484 case CMD_GET_FORBIDDEN_PLMNS:
1485 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001486 uiccPort = getUiccPortFromRequest(request);
1487 if (uiccPort == null) {
1488 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001489 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001490 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001491 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001492 break;
1493 }
1494 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001495 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001496 if (uiccApp == null) {
1497 loge("getForbiddenPlmns() no app with specified type -- "
1498 + appType);
1499 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001500 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001501 break;
1502 } else {
1503 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1504 + " specified type -- " + appType);
1505 }
1506 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1507 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1508 onCompleted);
1509 break;
1510
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001511 case CMD_SWITCH_SLOTS:
1512 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001513 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001514 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001515 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001516 break;
1517
1518 case EVENT_SWITCH_SLOTS_DONE:
1519 ar = (AsyncResult) msg.obj;
1520 request = (MainThreadRequest) ar.userObj;
1521 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001522 notifyRequester(request);
1523 break;
1524 case CMD_GET_NETWORK_SELECTION_MODE:
1525 request = (MainThreadRequest) msg.obj;
1526 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1527 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1528 break;
1529
1530 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1531 ar = (AsyncResult) msg.obj;
1532 request = (MainThreadRequest) ar.userObj;
1533 if (ar.exception != null) {
1534 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1535 } else {
1536 int mode = ((int[]) ar.result)[0];
1537 if (mode == 0) {
1538 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1539 } else {
1540 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1541 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001542 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001543 notifyRequester(request);
1544 break;
1545 case CMD_GET_CDMA_ROAMING_MODE:
1546 request = (MainThreadRequest) msg.obj;
1547 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1548 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1549 break;
1550 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1551 ar = (AsyncResult) msg.obj;
1552 request = (MainThreadRequest) ar.userObj;
1553 if (ar.exception != null) {
1554 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1555 } else {
1556 request.result = ((int[]) ar.result)[0];
1557 }
1558 notifyRequester(request);
1559 break;
1560 case CMD_SET_CDMA_ROAMING_MODE:
1561 request = (MainThreadRequest) msg.obj;
1562 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1563 int mode = (int) request.argument;
1564 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1565 break;
1566 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1567 ar = (AsyncResult) msg.obj;
1568 request = (MainThreadRequest) ar.userObj;
1569 request.result = ar.exception == null;
1570 notifyRequester(request);
1571 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001572 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1573 request = (MainThreadRequest) msg.obj;
1574 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1575 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1576 break;
1577 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
1580 if (ar.exception != null) {
1581 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1582 } else {
1583 request.result = ((int[]) ar.result)[0];
1584 }
1585 notifyRequester(request);
1586 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001587 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1588 request = (MainThreadRequest) msg.obj;
1589 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1590 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001591 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1592 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001593 break;
1594 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1595 ar = (AsyncResult) msg.obj;
1596 request = (MainThreadRequest) ar.userObj;
1597 request.result = ar.exception == null;
1598 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001599 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001600 case CMD_GET_ALL_CELL_INFO:
1601 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001602 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001603 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001604 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001605 case EVENT_GET_ALL_CELL_INFO_DONE:
1606 ar = (AsyncResult) msg.obj;
1607 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001608 // If a timeout occurs, the response will be null
1609 request.result = (ar.exception == null && ar.result != null)
1610 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001611 synchronized (request) {
1612 request.notifyAll();
1613 }
1614 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001615 case CMD_REQUEST_CELL_INFO_UPDATE:
1616 request = (MainThreadRequest) msg.obj;
1617 request.phone.requestCellInfoUpdate(request.workSource,
1618 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1619 break;
1620 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1621 ar = (AsyncResult) msg.obj;
1622 request = (MainThreadRequest) ar.userObj;
1623 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1624 try {
1625 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001626 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001627 cb.onError(
1628 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1629 ar.exception.getClass().getName(),
1630 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001631 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001632 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001633 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001634 } else {
1635 // use the result as returned
1636 cb.onCellInfo((List<CellInfo>) ar.result);
1637 }
1638 } catch (RemoteException re) {
1639 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1640 }
1641 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001642 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001643 request = (MainThreadRequest) msg.obj;
1644 WorkSource ws = (WorkSource) request.argument;
1645 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001646 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001647 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001648 }
1649 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001650 ar = (AsyncResult) msg.obj;
1651 request = (MainThreadRequest) ar.userObj;
1652 if (ar.exception == null) {
1653 request.result = ar.result;
1654 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001655 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001656 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001657 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 }
1659
1660 synchronized (request) {
1661 request.notifyAll();
1662 }
1663 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001664 }
chen xu6dac5ab2018-10-26 17:39:23 -07001665 case CMD_MODEM_REBOOT:
1666 request = (MainThreadRequest) msg.obj;
1667 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001668 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001669 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001670 case EVENT_CMD_MODEM_REBOOT_DONE:
1671 handleNullReturnEvent(msg, "rebootModem");
1672 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001673 case CMD_REQUEST_ENABLE_MODEM:
1674 request = (MainThreadRequest) msg.obj;
1675 boolean enable = (boolean) request.argument;
1676 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001677 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001678 PhoneConfigurationManager.getInstance()
1679 .enablePhone(request.phone, enable, onCompleted);
1680 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001681 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001685 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001686 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001687 if ((boolean) request.result) {
1688 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1689 updateModemStateMetrics();
1690 } else {
1691 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1692 + ar.exception);
1693 }
1694 notifyRequester(request);
1695 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001696 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001697 case CMD_GET_MODEM_STATUS:
1698 request = (MainThreadRequest) msg.obj;
1699 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1700 PhoneConfigurationManager.getInstance()
1701 .getPhoneStatusFromModem(request.phone, onCompleted);
1702 break;
1703 case EVENT_GET_MODEM_STATUS_DONE:
1704 ar = (AsyncResult) msg.obj;
1705 request = (MainThreadRequest) ar.userObj;
1706 int id = request.phone.getPhoneId();
1707 if (ar.exception == null && ar.result != null) {
1708 request.result = ar.result;
1709 //update the cache as modem status has changed
1710 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1711 (boolean) request.result);
1712 } else {
1713 // Return true if modem status cannot be retrieved. For most cases,
1714 // modem status is on. And for older version modems, GET_MODEM_STATUS
1715 // and disable modem are not supported. Modem is always on.
1716 // TODO: this should be fixed in R to support a third
1717 // status UNKNOWN b/131631629
1718 request.result = true;
1719 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1720 + ar.exception);
1721 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001722 notifyRequester(request);
1723 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001724 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1725 request = (MainThreadRequest) msg.obj;
1726 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1727 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1728 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1729 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1730 break;
1731 }
1732 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1736 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1737 args.second.accept(ar.exception == null);
1738 notifyRequester(request);
1739 break;
1740 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001741 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1742 request = (MainThreadRequest) msg.obj;
1743 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1744 Phone phone = getPhoneFromRequest(request);
1745 if (phone != null) {
1746 phone.getSystemSelectionChannels(onCompleted);
1747 } else {
1748 loge("getSystemSelectionChannels: No phone object");
1749 request.result = new ArrayList<RadioAccessSpecifier>();
1750 notifyRequester(request);
1751 }
1752 break;
1753 }
1754 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1755 ar = (AsyncResult) msg.obj;
1756 request = (MainThreadRequest) ar.userObj;
1757 if (ar.exception == null && ar.result != null) {
1758 request.result = ar.result;
1759 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001760 request.result = new IllegalStateException(
1761 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001762 if (ar.result == null) {
1763 loge("getSystemSelectionChannels: Empty response");
1764 } else {
1765 loge("getSystemSelectionChannels: Unknown exception");
1766 }
1767 }
1768 notifyRequester(request);
1769 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001770 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1771 ar = (AsyncResult) msg.obj;
1772 request = (MainThreadRequest) ar.userObj;
1773 if (ar.exception == null && ar.result != null) {
1774 request.result = ar.result;
1775 } else {
1776 request.result = -1;
1777 loge("Failed to set Forbidden Plmns");
1778 if (ar.result == null) {
1779 loge("setForbidenPlmns: Empty response");
1780 } else if (ar.exception != null) {
1781 loge("setForbiddenPlmns: Exception: " + ar.exception);
1782 request.result = -1;
1783 } else {
1784 loge("setForbiddenPlmns: Unknown exception");
1785 }
1786 }
1787 notifyRequester(request);
1788 break;
1789 case CMD_SET_FORBIDDEN_PLMNS:
1790 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001791 uiccPort = getUiccPortFromRequest(request);
1792 if (uiccPort == null) {
1793 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001794 request.result = -1;
1795 notifyRequester(request);
1796 break;
1797 }
1798 Pair<Integer, List<String>> setFplmnsArgs =
1799 (Pair<Integer, List<String>>) request.argument;
1800 appType = setFplmnsArgs.first;
1801 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001802 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001803 if (uiccApp == null) {
1804 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1805 request.result = -1;
1806 loge("Failed to get UICC App");
1807 notifyRequester(request);
1808 } else {
1809 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1810 ((SIMRecords) uiccApp.getIccRecords())
1811 .setForbiddenPlmns(onCompleted, fplmns);
1812 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001813 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001814 case CMD_ERASE_MODEM_CONFIG:
1815 request = (MainThreadRequest) msg.obj;
1816 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1817 defaultPhone.eraseModemConfig(onCompleted);
1818 break;
1819 case EVENT_ERASE_MODEM_CONFIG_DONE:
1820 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001821 break;
zoey chene02881a2019-12-30 16:11:23 +08001822
Kai Shif70f46f2021-03-03 13:59:46 -08001823 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1824 request = (MainThreadRequest) msg.obj;
1825 request.result = defaultPhone.eraseDataInSharedPreferences();
1826 notifyRequester(request);
1827 break;
1828
zoey chene02881a2019-12-30 16:11:23 +08001829 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1830 request = (MainThreadRequest) msg.obj;
1831 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1832 Pair<String, String> changed = (Pair<String, String>) request.argument;
1833 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1834 changed.first, changed.second, onCompleted);
1835 break;
1836 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1837 ar = (AsyncResult) msg.obj;
1838 request = (MainThreadRequest) ar.userObj;
1839 if (ar.exception == null) {
1840 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001841 // If the operation is successful, update the PIN storage
1842 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1843 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001844 UiccController.getInstance().getPinStorage()
1845 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001846 } else {
1847 request.result = msg.arg1;
1848 }
1849 notifyRequester(request);
1850 break;
1851
Michele Berionne5e411512020-11-13 02:36:59 +00001852 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001853 request = (MainThreadRequest) msg.obj;
1854 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1855 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1856 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1857 enabled.first, enabled.second, onCompleted);
1858 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001859 }
zoey chene02881a2019-12-30 16:11:23 +08001860 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1861 ar = (AsyncResult) msg.obj;
1862 request = (MainThreadRequest) ar.userObj;
1863 if (ar.exception == null) {
1864 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001865 // If the operation is successful, update the PIN storage
1866 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1867 int phoneId = getPhoneFromRequest(request).getPhoneId();
1868 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001869 UiccController.getInstance().getPinStorage()
1870 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001871 } else {
1872 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1873 }
zoey chene02881a2019-12-30 16:11:23 +08001874 } else {
1875 request.result = msg.arg1;
1876 }
Michele Berionne5e411512020-11-13 02:36:59 +00001877
1878
zoey chene02881a2019-12-30 16:11:23 +08001879 notifyRequester(request);
1880 break;
1881
Peter Wangdafb9ac2020-01-15 14:13:38 -08001882 case MSG_NOTIFY_USER_ACTIVITY:
1883 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001884 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001885 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1886 getDefaultPhone().getContext().sendBroadcastAsUser(
1887 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1888 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001889
1890 case CMD_SET_DATA_THROTTLING: {
1891 request = (MainThreadRequest) msg.obj;
1892 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1893 DataThrottlingRequest dataThrottlingRequest =
1894 (DataThrottlingRequest) request.argument;
1895 Phone phone = getPhoneFromRequest(request);
1896 if (phone != null) {
1897 phone.setDataThrottling(onCompleted,
1898 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1899 dataThrottlingRequest.getCompletionDurationMillis());
1900 } else {
1901 loge("setDataThrottling: No phone object");
1902 request.result =
1903 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1904 notifyRequester(request);
1905 }
1906
1907 break;
1908 }
1909 case EVENT_SET_DATA_THROTTLING_DONE:
1910 ar = (AsyncResult) msg.obj;
1911 request = (MainThreadRequest) ar.userObj;
1912
1913 if (ar.exception == null) {
1914 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1915 } else if (ar.exception instanceof CommandException) {
1916 loge("setDataThrottling: CommandException: " + ar.exception);
1917 CommandException.Error error =
1918 ((CommandException) (ar.exception)).getCommandError();
1919
1920 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1921 request.result = TelephonyManager
1922 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1923 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1924 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001925 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1926 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001927 } else {
1928 request.result =
1929 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1930 }
1931 } else {
1932 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1933 }
1934 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1935 notifyRequester(request);
1936 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001937
1938 case CMD_SET_SIM_POWER: {
1939 request = (MainThreadRequest) msg.obj;
1940 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1941 request = (MainThreadRequest) msg.obj;
1942 int stateToSet =
1943 ((Pair<Integer, IIntegerConsumer>)
1944 request.argument).first;
1945 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1946 break;
1947 }
1948 case EVENT_SET_SIM_POWER_DONE: {
1949 ar = (AsyncResult) msg.obj;
1950 request = (MainThreadRequest) ar.userObj;
1951 IIntegerConsumer callback =
1952 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1953 if (ar.exception != null) {
1954 loge("setSimPower exception: " + ar.exception);
1955 int errorCode = TelephonyManager.CallForwardingInfoCallback
1956 .RESULT_ERROR_UNKNOWN;
1957 if (ar.exception instanceof CommandException) {
1958 CommandException.Error error =
1959 ((CommandException) (ar.exception)).getCommandError();
1960 if (error == CommandException.Error.SIM_ERR) {
1961 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1962 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1963 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1964 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1965 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1966 } else {
1967 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1968 }
1969 }
1970 try {
1971 callback.accept(errorCode);
1972 } catch (RemoteException e) {
1973 // Ignore if the remote process is no longer available to call back.
1974 Log.w(LOG_TAG, "setSimPower: callback not available.");
1975 }
1976 } else {
1977 try {
1978 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1979 } catch (RemoteException e) {
1980 // Ignore if the remote process is no longer available to call back.
1981 Log.w(LOG_TAG, "setSimPower: callback not available.");
1982 }
1983 }
1984 break;
1985 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001986 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1987 request = (MainThreadRequest) msg.obj;
1988
1989 final Phone phone = getPhoneFromRequest(request);
1990 if (phone == null || phone.getServiceStateTracker() == null) {
1991 request.result = new IllegalStateException("Phone or SST is null");
1992 notifyRequester(request);
1993 break;
1994 }
1995
1996 Pair<Integer, SignalStrengthUpdateRequest> pair =
1997 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1998 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1999 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002000 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002001 request.subId, pair.first /*callingUid*/,
2002 pair.second /*request*/, onCompleted);
2003 break;
2004 }
2005 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2006 ar = (AsyncResult) msg.obj;
2007 request = (MainThreadRequest) ar.userObj;
2008 // request.result will be the exception of ar if present, true otherwise.
2009 // Be cautious not to leave result null which will wait() forever
2010 request.result = ar.exception != null ? ar.exception : true;
2011 notifyRequester(request);
2012 break;
2013 }
2014 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2015 request = (MainThreadRequest) msg.obj;
2016
2017 Phone phone = getPhoneFromRequest(request);
2018 if (phone == null || phone.getServiceStateTracker() == null) {
2019 request.result = new IllegalStateException("Phone or SST is null");
2020 notifyRequester(request);
2021 break;
2022 }
2023
2024 Pair<Integer, SignalStrengthUpdateRequest> pair =
2025 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2026 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2027 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002028 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002029 request.subId, pair.first /*callingUid*/,
2030 pair.second /*request*/, onCompleted);
2031 break;
2032 }
2033 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2034 ar = (AsyncResult) msg.obj;
2035 request = (MainThreadRequest) ar.userObj;
2036 request.result = ar.exception != null ? ar.exception : true;
2037 notifyRequester(request);
2038 break;
2039 }
Jordan Liu109698e2020-11-24 14:50:34 -08002040
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002041 case CMD_GET_SLICING_CONFIG: {
2042 request = (MainThreadRequest) msg.obj;
2043 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2044 request.phone.getSlicingConfig(onCompleted);
2045 break;
2046 }
2047 case EVENT_GET_SLICING_CONFIG_DONE: {
2048 ar = (AsyncResult) msg.obj;
2049 request = (MainThreadRequest) ar.userObj;
2050 ResultReceiver result = (ResultReceiver) request.argument;
2051
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002052 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002053 Bundle bundle = new Bundle();
2054 int resultCode = 0;
2055 if (ar.exception != null) {
2056 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2057 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002058 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002059 } else if (ar.result == null) {
2060 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002061 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002062 } else {
2063 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002064 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2065 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002066 }
2067
2068 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002069 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002070 }
2071 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2072 result.send(resultCode, bundle);
2073 notifyRequester(request);
2074 break;
2075 }
2076
Michele Berionne5e411512020-11-13 02:36:59 +00002077 case CMD_PREPARE_UNATTENDED_REBOOT:
2078 request = (MainThreadRequest) msg.obj;
2079 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002080 UiccController.getInstance().getPinStorage()
2081 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002082 notifyRequester(request);
2083 break;
2084
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 default:
2086 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2087 break;
2088 }
2089 }
Jake Hambye994d462014-02-03 13:10:13 -08002090
Pengquan Menga1bb6272018-09-06 09:59:22 -07002091 private void notifyRequester(MainThreadRequest request) {
2092 synchronized (request) {
2093 request.notifyAll();
2094 }
2095 }
2096
Jake Hambye994d462014-02-03 13:10:13 -08002097 private void handleNullReturnEvent(Message msg, String command) {
2098 AsyncResult ar = (AsyncResult) msg.obj;
2099 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2100 if (ar.exception == null) {
2101 request.result = true;
2102 } else {
2103 request.result = false;
2104 if (ar.exception instanceof CommandException) {
2105 loge(command + ": CommandException: " + ar.exception);
2106 } else {
2107 loge(command + ": Unknown exception");
2108 }
2109 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002110 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113
2114 /**
2115 * Posts the specified command to be executed on the main thread,
2116 * waits for the request to complete, and returns the result.
2117 * @see #sendRequestAsync
2118 */
2119 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002120 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2121 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002122 }
2123
2124 /**
2125 * Posts the specified command to be executed on the main thread,
2126 * waits for the request to complete, and returns the result.
2127 * @see #sendRequestAsync
2128 */
2129 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2130 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002131 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002132 }
2133
2134 /**
2135 * Posts the specified command to be executed on the main thread,
2136 * waits for the request to complete, and returns the result.
2137 * @see #sendRequestAsync
2138 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002139 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002140 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2141 }
2142
2143 /**
2144 * Posts the specified command to be executed on the main thread,
2145 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2146 * if not timeout or null otherwise.
2147 * @see #sendRequestAsync
2148 */
2149 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2150 long timeoutInMs) {
2151 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002152 }
2153
2154 /**
2155 * Posts the specified command to be executed on the main thread,
2156 * waits for the request to complete, and returns the result.
2157 * @see #sendRequestAsync
2158 */
Nathan Harold92bed182018-10-12 18:16:49 -07002159 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002160 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002161 }
2162
2163 /**
2164 * Posts the specified command to be executed on the main thread,
2165 * waits for the request to complete, and returns the result.
2166 * @see #sendRequestAsync
2167 */
2168 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002169 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2170 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002171 }
2172
2173 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002174 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2175 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2176 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002177 * @see #sendRequestAsync
2178 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002179 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2180 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2182 throw new RuntimeException("This method will deadlock if called from the main thread.");
2183 }
2184
Nathan Harold92bed182018-10-12 18:16:49 -07002185 MainThreadRequest request = null;
2186 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2187 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2188 } else if (phone != null) {
2189 request = new MainThreadRequest(argument, phone, workSource);
2190 } else {
2191 request = new MainThreadRequest(argument, subId, workSource);
2192 }
2193
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 Message msg = mMainThreadHandler.obtainMessage(command, request);
2195 msg.sendToTarget();
2196
Rambo Wang0f050d82021-02-12 11:43:36 -08002197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002199 if (timeoutInMs >= 0) {
2200 // Wait for at least timeoutInMs before returning null request result
2201 long now = SystemClock.elapsedRealtime();
2202 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002203 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002204 try {
2205 request.wait(deadline - now);
2206 } catch (InterruptedException e) {
2207 // Do nothing, go back and check if request is completed or timeout
2208 } finally {
2209 now = SystemClock.elapsedRealtime();
2210 }
2211 }
2212 } else {
2213 // Wait for the request to complete
2214 while (request.result == null) {
2215 try {
2216 request.wait();
2217 } catch (InterruptedException e) {
2218 // Do nothing, go back and wait until the request is complete
2219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221 }
2222 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002223 if (request.result == null) {
2224 Log.wtf(LOG_TAG,
2225 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 return request.result;
2228 }
2229
2230 /**
2231 * Asynchronous ("fire and forget") version of sendRequest():
2232 * Posts the specified command to be executed on the main thread, and
2233 * returns immediately.
2234 * @see #sendRequest
2235 */
2236 private void sendRequestAsync(int command) {
2237 mMainThreadHandler.sendEmptyMessage(command);
2238 }
2239
2240 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002241 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002242 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002243 */
2244 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002245 sendRequestAsync(command, argument, null, null);
2246 }
2247
2248 /**
2249 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2250 * @see {@link #sendRequest(int,Object)}
2251 */
2252 private void sendRequestAsync(
2253 int command, Object argument, Phone phone, WorkSource workSource) {
2254 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002255 Message msg = mMainThreadHandler.obtainMessage(command, request);
2256 msg.sendToTarget();
2257 }
2258
2259 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 * Initialize the singleton PhoneInterfaceManager instance.
2261 * This is only done once, at startup, from PhoneApp.onCreate().
2262 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002263 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 synchronized (PhoneInterfaceManager.class) {
2265 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002266 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 } else {
2268 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2269 }
2270 return sInstance;
2271 }
2272 }
2273
2274 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002275 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002278 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002279 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002281 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002283 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002284 mTelephonySharedPreferences =
2285 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002286 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002287 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002288 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002289 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002290
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 publish();
2292 }
2293
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002294 private Phone getDefaultPhone() {
2295 Phone thePhone = getPhone(getDefaultSubscription());
2296 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2297 }
2298
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 private void publish() {
2300 if (DBG) log("publish: " + this);
2301
Peter Wangc035ce42020-01-08 21:00:22 -08002302 TelephonyFrameworkInitializer
2303 .getTelephonyServiceManager()
2304 .getTelephonyServiceRegisterer()
2305 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 }
2307
Stuart Scott584921c2015-01-15 17:10:34 -08002308 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002309 if (request.phone != null) {
2310 return request.phone;
2311 } else {
2312 return getPhoneFromSubId(request.subId);
2313 }
2314 }
2315
2316 private Phone getPhoneFromSubId(int subId) {
2317 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2318 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002319 }
2320
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002321 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002322 Phone phone = getPhoneFromRequest(request);
2323 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002324 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002325 }
2326
Wink Saville36469e72014-06-11 15:17:00 -07002327 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002328 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002329 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331
Kai Shif70f46f2021-03-03 13:59:46 -08002332 private void sendEraseModemConfig(@NonNull Phone phone) {
2333 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2334 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2335 }
2336
2337 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2338 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2339 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002340 }
2341
Peter Wang44b186e2020-01-13 23:33:09 -08002342 private boolean isImsAvailableOnDevice() {
2343 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2344 if (pm == null) {
2345 // For some reason package manger is not available.. This will fail internally anyway,
2346 // so do not throw error and allow.
2347 return true;
2348 }
2349 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2350 }
2351
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002353 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002354 }
2355
Wink Savilleb564aae2014-10-23 10:18:09 -07002356 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 if (DBG) log("dial: " + number);
2358 // No permission check needed here: This is just a wrapper around the
2359 // ACTION_DIAL intent, which is available to any app since it puts up
2360 // the UI before it does anything.
2361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 String url = createTelUrl(number);
2365 if (url == null) {
2366 return;
2367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002369 // PENDING: should we just silently fail if phone is offhook or ringing?
2370 PhoneConstants.State state = mCM.getState(subId);
2371 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2372 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2373 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2374 mApp.startActivity(intent);
2375 }
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 }
2379 }
2380
2381 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002382 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002383 }
2384
Wink Savilleb564aae2014-10-23 10:18:09 -07002385 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 if (DBG) log("call: " + number);
2387
2388 // This is just a wrapper around the ACTION_CALL intent, but we still
2389 // need to do a permission check since we're calling startActivity()
2390 // from the context of the phone app.
2391 enforceCallPermission();
2392
Jordan Liu1617b712019-07-10 15:06:26 -07002393 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 != AppOpsManager.MODE_ALLOWED) {
2395 return;
2396 }
2397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398 final long identity = Binder.clearCallingIdentity();
2399 try {
2400 String url = createTelUrl(number);
2401 if (url == null) {
2402 return;
2403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002405 boolean isValid = false;
2406 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2407 if (slist != null) {
2408 for (SubscriptionInfo subInfoRecord : slist) {
2409 if (subInfoRecord.getSubscriptionId() == subId) {
2410 isValid = true;
2411 break;
2412 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002413 }
Wink Saville08874612014-08-31 19:19:58 -07002414 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415 if (!isValid) {
2416 return;
2417 }
Wink Saville08874612014-08-31 19:19:58 -07002418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002419 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2420 intent.putExtra(SUBSCRIPTION_KEY, subId);
2421 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2422 mApp.startActivity(intent);
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
2425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 }
2427
Wink Savilleb564aae2014-10-23 10:18:09 -07002428 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002429 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002430 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2431 }
2432
Wink Savilleb564aae2014-10-23 10:18:09 -07002433 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002434 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002435 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2436 }
2437
Wink Savilleb564aae2014-10-23 10:18:09 -07002438 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440
2441 final long identity = Binder.clearCallingIdentity();
2442 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002443 Phone phone = getPhone(subId);
2444 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445 checkSimPin.start();
2446 return checkSimPin.unlockSim(null, pin);
2447 } finally {
2448 Binder.restoreCallingIdentity(identity);
2449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 }
2451
Wink Savilleb564aae2014-10-23 10:18:09 -07002452 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002454
2455 final long identity = Binder.clearCallingIdentity();
2456 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002457 Phone phone = getPhone(subId);
2458 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 checkSimPuk.start();
2460 return checkSimPuk.unlockSim(puk, pin);
2461 } finally {
2462 Binder.restoreCallingIdentity(identity);
2463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465
2466 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002467 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 * a synchronous one.
2469 */
2470 private static class UnlockSim extends Thread {
2471
2472 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002473 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474
2475 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002476 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2477 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478
2479 // For replies from SimCard interface
2480 private Handler mHandler;
2481
2482 // For async handler to identify request type
2483 private static final int SUPPLY_PIN_COMPLETE = 100;
2484
Michele Berionne5e411512020-11-13 02:36:59 +00002485 UnlockSim(int phoneId, IccCard simCard) {
2486 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 mSimCard = simCard;
2488 }
2489
2490 @Override
2491 public void run() {
2492 Looper.prepare();
2493 synchronized (UnlockSim.this) {
2494 mHandler = new Handler() {
2495 @Override
2496 public void handleMessage(Message msg) {
2497 AsyncResult ar = (AsyncResult) msg.obj;
2498 switch (msg.what) {
2499 case SUPPLY_PIN_COMPLETE:
2500 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2501 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002502 mRetryCount = msg.arg1;
2503 if (ar.exception != null) {
2504 if (ar.exception instanceof CommandException &&
2505 ((CommandException)(ar.exception)).getCommandError()
2506 == CommandException.Error.PASSWORD_INCORRECT) {
2507 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002508 } //When UiccCardApp dispose,handle message and return exception
2509 else if (ar.exception instanceof CommandException &&
2510 ((CommandException) (ar.exception)).getCommandError()
2511 == CommandException.Error.ABORTED) {
2512 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002513 } else {
2514 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2515 }
2516 } else {
2517 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 mDone = true;
2520 UnlockSim.this.notifyAll();
2521 }
2522 break;
2523 }
2524 }
2525 };
2526 UnlockSim.this.notifyAll();
2527 }
2528 Looper.loop();
2529 }
2530
2531 /*
2532 * Use PIN or PUK to unlock SIM card
2533 *
2534 * If PUK is null, unlock SIM card with PIN
2535 *
2536 * If PUK is not null, unlock SIM card with PUK and set PIN code
2537 */
Wink Saville9de0f752013-10-22 19:04:03 -07002538 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539
2540 while (mHandler == null) {
2541 try {
2542 wait();
2543 } catch (InterruptedException e) {
2544 Thread.currentThread().interrupt();
2545 }
2546 }
2547 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2548
2549 if (puk == null) {
2550 mSimCard.supplyPin(pin, callback);
2551 } else {
2552 mSimCard.supplyPuk(puk, pin, callback);
2553 }
2554
2555 while (!mDone) {
2556 try {
2557 Log.d(LOG_TAG, "wait for done");
2558 wait();
2559 } catch (InterruptedException e) {
2560 // Restore the interrupted status
2561 Thread.currentThread().interrupt();
2562 }
2563 }
2564 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002565 int[] resultArray = new int[2];
2566 resultArray[0] = mResult;
2567 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002568
2569 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002570 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002571 }
2572
Wink Saville9de0f752013-10-22 19:04:03 -07002573 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 }
2575 }
2576
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002577 /**
2578 * This method has been removed due to privacy and stability concerns.
2579 */
2580 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002582 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2583 return;
Wink Saville36469e72014-06-11 15:17:00 -07002584 }
2585
Nathan Harold1f889d82020-06-04 17:05:26 -07002586 @Override
2587 public void updateServiceLocationWithPackageName(String callingPackage) {
2588 mApp.getSystemService(AppOpsManager.class)
2589 .checkPackage(Binder.getCallingUid(), callingPackage);
2590
Nathan Haroldf096d982020-11-18 17:18:06 -08002591 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002592 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2593 // Callers targeting S have no business invoking this method.
2594 return;
2595 }
2596
2597 LocationAccessPolicy.LocationPermissionResult locationResult =
2598 LocationAccessPolicy.checkLocationPermission(mApp,
2599 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2600 .setCallingPackage(callingPackage)
2601 .setCallingFeatureId(null)
2602 .setCallingPid(Binder.getCallingPid())
2603 .setCallingUid(Binder.getCallingUid())
2604 .setMethod("updateServiceLocation")
2605 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2606 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2607 .build());
2608 // Apps that lack location permission have no business calling this method;
2609 // however, because no permission was declared in the public API, denials must
2610 // all be "soft".
2611 switch (locationResult) {
2612 case DENIED_HARD: /* fall through */
2613 case DENIED_SOFT:
2614 return;
2615 }
2616
2617 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618 final long identity = Binder.clearCallingIdentity();
2619 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002620 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002622 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002626 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 }
2628
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002629 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002630 @Override
2631 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002632 return isRadioOnWithFeature(callingPackage, null);
2633 }
2634
2635
2636 @Override
2637 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2638 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2639 callingFeatureId);
2640 }
2641
2642 @Deprecated
2643 @Override
2644 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2645 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002646 }
2647
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002648 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002649 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2650 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002652 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002653 return false;
2654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 return isRadioOnForSubscriber(subId);
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002662 }
2663
2664 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 final Phone phone = getPhone(subId);
2668 if (phone != null) {
2669 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2670 } else {
2671 return false;
2672 }
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 }
2677
2678 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002679 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 }
Wink Saville36469e72014-06-11 15:17:00 -07002681
Wink Savilleb564aae2014-10-23 10:18:09 -07002682 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 final Phone phone = getPhone(subId);
2688 if (phone != null) {
2689 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2690 }
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 }
Wink Saville36469e72014-06-11 15:17:00 -07002694 }
2695
2696 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002697 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002698 }
2699
Wink Savilleb564aae2014-10-23 10:18:09 -07002700 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 final Phone phone = getPhone(subId);
2706 if (phone == null) {
2707 return false;
2708 }
2709 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2710 toggleRadioOnOffForSubscriber(subId);
2711 }
2712 return true;
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 }
Wink Saville36469e72014-06-11 15:17:00 -07002717
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002719 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002720 /*
2721 * If any of the Radios are available, it will need to be
2722 * shutdown. So return true if any Radio is available.
2723 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2727 Phone phone = PhoneFactory.getPhone(i);
2728 if (phone != null && phone.isRadioAvailable()) return true;
2729 }
2730 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2731 return false;
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002734 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002735 }
2736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002738 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 enforceModifyPermission();
2740
2741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2744 logv("Shutting down Phone " + i);
2745 shutdownRadioUsingPhoneId(i);
2746 }
2747 } finally {
2748 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002749 }
2750 }
2751
2752 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002753 Phone phone = PhoneFactory.getPhone(phoneId);
2754 if (phone != null && phone.isRadioAvailable()) {
2755 phone.shutdownRadio();
2756 }
2757 }
2758
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761
2762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2765 if (defaultPhone != null) {
2766 defaultPhone.setRadioPower(turnOn);
2767 return true;
2768 } else {
2769 loge("There's no default phone.");
2770 return false;
2771 }
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002774 }
Wink Saville36469e72014-06-11 15:17:00 -07002775 }
2776
Wink Savilleb564aae2014-10-23 10:18:09 -07002777 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779
2780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 final Phone phone = getPhone(subId);
2783 if (phone != null) {
2784 phone.setRadioPower(turnOn);
2785 return true;
2786 } else {
2787 return false;
2788 }
2789 } finally {
2790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793
Wink Saville36469e72014-06-11 15:17:00 -07002794 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002795 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 public boolean enableDataConnectivity() {
2797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 int subId = mSubscriptionController.getDefaultDataSubId();
2802 final Phone phone = getPhone(subId);
2803 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002804 phone.getDataEnabledSettings().setDataEnabled(
2805 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 return true;
2807 } else {
2808 return false;
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 }
2814
Wink Saville36469e72014-06-11 15:17:00 -07002815 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002816 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 public boolean disableDataConnectivity() {
2818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 int subId = mSubscriptionController.getDefaultDataSubId();
2823 final Phone phone = getPhone(subId);
2824 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002825 phone.getDataEnabledSettings().setDataEnabled(
2826 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 return true;
2828 } else {
2829 return false;
2830 }
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 }
2835
Sanket Padawe356d7632015-06-22 14:03:32 -07002836 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002837 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 final Phone phone = getPhone(subId);
2841 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002842 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002843 } else {
2844 return false;
2845 }
2846 } finally {
2847 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002848 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849 }
2850
2851 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002852 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002853 }
2854
pkanwarae03a6b2016-11-06 20:37:09 -08002855 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 enforceCallPermission();
2857
2858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2861 return;
2862 }
2863 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2864 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
2867 }
pkanwar32d516d2016-10-14 19:37:38 -07002868 };
2869
Wink Savilleb564aae2014-10-23 10:18:09 -07002870 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002871 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872
2873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2876 return false;
2877 }
2878 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2879 } finally {
2880 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882 }
2883
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002884 /**
2885 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2886 * tag on getCallState Binder call.
2887 */
2888 @Deprecated
2889 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002891 if (CompatChanges.isChangeEnabled(
2892 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2893 Binder.getCallingUid())) {
2894 // Do not allow this API to be called on API version 31+, it should only be
2895 // called on old apps using this Binder call directly.
2896 throw new SecurityException("This method can only be used for applications "
2897 + "targeting API version 30 or less.");
2898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899 final long identity = Binder.clearCallingIdentity();
2900 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002901 Phone phone = getPhone(getDefaultSubscription());
2902 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2903 PhoneConstantConversions.convertCallState(phone.getState());
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
2907 }
2908
2909 @Override
2910 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2911 if (CompatChanges.isChangeEnabled(
2912 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2913 Binder.getCallingUid())) {
2914 // Check READ_PHONE_STATE for API version 31+
2915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2916 featureId, "getCallStateForSubscription")) {
2917 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2918 + "targeting API level 31+.");
2919 }
2920 }
2921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2925 PhoneConstantConversions.convertCallState(phone.getState());
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
2928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
Sanket Padawe356d7632015-06-22 14:03:32 -07002931 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002932 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002933 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2934 }
2935
2936 @Override
2937 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 final long identity = Binder.clearCallingIdentity();
2939 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002940 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08002942 if (phone.isUsingNewDataStack()) {
2943 return phone.getDataNetworkController().getInternetDataNetworkState();
2944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2946 } else {
2947 return PhoneConstantConversions.convertDataState(
2948 PhoneConstants.DataState.DISCONNECTED);
2949 }
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 }
2954
Sanket Padawe356d7632015-06-22 14:03:32 -07002955 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002956 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002957 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2958 }
2959
2960 @Override
2961 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962 final long identity = Binder.clearCallingIdentity();
2963 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002964 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 if (phone != null) {
2966 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2967 } else {
2968 return TelephonyManager.DATA_ACTIVITY_NONE;
2969 }
2970 } finally {
2971 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 }
2974
2975 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002976 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002977 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002978 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002979
2980 LocationAccessPolicy.LocationPermissionResult locationResult =
2981 LocationAccessPolicy.checkLocationPermission(mApp,
2982 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2983 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002984 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002985 .setCallingPid(Binder.getCallingPid())
2986 .setCallingUid(Binder.getCallingUid())
2987 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002988 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002989 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2990 .build());
2991 switch (locationResult) {
2992 case DENIED_HARD:
2993 throw new SecurityException("Not allowed to access cell location");
2994 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002995 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2996 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002997 }
2998
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002999 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003003 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003004 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
Svetoslav64fad262015-04-14 14:35:21 -07003008 }
3009
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003011 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003012 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3013 // registered cell info, so return a NULL country instead.
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003016 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3017 // Get default phone in this case.
3018 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3019 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003020 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003022 if (phone == null) return "";
3023 ServiceStateTracker sst = phone.getServiceStateTracker();
3024 if (sst == null) return "";
3025 LocaleTracker lt = sst.getLocaleTracker();
3026 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003027 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003031 }
3032
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003033 /**
3034 * This method was removed due to potential issues caused by performing partial
3035 * updates of service state, and lack of a credible use case.
3036 *
3037 * This has the ability to break the telephony implementation by disabling notification of
3038 * changes in device connectivity. DO NOT USE THIS!
3039 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003040 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 public void enableLocationUpdates() {
3042 mApp.enforceCallingOrSelfPermission(
3043 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003044 }
3045
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003046 /**
3047 * This method was removed due to potential issues caused by performing partial
3048 * updates of service state, and lack of a credible use case.
3049 *
3050 * This has the ability to break the telephony implementation by disabling notification of
3051 * changes in device connectivity. DO NOT USE THIS!
3052 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003053 @Override
3054 public void disableLocationUpdates() {
3055 mApp.enforceCallingOrSelfPermission(
3056 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057 }
3058
3059 @Override
3060 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003061 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3062 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003063 try {
3064 mApp.getSystemService(AppOpsManager.class)
3065 .checkPackage(Binder.getCallingUid(), callingPackage);
3066 } catch (SecurityException e) {
3067 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3068 throw e;
3069 }
3070
Nathan Haroldf096d982020-11-18 17:18:06 -08003071 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003072 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3073 throw new SecurityException(
3074 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3075 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003076
Jordan Liu1617b712019-07-10 15:06:26 -07003077 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003078 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3079 return null;
3080 }
Svetoslav64fad262015-04-14 14:35:21 -07003081
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003082 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003083
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003084 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003085 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003086
Nathan Haroldf180aac2018-06-01 18:43:55 -07003087 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3088 for (CellInfo ci : info) {
3089 if (ci instanceof CellInfoGsm) {
3090 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3091 } else if (ci instanceof CellInfoWcdma) {
3092 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003094 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003095 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096 }
3097
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003098 private List<CellInfo> getCachedCellInfo() {
3099 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3100 for (Phone phone : PhoneFactory.getPhones()) {
3101 List<CellInfo> info = phone.getAllCellInfo();
3102 if (info != null) cellInfos.addAll(info);
3103 }
3104 return cellInfos;
3105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003106
3107 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003108 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003109 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003110 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003111
3112 LocationAccessPolicy.LocationPermissionResult locationResult =
3113 LocationAccessPolicy.checkLocationPermission(mApp,
3114 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3115 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003116 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003117 .setCallingPid(Binder.getCallingPid())
3118 .setCallingUid(Binder.getCallingUid())
3119 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003120 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003121 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3122 .build());
3123 switch (locationResult) {
3124 case DENIED_HARD:
3125 throw new SecurityException("Not allowed to access cell info");
3126 case DENIED_SOFT:
3127 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003128 }
3129
Nathan Haroldf096d982020-11-18 17:18:06 -08003130 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003131 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3132 return getCachedCellInfo();
3133 }
3134
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003135 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003136 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3140 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003141 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003142 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003143 if (info != null) cellInfos.addAll(info);
3144 }
3145 return cellInfos;
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 }
3149 }
3150
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003151 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003152 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3153 String callingFeatureId) {
3154 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3155 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003156 }
3157
3158 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003159 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3160 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003161 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003162 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003163 }
3164
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003165 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3166 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003167 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003168 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003169
3170 LocationAccessPolicy.LocationPermissionResult locationResult =
3171 LocationAccessPolicy.checkLocationPermission(mApp,
3172 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3173 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003174 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003175 .setCallingPid(Binder.getCallingPid())
3176 .setCallingUid(Binder.getCallingUid())
3177 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003178 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3179 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003180 .build());
3181 switch (locationResult) {
3182 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003183 if (TelephonyPermissions
3184 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003185 // Safetynet logging for b/154934934
3186 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3187 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003188 throw new SecurityException("Not allowed to access cell info");
3189 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003190 if (TelephonyPermissions
3191 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003192 // Safetynet logging for b/154934934
3193 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3194 }
Nathan Harold5320c422019-05-09 10:26:08 -07003195 try {
3196 cb.onCellInfo(new ArrayList<CellInfo>());
3197 } catch (RemoteException re) {
3198 // Drop without consequences
3199 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003200 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003201 }
3202
Nathan Harolda939a962019-05-09 10:13:47 -07003203
3204 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003205 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3206
3207 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3208 }
3209
3210 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003212 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003213 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214
3215 final long identity = Binder.clearCallingIdentity();
3216 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003217 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003221 }
3222
Shishir Agrawala9f32182016-04-12 12:00:16 -07003223 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003224 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003225 Phone phone = PhoneFactory.getPhone(slotIndex);
3226 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003227 return null;
3228 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003229 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003230 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003231 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003232 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003233 return null;
3234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235
3236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 return phone.getImei();
3239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003242 }
3243
3244 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003245 public String getTypeAllocationCodeForSlot(int slotIndex) {
3246 Phone phone = PhoneFactory.getPhone(slotIndex);
3247 String tac = null;
3248 if (phone != null) {
3249 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003250 try {
3251 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3252 } catch (IndexOutOfBoundsException e) {
3253 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3254 return null;
3255 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003256 }
3257 return tac;
3258 }
3259
3260 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003261 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003262 try {
3263 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3264 } catch (SecurityException se) {
3265 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3266 throw new SecurityException("Package " + callingPackage + " does not belong to "
3267 + Binder.getCallingUid());
3268 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003269 Phone phone = PhoneFactory.getPhone(slotIndex);
3270 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003271 return null;
3272 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003273
Jeff Davidson913390f2018-02-23 17:11:49 -08003274 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003275 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003276 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003277 return null;
3278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279
3280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 return phone.getMeid();
3283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
Jack Yu2af8d712017-03-15 17:14:14 -07003286 }
3287
3288 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003289 public String getManufacturerCodeForSlot(int slotIndex) {
3290 Phone phone = PhoneFactory.getPhone(slotIndex);
3291 String manufacturerCode = null;
3292 if (phone != null) {
3293 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003294 try {
3295 manufacturerCode =
3296 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3297 } catch (IndexOutOfBoundsException e) {
3298 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3299 return null;
3300 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003301 }
3302 return manufacturerCode;
3303 }
3304
3305 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003306 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3307 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003308 Phone phone = PhoneFactory.getPhone(slotIndex);
3309 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003310 return null;
3311 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003312 int subId = phone.getSubId();
3313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003314 mApp, subId, callingPackage, callingFeatureId,
3315 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003316 return null;
3317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003318
3319 final long identity = Binder.clearCallingIdentity();
3320 try {
3321 return phone.getDeviceSvn();
3322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003325 }
3326
fionaxu43304da2017-11-27 22:51:16 -08003327 @Override
3328 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 final Phone phone = getPhone(subId);
3332 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3333 } finally {
3334 Binder.restoreCallingIdentity(identity);
3335 }
fionaxu43304da2017-11-27 22:51:16 -08003336 }
3337
3338 @Override
3339 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 final Phone phone = getPhone(subId);
3343 return phone == null ? null : phone.getCarrierName();
3344 } finally {
3345 Binder.restoreCallingIdentity(identity);
3346 }
fionaxu43304da2017-11-27 22:51:16 -08003347 }
3348
calvinpanffe225e2018-11-01 19:43:06 +08003349 @Override
chen xu0026ca62019-03-06 15:28:50 -08003350 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003351 final long identity = Binder.clearCallingIdentity();
3352 try {
3353 final Phone phone = getPhone(subId);
3354 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003355 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003356 } finally {
3357 Binder.restoreCallingIdentity(identity);
3358 }
3359 }
3360
3361 @Override
chen xu0026ca62019-03-06 15:28:50 -08003362 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003366 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003367 } finally {
3368 Binder.restoreCallingIdentity(identity);
3369 }
3370 }
3371
chen xu651eec72018-11-11 19:03:44 -08003372 @Override
chen xu864e11c2018-12-06 22:10:03 -08003373 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3374 if (!isSubscriptionMccMnc) {
3375 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3376 }
chen xu651eec72018-11-11 19:03:44 -08003377 final Phone phone = PhoneFactory.getPhone(slotIndex);
3378 if (phone == null) {
3379 return TelephonyManager.UNKNOWN_CARRIER_ID;
3380 }
3381 final long identity = Binder.clearCallingIdentity();
3382 try {
3383 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3384 } finally {
3385 Binder.restoreCallingIdentity(identity);
3386 }
3387 }
3388
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389 //
3390 // Internal helper methods.
3391 //
3392
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003393 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003394 * Make sure the caller is the calling package itself
3395 *
3396 * @throws SecurityException if the caller is not the calling package
3397 */
3398 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3399 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003400 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3401 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003402 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003403 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003404 } catch (PackageManager.NameNotFoundException e) {
3405 // packageUid is -1
3406 }
3407 if (packageUid != callingUid) {
3408 throw new SecurityException(message + ": Package " + callingPackage
3409 + " does not belong to " + callingUid);
3410 }
3411 }
3412
3413 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003414 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3415 *
3416 * @throws SecurityException if the caller does not have the required permission
3417 */
3418 private void enforceModifyPermission() {
3419 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3420 }
3421
Shuo Qian3b6ee772019-11-13 17:43:31 -08003422 private void enforceActiveEmergencySessionPermission() {
3423 mApp.enforceCallingOrSelfPermission(
3424 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3425 }
3426
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003427 /**
3428 * Make sure the caller has the CALL_PHONE permission.
3429 *
3430 * @throws SecurityException if the caller does not have the required permission
3431 */
3432 private void enforceCallPermission() {
3433 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3434 }
3435
paulhu5a773602019-08-23 19:17:33 +08003436 private void enforceSettingsPermission() {
3437 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003438 }
3439
Michele Berionne5e411512020-11-13 02:36:59 +00003440 private void enforceRebootPermission() {
3441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3442 }
3443
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003444 private String createTelUrl(String number) {
3445 if (TextUtils.isEmpty(number)) {
3446 return null;
3447 }
3448
Jake Hambye994d462014-02-03 13:10:13 -08003449 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003450 }
3451
Ihab Awadf9e92732013-12-05 18:02:52 -08003452 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003453 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3454 }
3455
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003456 private static void logv(String msg) {
3457 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3458 }
3459
Ihab Awadf9e92732013-12-05 18:02:52 -08003460 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003461 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3462 }
3463
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003464 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003465 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003466 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003467 }
3468
Sanket Padawe356d7632015-06-22 14:03:32 -07003469 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003470 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003471 final long identity = Binder.clearCallingIdentity();
3472 try {
3473 final Phone phone = PhoneFactory.getPhone(slotIndex);
3474 if (phone == null) {
3475 return PhoneConstants.PHONE_TYPE_NONE;
3476 } else {
3477 return phone.getPhoneType();
3478 }
3479 } finally {
3480 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003482 }
3483
3484 /**
3485 * Returns the CDMA ERI icon index to display
3486 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003487 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003488 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3489 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3490 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003491 }
3492
Sanket Padawe356d7632015-06-22 14:03:32 -07003493 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003494 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3495 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003497 mApp, subId, callingPackage, callingFeatureId,
3498 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003499 return -1;
3500 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003501
3502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 final Phone phone = getPhone(subId);
3505 if (phone != null) {
3506 return phone.getCdmaEriIconIndex();
3507 } else {
3508 return -1;
3509 }
3510 } finally {
3511 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003513 }
3514
3515 /**
3516 * Returns the CDMA ERI icon mode,
3517 * 0 - ON
3518 * 1 - FLASHING
3519 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003520 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003521 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3522 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3523 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003524 }
3525
Sanket Padawe356d7632015-06-22 14:03:32 -07003526 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003527 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3528 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003530 mApp, subId, callingPackage, callingFeatureId,
3531 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003532 return -1;
3533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534
3535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 final Phone phone = getPhone(subId);
3538 if (phone != null) {
3539 return phone.getCdmaEriIconMode();
3540 } else {
3541 return -1;
3542 }
3543 } finally {
3544 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003546 }
3547
3548 /**
3549 * Returns the CDMA ERI text,
3550 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003552 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3553 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3554 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003555 }
3556
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003558 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3559 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003561 mApp, subId, callingPackage, callingFeatureId,
3562 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003563 return null;
3564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 final Phone phone = getPhone(subId);
3569 if (phone != null) {
3570 return phone.getCdmaEriText();
3571 } else {
3572 return null;
3573 }
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003577 }
3578
3579 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003580 * Returns the CDMA MDN.
3581 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003582 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003583 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3585 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586
3587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003590 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003591 return phone.getLine1Number();
3592 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003593 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003594 return null;
3595 }
3596 } finally {
3597 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003598 }
3599 }
3600
3601 /**
3602 * Returns the CDMA MIN.
3603 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003604 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003605 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3607 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003608
3609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 final Phone phone = getPhone(subId);
3612 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3613 return phone.getCdmaMin();
3614 } else {
3615 return null;
3616 }
3617 } finally {
3618 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003619 }
3620 }
3621
Hall Liud892bec2018-11-30 14:51:45 -08003622 @Override
3623 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3624 INumberVerificationCallback callback, String callingPackage) {
3625 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3626 != PERMISSION_GRANTED) {
3627 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3628 }
3629 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3630
3631 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3632 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003633 throw new SecurityException("Calling package must be configured in the device config: "
3634 + "calling package: " + callingPackage
3635 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003636 }
3637
3638 if (range == null) {
3639 throw new NullPointerException("Range must be non-null");
3640 }
3641
3642 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003643 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003644
3645 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3646 }
3647
Junda Liuca05d5d2014-08-14 22:36:34 -07003648 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 * Returns true if CDMA provisioning needs to run.
3650 */
3651 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652 final long identity = Binder.clearCallingIdentity();
3653 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003654 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655 } finally {
3656 Binder.restoreCallingIdentity(identity);
3657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003658 }
3659
3660 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003661 * Sets the voice mail number of a given subId.
3662 */
3663 @Override
3664 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003665 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3666 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003667
3668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3671 new Pair<String, String>(alphaTag, number), new Integer(subId));
3672 return success;
3673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003676 }
3677
Ta-wei Yen87c49842016-05-13 21:19:52 -07003678 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003679 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003681 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3682 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003683 if (!TextUtils.equals(callingPackage, systemDialer)) {
3684 throw new SecurityException("caller must be system dialer");
3685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3690 if (phoneAccountHandle == null) {
3691 return null;
3692 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003693 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003694 } finally {
3695 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003696 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003697 }
3698
3699 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003700 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3701 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003704 mApp, subId, callingPackage, callingFeatureId,
3705 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003706 return null;
3707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003709 final long identity = Binder.clearCallingIdentity();
3710 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003711 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003715 }
3716
3717 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003718 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3719 VisualVoicemailSmsFilterSettings settings) {
3720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003725 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003729 }
3730
3731 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003732 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003738 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739 } finally {
3740 Binder.restoreCallingIdentity(identity);
3741 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003742 }
3743
3744 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003745 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3746 String callingPackage, int subId) {
3747 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748
3749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003752 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753 } finally {
3754 Binder.restoreCallingIdentity(identity);
3755 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003756 }
3757
3758 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003759 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003760 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761
3762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003765 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003769 }
3770
3771 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003772 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3773 String callingAttributionTag, int subId, String number, int port, String text,
3774 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003775 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003776 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003777 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003778 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003779 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3780 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003781 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003782
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003783 /**
fionaxu0152e512016-11-14 13:36:14 -08003784 * Sets the voice activation state of a given subId.
3785 */
3786 @Override
3787 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3789 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790
3791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 final Phone phone = getPhone(subId);
3794 if (phone != null) {
3795 phone.setVoiceActivationState(activationState);
3796 } else {
3797 loge("setVoiceActivationState fails with invalid subId: " + subId);
3798 }
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003801 }
3802 }
3803
3804 /**
3805 * Sets the data activation state of a given subId.
3806 */
3807 @Override
3808 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3810 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811
3812 final long identity = Binder.clearCallingIdentity();
3813 try {
3814 final Phone phone = getPhone(subId);
3815 if (phone != null) {
3816 phone.setDataActivationState(activationState);
3817 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003818 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819 }
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003822 }
3823 }
3824
3825 /**
3826 * Returns the voice activation state of a given subId.
3827 */
3828 @Override
3829 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003830 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831
fionaxu0152e512016-11-14 13:36:14 -08003832 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 if (phone != null) {
3836 return phone.getVoiceActivationState();
3837 } else {
3838 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3839 }
3840 } finally {
3841 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003842 }
3843 }
3844
3845 /**
3846 * Returns the data activation state of a given subId.
3847 */
3848 @Override
3849 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003850 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851
fionaxu0152e512016-11-14 13:36:14 -08003852 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853 final long identity = Binder.clearCallingIdentity();
3854 try {
3855 if (phone != null) {
3856 return phone.getDataActivationState();
3857 } else {
3858 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3859 }
3860 } finally {
3861 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003862 }
3863 }
3864
3865 /**
Wink Saville36469e72014-06-11 15:17:00 -07003866 * Returns the unread count of voicemails for a subId
3867 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003868 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003869 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3870 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003871 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003872 mApp, subId, callingPackage, callingFeatureId,
3873 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003874 return 0;
3875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003876 final long identity = Binder.clearCallingIdentity();
3877 try {
3878 final Phone phone = getPhone(subId);
3879 if (phone != null) {
3880 return phone.getVoiceMessageCount();
3881 } else {
3882 return 0;
3883 }
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003887 }
3888
3889 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003890 * returns true, if the device is in a state where both voice and data
3891 * are supported simultaneously. This can change based on location or network condition.
3892 */
3893 @Override
3894 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895 final long identity = Binder.clearCallingIdentity();
3896 try {
3897 final Phone phone = getPhone(subId);
3898 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3899 } finally {
3900 Binder.restoreCallingIdentity(identity);
3901 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003902 }
3903
3904 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003905 * Send the dialer code if called from the current default dialer or the caller has
3906 * carrier privilege.
3907 * @param inputCode The dialer code to send
3908 */
3909 @Override
3910 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003911 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003913 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3914 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003915 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003916 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003917 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003919
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003922 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003923 } finally {
3924 Binder.restoreCallingIdentity(identity);
3925 }
fionaxu235cc5e2017-03-06 22:25:57 -08003926 }
3927
Pengquan Menga1bb6272018-09-06 09:59:22 -07003928 @Override
3929 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003930 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003931 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003932 mApp, subId, "getNetworkSelectionMode");
3933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 if (!isActiveSubscription(subId)) {
3936 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3937 }
3938 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3939 } finally {
3940 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003941 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003942 }
3943
Brad Ebinger35c841c2018-10-01 10:40:55 -07003944 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003945 public boolean isInEmergencySmsMode() {
3946 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3947 final long identity = Binder.clearCallingIdentity();
3948 try {
3949 for (Phone phone : PhoneFactory.getPhones()) {
3950 if (phone.isInEmergencySmsMode()) {
3951 return true;
3952 }
3953 }
3954 } finally {
3955 Binder.restoreCallingIdentity(identity);
3956 }
3957 return false;
3958 }
3959
shilu366312e2019-12-17 09:28:10 -08003960 /**
3961 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3962 * @param subId The subscription to use to check the configuration.
3963 * @param c The callback that will be used to send the result.
3964 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003965 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003966 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3967 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003968 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003969 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003970
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003971 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3972 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3973 "IMS not available on device.");
3974 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003975 final long token = Binder.clearCallingIdentity();
3976 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003977 int slotId = getSlotIndexOrException(subId);
3978 verifyImsMmTelConfiguredOrThrow(slotId);
3979 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003980 } catch (ImsException e) {
3981 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 } finally {
3983 Binder.restoreCallingIdentity(token);
3984 }
3985 }
3986
shilu366312e2019-12-17 09:28:10 -08003987 /**
3988 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3989 * @param subId The subscription to use to check the configuration.
3990 * @param c The callback that will be used to send the result.
3991 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003993 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003994 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003995 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003996 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3997 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3998 }
Meng Wangafbc5852019-09-19 17:37:13 -07003999 final long token = Binder.clearCallingIdentity();
4000 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004001 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4002 .removeRegistrationCallbackForSubscription(c, subId);
4003 } catch (ImsException e) {
4004 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4005 + "is inactive, ignoring unregister.");
4006 // If the subscription is no longer active, just return, since the callback
4007 // will already have been removed internally.
4008 } finally {
4009 Binder.restoreCallingIdentity(token);
4010 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004011 }
4012
Brad Ebingera34a6c22019-10-22 17:36:18 -07004013 /**
4014 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4015 */
4016 @Override
4017 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4018 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4019 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4020 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4021 "IMS not available on device.");
4022 }
4023 final long token = Binder.clearCallingIdentity();
4024 try {
4025 Phone phone = getPhone(subId);
4026 if (phone == null) {
4027 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4028 + subId + "'");
4029 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4030 }
4031 phone.getImsRegistrationState(regState -> {
4032 try {
4033 consumer.accept((regState == null)
4034 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4035 } catch (RemoteException e) {
4036 // Ignore if the remote process is no longer available to call back.
4037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4038 }
4039 });
4040 } finally {
4041 Binder.restoreCallingIdentity(token);
4042 }
4043 }
4044
4045 /**
4046 * Get the transport type for the IMS service registration state.
4047 */
4048 @Override
4049 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004050 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004051 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004052 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4053 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4054 "IMS not available on device.");
4055 }
4056 final long token = Binder.clearCallingIdentity();
4057 try {
4058 Phone phone = getPhone(subId);
4059 if (phone == null) {
4060 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4061 + subId + "'");
4062 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4063 }
4064 phone.getImsRegistrationTech(regTech -> {
4065 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4066 int regTechConverted = (regTech == null)
4067 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4068 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4069 regTechConverted);
4070 try {
4071 consumer.accept(regTechConverted);
4072 } catch (RemoteException e) {
4073 // Ignore if the remote process is no longer available to call back.
4074 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4075 }
4076 });
4077 } finally {
4078 Binder.restoreCallingIdentity(token);
4079 }
4080 }
4081
shilu366312e2019-12-17 09:28:10 -08004082 /**
4083 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4084 * @param subId The subscription to use to check the configuration.
4085 * @param c The callback that will be used to send the result.
4086 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004088 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4089 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004090 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004091 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004092 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4093 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4094 "IMS not available on device.");
4095 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004096 final long token = Binder.clearCallingIdentity();
4097 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004098 int slotId = getSlotIndexOrException(subId);
4099 verifyImsMmTelConfiguredOrThrow(slotId);
4100 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004101 } catch (ImsException e) {
4102 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 } finally {
4104 Binder.restoreCallingIdentity(token);
4105 }
4106 }
4107
shilu366312e2019-12-17 09:28:10 -08004108 /**
4109 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4110 * @param subId The subscription to use to check the configuration.
4111 * @param c The callback that will be used to send the result.
4112 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004113 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004114 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004115 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004116 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004117 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4118 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4119 }
Meng Wangafbc5852019-09-19 17:37:13 -07004120
4121 final long token = Binder.clearCallingIdentity();
4122 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004123 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004124 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004125 } catch (ImsException e) {
4126 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4127 + "is inactive, ignoring unregister.");
4128 // If the subscription is no longer active, just return, since the callback
4129 // will already have been removed internally.
4130 } finally {
4131 Binder.restoreCallingIdentity(token);
4132 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 }
4134
4135 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004136 public boolean isCapable(int subId, int capability, int regTech) {
4137 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 final long token = Binder.clearCallingIdentity();
4139 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004140 int slotId = getSlotIndexOrException(subId);
4141 verifyImsMmTelConfiguredOrThrow(slotId);
4142 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004143 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4145 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004146 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004147 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4148 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 } finally {
4150 Binder.restoreCallingIdentity(token);
4151 }
4152 }
4153
4154 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004155 public boolean isAvailable(int subId, int capability, int regTech) {
4156 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 final long token = Binder.clearCallingIdentity();
4158 try {
4159 Phone phone = getPhone(subId);
4160 if (phone == null) return false;
4161 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004162 } catch (com.android.ims.ImsException e) {
4163 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4164 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004165 } finally {
4166 Binder.restoreCallingIdentity(token);
4167 }
4168 }
4169
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004170 /**
4171 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4172 * subscription.
4173 * @param subId The subscription to use to check the configuration.
4174 * @param callback The callback that will be used to send the result.
4175 * @param capability The MmTelFeature capability that will be used to send the result.
4176 * @param transportType The transport type of the MmTelFeature capability.
4177 */
4178 @Override
4179 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4180 int transportType) {
4181 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4182 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4183 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4184 "IMS not available on device.");
4185 }
4186 final long token = Binder.clearCallingIdentity();
4187 try {
4188 int slotId = getSlotIndex(subId);
4189 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4190 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4191 + subId + "'");
4192 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4193 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004194 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004195 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4196 transportType, aBoolean -> {
4197 try {
4198 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4199 } catch (RemoteException e) {
4200 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4201 + "running. Ignore");
4202 }
4203 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004204 } catch (ImsException e) {
4205 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004206 } finally {
4207 Binder.restoreCallingIdentity(token);
4208 }
4209 }
4210
shilu366312e2019-12-17 09:28:10 -08004211 /**
4212 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4213 * @param subId The subscription to use to check the configuration.
4214 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 @Override
4216 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004217 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004218 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004219
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 final long token = Binder.clearCallingIdentity();
4221 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004222 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004223 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004224 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004225 } catch (ImsException e) {
4226 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 } finally {
4228 Binder.restoreCallingIdentity(token);
4229 }
4230 }
4231
4232 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004233 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004235 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 final long identity = Binder.clearCallingIdentity();
4237 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004238 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004239 // This setting doesn't require an active ImsService connection, so do not verify. The
4240 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004241 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004242 } catch (ImsException e) {
4243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 } finally {
4245 Binder.restoreCallingIdentity(identity);
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
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004254 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004255 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004256 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004257 final long identity = Binder.clearCallingIdentity();
4258 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004259 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004260 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004261 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004262 } catch (ImsException e) {
4263 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 } finally {
4265 Binder.restoreCallingIdentity(identity);
4266 }
4267 }
4268
4269 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004270 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004272 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 final long identity = Binder.clearCallingIdentity();
4274 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004275 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004276 // This setting doesn't require an active ImsService connection, so do not verify. The
4277 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004278 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004279 } catch (ImsException e) {
4280 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
4284 }
4285
shilu366312e2019-12-17 09:28:10 -08004286 /**
4287 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4288 * @param subId The subscription to use to check the configuration.
4289 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004290 @Override
4291 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004292 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004293 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 final long identity = Binder.clearCallingIdentity();
4295 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004296 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004297 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004299 } catch (ImsException e) {
4300 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004301 } finally {
4302 Binder.restoreCallingIdentity(identity);
4303 }
4304 }
4305
4306 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004307 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004309 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004310 final long identity = Binder.clearCallingIdentity();
4311 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004312 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004313 // This setting doesn't require an active ImsService connection, so do not verify. The
4314 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004315 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004316 } catch (ImsException e) {
4317 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
4321 }
4322
shilu366312e2019-12-17 09:28:10 -08004323 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004324 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4325 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4326 * @param subId The subscription to use to check the configuration.
4327 */
4328 @Override
4329 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004330 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004331 mApp, subId, "isCrossSimCallingEnabledByUser");
4332 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).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004337 } catch (ImsException e) {
4338 throw new ServiceSpecificException(e.getCode());
4339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
4342 }
4343
4344 /**
4345 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4346 * Requires MODIFY_PHONE_STATE permission.
4347 * @param subId The subscription to use to check the configuration.
4348 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4349 * false otherwise
4350 */
4351 @Override
4352 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4354 "setCrossSimCallingEnabled");
4355 final long identity = Binder.clearCallingIdentity();
4356 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004357 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004358 // This setting doesn't require an active ImsService connection, so do not verify. The
4359 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004360 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004361 } catch (ImsException e) {
4362 throw new ServiceSpecificException(e.getCode());
4363 } finally {
4364 Binder.restoreCallingIdentity(identity);
4365 }
4366 }
4367
4368 /**
shilu366312e2019-12-17 09:28:10 -08004369 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4370 * @param subId The subscription to use to check the configuration.
4371 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004373
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004375 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004376 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004377 final long identity = Binder.clearCallingIdentity();
4378 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004379 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004380 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004381 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004382 } catch (ImsException e) {
4383 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004384 } finally {
4385 Binder.restoreCallingIdentity(identity);
4386 }
4387 }
4388
4389 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004390 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004392 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004393 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).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004399 } catch (ImsException e) {
4400 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004401 } finally {
4402 Binder.restoreCallingIdentity(identity);
4403 }
4404 }
4405
4406 @Override
4407 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4409 "setVoWiFiNonPersistent");
4410 final long identity = Binder.clearCallingIdentity();
4411 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004412 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004413 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004414 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004415 } catch (ImsException e) {
4416 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
4420 }
4421
shilu366312e2019-12-17 09:28:10 -08004422 /**
4423 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4424 * @param subId The subscription to use to check the configuration.
4425 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004426 @Override
4427 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004428 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004429 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004430 final long identity = Binder.clearCallingIdentity();
4431 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004432 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004433 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004434 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004435 } catch (ImsException e) {
4436 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
4440 }
4441
4442 @Override
4443 public void setVoWiFiModeSetting(int subId, int mode) {
4444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4445 "setVoWiFiModeSetting");
4446 final long identity = Binder.clearCallingIdentity();
4447 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004448 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004449 // This setting doesn't require an active ImsService connection, so do not verify. The
4450 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004451 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004452 } catch (ImsException e) {
4453 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004454 } finally {
4455 Binder.restoreCallingIdentity(identity);
4456 }
4457 }
4458
4459 @Override
4460 public int getVoWiFiRoamingModeSetting(int subId) {
4461 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4462 final long identity = Binder.clearCallingIdentity();
4463 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004464 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004465 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004466 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004467 } catch (ImsException e) {
4468 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004469 } finally {
4470 Binder.restoreCallingIdentity(identity);
4471 }
4472 }
4473
4474 @Override
4475 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4477 "setVoWiFiRoamingModeSetting");
4478 final long identity = Binder.clearCallingIdentity();
4479 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004480 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004481 // This setting doesn't require an active ImsService connection, so do not verify. The
4482 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004483 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004484 } catch (ImsException e) {
4485 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
4489 }
4490
4491 @Override
4492 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4494 "setRttCapabilityEnabled");
4495 final long identity = Binder.clearCallingIdentity();
4496 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004498 // This setting doesn't require an active ImsService connection, so do not verify. The
4499 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004500 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004501 } catch (ImsException e) {
4502 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
4506 }
4507
shilu366312e2019-12-17 09:28:10 -08004508 /**
4509 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4510 * @param subId The subscription to use to check the configuration.
4511 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004512 @Override
4513 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004514 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004515 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004520 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004521 } catch (ImsException e) {
4522 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004523 } finally {
4524 Binder.restoreCallingIdentity(identity);
4525 }
4526 }
4527
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004528 @Override
4529 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4530 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4531 final long identity = Binder.clearCallingIdentity();
4532 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004533 if (!isImsAvailableOnDevice()) {
4534 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4535 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004536 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004537 int slotId = getSlotIndexOrException(subId);
4538 verifyImsMmTelConfiguredOrThrow(slotId);
4539 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004540 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004541 } catch (ImsException e) {
4542 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
4546 }
4547
4548 @Override
4549 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4550 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4551 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4553 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4554 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004555 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004556 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004557 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004558 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004559 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4560 + "is inactive, ignoring unregister.");
4561 // If the subscription is no longer active, just return, since the callback will already
4562 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
4566 }
4567
allenwtsu99c623b2020-01-03 18:24:23 +08004568
4569 private void checkModifyPhoneStatePermission(int subId, String message) {
4570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4571 message);
4572 }
4573
4574 private boolean isImsProvisioningRequired(int subId, int capability,
4575 boolean isMmtelCapability) {
4576 Phone phone = getPhone(subId);
4577 if (phone == null) {
4578 loge("phone instance null for subid " + subId);
4579 return false;
4580 }
4581 if (isMmtelCapability) {
4582 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4583 return false;
4584 }
4585 } else {
4586 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4587 return false;
4588 }
4589 }
4590 return true;
4591 }
4592
4593 @Override
4594 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4595 boolean isProvisioned) {
4596 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4597
4598 final long identity = Binder.clearCallingIdentity();
4599 try {
4600 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4601 if (!isImsProvisioningRequired(subId, capability, false)) {
4602 return;
4603 }
4604
4605 // this capability requires provisioning, route to the correct API.
4606 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4607 switch (capability) {
4608 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4609 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4610 ims.setEabProvisioned(isProvisioned);
4611 break;
4612 default: {
4613 throw new IllegalArgumentException("Tried to set provisioning for "
4614 + "rcs capability '" + capability + "', which does not require "
4615 + "provisioning.");
4616 }
4617 }
4618 } finally {
4619 Binder.restoreCallingIdentity(identity);
4620 }
4621
4622 }
4623
4624
4625 @Override
4626 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4627 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4628 final long identity = Binder.clearCallingIdentity();
4629 try {
4630 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4631 if (!isImsProvisioningRequired(subId, capability, false)) {
4632 return true;
4633 }
4634
4635 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4636 switch (capability) {
4637 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4638 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4639 return ims.isEabProvisionedOnDevice();
4640
4641 default: {
4642 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4643 + "capability '" + capability + "', which does not require "
4644 + "provisioning.");
4645 }
4646 }
4647
4648 } finally {
4649 Binder.restoreCallingIdentity(identity);
4650 }
4651 }
4652
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004653 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4655 boolean isProvisioned) {
4656 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004657 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4658 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4659 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004660 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4661 }
allenwtsu99c623b2020-01-03 18:24:23 +08004662 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004663 final long identity = Binder.clearCallingIdentity();
4664 try {
4665 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004666 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004667 return;
4668 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004669 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4670 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4671 loge("setImsProvisioningStatusForCapability: called for technology that does "
4672 + "not support provisioning - " + tech);
4673 return;
4674 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004675
4676 // this capability requires provisioning, route to the correct API.
4677 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4678 switch (capability) {
4679 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4680 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4681 ims.setVolteProvisioned(isProvisioned);
4682 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4683 ims.setWfcProvisioned(isProvisioned);
4684 }
4685 break;
4686 }
4687 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4688 // There is currently no difference in VT provisioning type.
4689 ims.setVtProvisioned(isProvisioned);
4690 break;
4691 }
4692 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4693 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4694 // change the capability of the feature instead if needed.
4695 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4696 == isProvisioned) {
4697 // No change in provisioning.
4698 return;
4699 }
4700 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4701 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004702 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004703 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004704 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4705 + ", Exception" + e.getMessage());
4706 }
4707 break;
4708 }
4709 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004710 throw new IllegalArgumentException("Tried to set provisioning for "
4711 + "MmTel capability '" + capability + "', which does not require "
4712 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004713 }
4714 }
4715
4716 } finally {
4717 Binder.restoreCallingIdentity(identity);
4718 }
4719 }
4720
4721 @Override
4722 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4723 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004724 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4725 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4726 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004727 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4728 }
4729 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4730 final long identity = Binder.clearCallingIdentity();
4731 try {
4732 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004733 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 return true;
4735 }
4736
Brad Ebinger0d79c572021-04-17 15:20:49 -07004737 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4738 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4739 loge("getImsProvisioningStatusForCapability: called for technology that does "
4740 + "not support provisioning - " + tech);
4741 return true;
4742 }
4743
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004744 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4745 switch (capability) {
4746 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4747 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4748 return ims.isVolteProvisionedOnDevice();
4749 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4750 return ims.isWfcProvisionedOnDevice();
4751 }
4752 // This should never happen, since we are checking tech above to make sure it
4753 // is either LTE or IWLAN.
4754 throw new IllegalArgumentException("Invalid radio technology for voice "
4755 + "capability.");
4756 }
4757 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4758 // There is currently no difference in VT provisioning type.
4759 return ims.isVtProvisionedOnDevice();
4760 }
4761 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4762 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4763 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4764 }
4765 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004766 throw new IllegalArgumentException(
4767 "Tried to get provisioning for MmTel capability '" + capability
4768 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004769 }
4770 }
4771
4772 } finally {
4773 Binder.restoreCallingIdentity(identity);
4774 }
4775 }
4776
4777 @Override
4778 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4779 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4780 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4781 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4782 }
4783 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4784 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4785 return (provisionedBits & capability) > 0;
4786 }
4787
4788 @Override
4789 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4790 boolean isProvisioned) {
4791 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4792 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4793 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4794 }
4795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4796 "setProvisioningStatusForCapability");
4797 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4798 // If the current provisioning status for capability already matches isProvisioned,
4799 // do nothing.
4800 if (((provisionedBits & capability) > 0) == isProvisioned) {
4801 return;
4802 }
4803 if (isProvisioned) {
4804 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4805 } else {
4806 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4807 }
4808 }
4809
4810 /**
4811 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4812 * technology. The bitfield should mirror the bitfield defined by
4813 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4814 */
4815 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4816 String key = getMmTelProvisioningKey(subId, tech);
4817 // Default is no capabilities are provisioned.
4818 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4819 }
4820
4821 /**
4822 * Sets the MmTel capability provisioning bitfield (defined by
4823 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4824 * technology specified.
4825 *
4826 * Note: This is a synchronous command and should not be called on UI thread.
4827 */
4828 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4829 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4830 String key = getMmTelProvisioningKey(subId, tech);
4831 editor.putInt(key, newField);
4832 editor.commit();
4833 }
4834
4835 private static String getMmTelProvisioningKey(int subId, int tech) {
4836 // resulting key is provision_ims_mmtel_{subId}_{tech}
4837 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4838 }
4839
4840 /**
4841 * Query CarrierConfig to see if the specified capability requires provisioning for the
4842 * carrier associated with the subscription id.
4843 */
4844 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4845 int capability) {
4846 CarrierConfigManager configManager = new CarrierConfigManager(context);
4847 PersistableBundle c = configManager.getConfigForSubId(subId);
4848 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004849 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004850 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4851 false);
4852 boolean requireVoiceVtProvisioning = c.getBoolean(
4853 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4854
4855 // First check to make sure that the capability requires provisioning.
4856 switch (capability) {
4857 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4858 // intentional fallthrough
4859 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4860 if (requireVoiceVtProvisioning) {
4861 // Voice and Video requires provisioning
4862 return true;
4863 }
4864 break;
4865 }
4866 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4867 if (requireUtProvisioning) {
4868 // UT requires provisioning
4869 return true;
4870 }
4871 break;
4872 }
4873 }
4874 return false;
4875 }
4876
allenwtsu99c623b2020-01-03 18:24:23 +08004877 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4878 int capability) {
4879 CarrierConfigManager configManager = new CarrierConfigManager(context);
4880 PersistableBundle c = configManager.getConfigForSubId(subId);
4881
4882 boolean requireRcsProvisioning = c.getBoolean(
4883 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4884
4885 // First check to make sure that the capability requires provisioning.
4886 switch (capability) {
4887 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4888 // intentional fallthrough
4889 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4890 if (requireRcsProvisioning) {
4891 // OPTION or PRESENCE requires provisioning
4892 return true;
4893 }
4894 break;
4895 }
4896 }
4897 return false;
4898 }
4899
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004900 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004901 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004902 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4903 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4904 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004905 enforceReadPrivilegedPermission("getImsProvisioningInt");
4906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004909 int slotId = getSlotIndex(subId);
4910 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4911 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4912 + subId + "' for key:" + key);
4913 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4914 }
calvinpanb5a34062021-02-08 19:59:36 +08004915 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004916 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4918 + subId + "' for key:" + key);
4919 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004920 } finally {
4921 Binder.restoreCallingIdentity(identity);
4922 }
4923 }
4924
4925 @Override
4926 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4928 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4929 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004930 enforceReadPrivilegedPermission("getImsProvisioningString");
4931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004934 int slotId = getSlotIndex(subId);
4935 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4936 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4937 + subId + "' for key:" + key);
4938 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4939 }
calvinpanb5a34062021-02-08 19:59:36 +08004940 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004941 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004942 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4943 + subId + "' for key:" + key);
4944 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
4948 }
4949
4950 @Override
4951 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004952 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4953 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4954 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4956 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004957 final long identity = Binder.clearCallingIdentity();
4958 try {
4959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004960 int slotId = getSlotIndex(subId);
4961 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4962 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4963 + subId + "' for key:" + key);
4964 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4965 }
calvinpanb5a34062021-02-08 19:59:36 +08004966 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4967 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004968 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004969 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004970 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
4974 }
4975
4976 @Override
4977 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004978 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4979 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4980 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4982 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004986 int slotId = getSlotIndex(subId);
4987 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4988 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4989 + subId + "' for key:" + key);
4990 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4991 }
calvinpanb5a34062021-02-08 19:59:36 +08004992 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4993 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004994 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004995 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004996 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
5000 }
5001
Brad Ebinger919631e2021-06-02 17:46:35 -07005002 /**
5003 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5004 * for the given slot ID or no ImsResolver instance has been created.
5005 * @param slotId The slot ID that the IMS service is created for.
5006 * @throws ImsException If there is no ImsService configured for this slot.
5007 */
5008 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5009 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5010 ImsFeature.FEATURE_MMTEL)) {
5011 throw new ImsException("This subscription does not support MMTEL over IMS",
5012 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5013 }
5014 }
5015
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005016 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005017 int slotId = SubscriptionManager.getSlotIndex(subId);
5018 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005019 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5020 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005021 }
5022 return slotId;
5023 }
5024
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005025 private int getSlotIndex(int subId) {
5026 int slotId = SubscriptionManager.getSlotIndex(subId);
5027 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5028 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5029 }
5030 return slotId;
5031 }
5032
Wink Saville36469e72014-06-11 15:17:00 -07005033 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005034 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005035 */
5036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005037 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5038 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005039 try {
5040 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5041 } catch (SecurityException se) {
5042 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5043 throw new SecurityException("Package " + callingPackage + " does not belong to "
5044 + Binder.getCallingUid());
5045 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005046 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005047 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005048 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005049 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005050 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005051 mApp, subId, callingPackage, callingFeatureId,
5052 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005053 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5054 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056 final long identity = Binder.clearCallingIdentity();
5057 try {
5058 final Phone phone = getPhone(subId);
5059 if (phone != null) {
5060 return phone.getServiceState().getDataNetworkType();
5061 } else {
5062 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5063 }
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005067 }
5068
5069 /**
5070 * Returns the data network type
5071 */
5072 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005073 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005074 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5075 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005076 }
5077
5078 /**
5079 * Returns the data network type for a subId
5080 */
5081 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005082 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5083 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005084 String functionName = "getDataNetworkTypeForSubscriber";
5085 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5086 mApp, functionName)) {
5087 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5088 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5089 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5090 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005091 }
5092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005093 final long identity = Binder.clearCallingIdentity();
5094 try {
5095 final Phone phone = getPhone(subId);
5096 if (phone != null) {
5097 return phone.getServiceState().getDataNetworkType();
5098 } else {
5099 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5100 }
5101 } finally {
5102 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005104 }
5105
5106 /**
Wink Saville36469e72014-06-11 15:17:00 -07005107 * Returns the Voice network type for a subId
5108 */
5109 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005110 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5111 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005112 String functionName = "getVoiceNetworkTypeForSubscriber";
5113 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5114 mApp, functionName)) {
5115 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5116 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5117 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5118 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005119 }
5120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 final long identity = Binder.clearCallingIdentity();
5122 try {
5123 final Phone phone = getPhone(subId);
5124 if (phone != null) {
5125 return phone.getServiceState().getVoiceNetworkType();
5126 } else {
5127 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5128 }
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005132 }
5133
5134 /**
5135 * @return true if a ICC card is present
5136 */
5137 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005138 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005139 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5140 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005141 }
5142
5143 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005144 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005145 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005146 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005147 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148 final long identity = Binder.clearCallingIdentity();
5149 try {
5150 final Phone phone = PhoneFactory.getPhone(slotIndex);
5151 if (phone != null) {
5152 return phone.getIccCard().hasIccCard();
5153 } else {
5154 return false;
5155 }
5156 } finally {
5157 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005159 }
5160
5161 /**
5162 * Return if the current radio is LTE on CDMA. This
5163 * is a tri-state return value as for a period of time
5164 * the mode may be unknown.
5165 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005166 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005167 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005168 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005169 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005170 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005171 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5172 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5173 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005174 }
5175
Sanket Padawe356d7632015-06-22 14:03:32 -07005176 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005177 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5178 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005179 try {
5180 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5181 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005182 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5183 }
5184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 final Phone phone = getPhone(subId);
5188 if (phone == null) {
5189 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5190 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005191 return TelephonyProperties.lte_on_cdma_device()
5192 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 }
5194 } finally {
5195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005196 }
Wink Saville36469e72014-06-11 15:17:00 -07005197 }
5198
Wink Saville36469e72014-06-11 15:17:00 -07005199 /**
5200 * {@hide}
5201 * Returns Default subId, 0 in the case of single standby.
5202 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005203 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005204 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005205 }
5206
Shishir Agrawala9f32182016-04-12 12:00:16 -07005207 private int getSlotForDefaultSubscription() {
5208 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5209 }
5210
Wink Savilleb564aae2014-10-23 10:18:09 -07005211 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005212 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005213 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005214
Pengquan Menge92a50d2018-09-21 15:54:48 -07005215 private boolean isActiveSubscription(int subId) {
5216 return mSubscriptionController.isActiveSubId(subId);
5217 }
5218
Ihab Awadf2177b72013-11-25 13:33:23 -08005219 /**
5220 * @see android.telephony.TelephonyManager.WifiCallingChoices
5221 */
5222 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005225 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5227 getWhenToMakeWifiCallsDefaultPreference());
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005231 }
5232
5233 /**
5234 * @see android.telephony.TelephonyManager.WifiCallingChoices
5235 */
5236 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 final long identity = Binder.clearCallingIdentity();
5238 try {
5239 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005240 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005245 }
5246
Sailesh Nepald1e68152013-12-12 19:08:02 -08005247 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005248 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005249 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005250 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005251
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005252 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5253 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5254 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005255 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005256 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5257 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005258 }
5259 return PhoneFactory.getPhone(phoneId);
5260 }
5261
Shishir Agrawal566b7612013-10-28 14:41:00 -07005262 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005263 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5264 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5266 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005268 if (DBG) {
5269 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5270 }
5271 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5272 p2);
5273 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005274
Jordan Liu4c733742019-02-28 12:03:40 -08005275
5276 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005277 public IccOpenLogicalChannelResponse iccOpenLogicalChannelByPort(
5278 int slotIndex, int portIndex, String callingPackage, String aid, int p2) {
Jordan Liu4c733742019-02-28 12:03:40 -08005279 enforceModifyPermission();
5280 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5281 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005282 log("iccOpenLogicalChannelByPort: slot=" + slotIndex + " port=" + portIndex + " aid="
5283 + aid + " p2=" + p2);
Jordan Liu4c733742019-02-28 12:03:40 -08005284 }
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005285 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotPortIndexOrThrowException(
5286 slotIndex, portIndex), callingPackage, aid, p2);
Jordan Liu4c733742019-02-28 12:03:40 -08005287 }
5288
5289 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5290 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 final long identity = Binder.clearCallingIdentity();
5292 try {
5293 if (TextUtils.equals(ISDR_AID, aid)) {
5294 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005295 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5296 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297 if (bestComponent == null
5298 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5299 loge("The calling package is not allowed to access ISD-R.");
5300 throw new SecurityException(
5301 "The calling package is not allowed to access ISD-R.");
5302 }
Derek Tan740e1672017-06-27 14:56:27 -07005303 }
Derek Tan740e1672017-06-27 14:56:27 -07005304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005306 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5307 null /* workSource */);
5308 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 return response;
5310 } finally {
5311 Binder.restoreCallingIdentity(identity);
5312 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005313 }
5314
5315 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005316 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5318 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005319 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5320 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5321 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005322
Jordan Liu4c733742019-02-28 12:03:40 -08005323 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005324 public boolean iccCloseLogicalChannelByPort(int slotIndex, int portIndex, int channel) {
Jordan Liu4c733742019-02-28 12:03:40 -08005325 enforceModifyPermission();
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005326 if (DBG) log("iccCloseLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5327 + portIndex + " chnl=" + channel);
5328 return iccCloseLogicalChannelWithPermission(
5329 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel);
Jordan Liu4c733742019-02-28 12:03:40 -08005330 }
5331
5332 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 final long identity = Binder.clearCallingIdentity();
5334 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 if (channel < 0) {
5336 return false;
5337 }
Jordan Liu4c733742019-02-28 12:03:40 -08005338 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5339 null /* workSource */);
5340 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 return success;
5342 } finally {
5343 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005344 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005345 }
5346
5347 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005348 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005349 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5351 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005352 if (DBG) {
5353 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5354 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5355 + p3 + " data=" + data);
5356 }
5357 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5358 command, p1, p2, p3, data);
5359 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005360
Jordan Liu4c733742019-02-28 12:03:40 -08005361 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005362 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5363 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005364 enforceModifyPermission();
5365 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005366 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5367 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5368 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005369 }
5370 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005371 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5372 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005373 }
5374
5375 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5376 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 final long identity = Binder.clearCallingIdentity();
5378 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005379 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 return "";
5381 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005384 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5385 null /* workSource */);
5386 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 // Append the returned status code to the end of the response payload.
5389 String s = Integer.toHexString(
5390 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5391 if (response.payload != null) {
5392 s = IccUtils.bytesToHexString(response.payload) + s;
5393 }
5394 return s;
5395 } finally {
5396 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005397 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005398 }
Jake Hambye994d462014-02-03 13:10:13 -08005399
Evan Charltonc66da362014-05-16 14:06:40 -07005400 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005401 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5402 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5404 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005406 if (DBG) {
5407 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5408 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5409 }
5410 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5411 cla, command, p1, p2, p3, data);
5412 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005413
Jordan Liu4c733742019-02-28 12:03:40 -08005414 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005415 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5416 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005417 enforceModifyPermission();
5418 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5419 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005420 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5421 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5422 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005423 }
5424
5425 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005426 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5427 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005428 }
5429
5430 // open APDU basic channel assuming the caller has sufficient permissions
5431 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5432 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433 final long identity = Binder.clearCallingIdentity();
5434 try {
5435 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5436 && TextUtils.equals(ISDR_AID, data)) {
5437 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005438 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5439 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 if (bestComponent == null
5441 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5442 loge("The calling package is not allowed to select ISD-R.");
5443 throw new SecurityException(
5444 "The calling package is not allowed to select ISD-R.");
5445 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005446 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005449 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5450 null /* workSource */);
5451 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453 // Append the returned status code to the end of the response payload.
5454 String s = Integer.toHexString(
5455 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5456 if (response.payload != null) {
5457 s = IccUtils.bytesToHexString(response.payload) + s;
5458 }
5459 return s;
5460 } finally {
5461 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005462 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005463 }
5464
5465 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005466 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005467 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5469 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 final long identity = Binder.clearCallingIdentity();
5472 try {
5473 if (DBG) {
5474 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5475 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5476 }
5477
5478 IccIoResult response =
5479 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5480 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5481 subId);
5482
5483 if (DBG) {
5484 log("Exchange SIM_IO [R]" + response);
5485 }
5486
5487 byte[] result = null;
5488 int length = 2;
5489 if (response.payload != null) {
5490 length = 2 + response.payload.length;
5491 result = new byte[length];
5492 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5493 } else {
5494 result = new byte[length];
5495 }
5496
5497 result[length - 1] = (byte) response.sw2;
5498 result[length - 2] = (byte) response.sw1;
5499 return result;
5500 } finally {
5501 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005502 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005503 }
5504
Nathan Haroldb3014052017-01-25 15:57:32 -08005505 /**
5506 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5507 * on a particular subscription
5508 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005509 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5510 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005511 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005512 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005513 return null;
5514 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515
5516 final long identity = Binder.clearCallingIdentity();
5517 try {
5518 if (appType != TelephonyManager.APPTYPE_USIM
5519 && appType != TelephonyManager.APPTYPE_SIM) {
5520 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5521 return null;
5522 }
5523 Object response = sendRequest(
5524 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5525 if (response instanceof String[]) {
5526 return (String[]) response;
5527 }
yincheng zhao2737e882019-09-06 17:06:54 -07005528 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005530 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 } finally {
5532 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005533 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005534 }
5535
yincheng zhao2737e882019-09-06 17:06:54 -07005536 /**
5537 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5538 * subscription.
5539 *
5540 * @param subId the id of the subscription.
5541 * @param appType the uicc app type, must be USIM or SIM.
5542 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5543 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005544 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005545 * @return number of fplmns that is successfully written to the SIM.
5546 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005547 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5548 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5550 mApp, subId, "setForbiddenPlmns");
5551
yincheng zhao2737e882019-09-06 17:06:54 -07005552 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5553 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5554 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5555 }
5556 if (fplmns == null) {
5557 throw new IllegalArgumentException("Fplmn List provided is null");
5558 }
5559 for (String fplmn : fplmns) {
5560 if (!CellIdentity.isValidPlmn(fplmn)) {
5561 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5562 }
5563 }
5564 final long identity = Binder.clearCallingIdentity();
5565 try {
5566 Object response = sendRequest(
5567 CMD_SET_FORBIDDEN_PLMNS,
5568 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5569 subId);
5570 return (int) response;
5571 } finally {
5572 Binder.restoreCallingIdentity(identity);
5573 }
5574 }
5575
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005576 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005577 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5579 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5584 if (response.payload == null) {
5585 return "";
5586 }
Evan Charltonc66da362014-05-16 14:06:40 -07005587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 // Append the returned status code to the end of the response payload.
5589 String s = Integer.toHexString(
5590 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5591 s = IccUtils.bytesToHexString(response.payload) + s;
5592 return s;
5593 } finally {
5594 Binder.restoreCallingIdentity(identity);
5595 }
Evan Charltonc66da362014-05-16 14:06:40 -07005596 }
5597
Jake Hambye994d462014-02-03 13:10:13 -08005598 /**
5599 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5600 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5601 *
5602 * @param itemID the ID of the item to read
5603 * @return the NV item as a String, or null on error.
5604 */
5605 @Override
5606 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005607 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5609 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610
5611 final long identity = Binder.clearCallingIdentity();
5612 try {
5613 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005614 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5616 return value;
5617 } finally {
5618 Binder.restoreCallingIdentity(identity);
5619 }
Jake Hambye994d462014-02-03 13:10:13 -08005620 }
5621
5622 /**
5623 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5624 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5625 *
5626 * @param itemID the ID of the item to read
5627 * @param itemValue the value to write, as a String
5628 * @return true on success; false on any failure
5629 */
5630 @Override
5631 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005632 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5634 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5639 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005640 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5642 return success;
5643 } finally {
5644 Binder.restoreCallingIdentity(identity);
5645 }
Jake Hambye994d462014-02-03 13:10:13 -08005646 }
5647
5648 /**
5649 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5650 * Used for device configuration by some CDMA operators.
5651 *
5652 * @param preferredRoamingList byte array containing the new PRL
5653 * @return true on success; false on any failure
5654 */
5655 @Override
5656 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5658 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659
5660 final long identity = Binder.clearCallingIdentity();
5661 try {
5662 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5663 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5664 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5665 return success;
5666 } finally {
5667 Binder.restoreCallingIdentity(identity);
5668 }
Jake Hambye994d462014-02-03 13:10:13 -08005669 }
5670
5671 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005672 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005673 * Used for device configuration by some CDMA operators.
5674 *
chen xu6dac5ab2018-10-26 17:39:23 -07005675 * @param slotIndex - device slot.
5676 *
Jake Hambye994d462014-02-03 13:10:13 -08005677 * @return true on success; false on any failure
5678 */
5679 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005680 public boolean resetModemConfig(int slotIndex) {
5681 Phone phone = PhoneFactory.getPhone(slotIndex);
5682 if (phone != null) {
5683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5684 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685
chen xu6dac5ab2018-10-26 17:39:23 -07005686 final long identity = Binder.clearCallingIdentity();
5687 try {
5688 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5689 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5690 return success;
5691 } finally {
5692 Binder.restoreCallingIdentity(identity);
5693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 }
chen xu6dac5ab2018-10-26 17:39:23 -07005695 return false;
5696 }
5697
5698 /**
5699 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5700 *
5701 * @param slotIndex - device slot.
5702 *
5703 * @return true on success; false on any failure
5704 */
5705 @Override
5706 public boolean rebootModem(int slotIndex) {
5707 Phone phone = PhoneFactory.getPhone(slotIndex);
5708 if (phone != null) {
5709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5710 mApp, phone.getSubId(), "rebootModem");
5711
5712 final long identity = Binder.clearCallingIdentity();
5713 try {
5714 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5715 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5716 return success;
5717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
5720 }
5721 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005722 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005723
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005724 public String[] getPcscfAddress(String apnType, String callingPackage,
5725 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005726 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005727 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5728 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005729 return new String[0];
5730 }
5731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 final long identity = Binder.clearCallingIdentity();
5733 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005734 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735 } finally {
5736 Binder.restoreCallingIdentity(identity);
5737 }
Wink Saville36469e72014-06-11 15:17:00 -07005738 }
5739
Brad Ebinger51f743a2017-01-23 13:50:20 -08005740 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005741 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5742 * {@link #disableIms(int)}.
5743 * @param slotIndex device slot.
5744 */
5745 public void resetIms(int slotIndex) {
5746 enforceModifyPermission();
5747
5748 final long identity = Binder.clearCallingIdentity();
5749 try {
5750 if (mImsResolver == null) {
5751 // may happen if the does not support IMS.
5752 return;
5753 }
5754 mImsResolver.disableIms(slotIndex);
5755 mImsResolver.enableIms(slotIndex);
5756 } finally {
5757 Binder.restoreCallingIdentity(identity);
5758 }
5759 }
5760
5761 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005762 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5763 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005764 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005765 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005766 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767
5768 final long identity = Binder.clearCallingIdentity();
5769 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005770 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005771 // may happen if the device does not support IMS.
5772 return;
5773 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005774 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005778 }
5779
5780 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005781 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5782 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005783 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005784 public void disableIms(int slotId) {
5785 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786
5787 final long identity = Binder.clearCallingIdentity();
5788 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005790 // may happen if the device does not support IMS.
5791 return;
5792 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005793 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005797 }
5798
5799 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005800 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5801 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005802 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005803 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005804 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005805 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806
5807 final long identity = Binder.clearCallingIdentity();
5808 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005809 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005810 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5811 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005812 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005813 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814 } finally {
5815 Binder.restoreCallingIdentity(identity);
5816 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005817 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005818 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005819 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5820 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005821 @Override
5822 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005823 enforceModifyPermission();
5824
5825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005828 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005829 } finally {
5830 Binder.restoreCallingIdentity(identity);
5831 }
5832 }
5833
5834 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005835 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005836 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005837 */
5838 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5839 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840
5841 final long identity = Binder.clearCallingIdentity();
5842 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005843 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005844 // may happen if the device does not support IMS.
5845 return null;
5846 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005847 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848 } finally {
5849 Binder.restoreCallingIdentity(identity);
5850 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005851 }
5852
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005853 /**
5854 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005855 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005856 */
5857 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5858 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859
5860 final long identity = Binder.clearCallingIdentity();
5861 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005862 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005863 // may happen if the device does not support IMS.
5864 return null;
5865 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005866 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005867 } finally {
5868 Binder.restoreCallingIdentity(identity);
5869 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005870 }
5871
Brad Ebinger884c07b2018-02-15 16:17:40 -08005872 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005873 * Sets the ImsService Package Name that Telephony will bind to.
5874 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005875 * @param slotIndex the slot ID that the ImsService should bind for.
5876 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005877 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005878 * @param featureTypes An integer array of feature types associated with a packageName.
5879 * @param packageName The name of the package that the current configuration will be replaced
5880 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005881 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005882 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005883 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5884 int[] featureTypes, String packageName) {
5885 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5886 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5888 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005889 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 final long identity = Binder.clearCallingIdentity();
5892 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005893 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005894 // may happen if the device does not support IMS.
5895 return false;
5896 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005897 Map<Integer, String> featureConfig = new HashMap<>();
5898 for (int featureType : featureTypes) {
5899 featureConfig.put(featureType, packageName);
5900 }
5901 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5902 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005906 }
5907
5908 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005909 * Clears any carrier ImsService overrides for the slot index specified that were previously
5910 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5911 *
5912 * This should only be used for testing.
5913 *
5914 * @param slotIndex the slot ID that the ImsService should bind for.
5915 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5916 */
5917 @Override
5918 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5919 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5920 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5921 "clearCarrierImsServiceOverride");
5922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5923 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5924 "clearCarrierImsServiceOverride");
5925
5926 final long identity = Binder.clearCallingIdentity();
5927 try {
5928 if (mImsResolver == null) {
5929 // may happen if the device does not support IMS.
5930 return false;
5931 }
5932 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5933 } finally {
5934 Binder.restoreCallingIdentity(identity);
5935 }
5936 }
5937
5938 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005939 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005940 *
5941 * @param slotId The slot that the ImsService is associated with.
5942 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5943 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005944 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005945 * @return the package name of the ImsService configuration.
5946 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005947 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5948 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005949 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005950 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005951 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005952 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5953 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 final long identity = Binder.clearCallingIdentity();
5956 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005957 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005958 // may happen if the device does not support IMS.
5959 return "";
5960 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005961 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005962 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5963 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964 } finally {
5965 Binder.restoreCallingIdentity(identity);
5966 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005967 }
5968
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005969 /**
5970 * Get the MmTelFeature state associated with the requested subscription id.
5971 * @param subId The subscription that the MmTelFeature is associated with.
5972 * @param callback A callback with an integer containing the
5973 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5974 */
5975 @Override
5976 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5977 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5978 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5979 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5980 "IMS not available on device.");
5981 }
5982 final long token = Binder.clearCallingIdentity();
5983 try {
5984 int slotId = getSlotIndex(subId);
5985 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5986 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5987 + subId + "'");
5988 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5989 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005990 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005991 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5992 try {
5993 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5994 } catch (RemoteException e) {
5995 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5996 + "Ignore");
5997 }
5998 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005999 } catch (ImsException e) {
6000 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006001 } finally {
6002 Binder.restoreCallingIdentity(token);
6003 }
6004 }
6005
Daniel Brightbb5840b2021-01-12 15:48:18 -08006006 /**
6007 * Sets the ims registration state on all valid {@link Phone}s.
6008 */
6009 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006010 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011
6012 final long identity = Binder.clearCallingIdentity();
6013 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006014 // NOTE: Before S, this method only set the default phone.
6015 for (final Phone phone : PhoneFactory.getPhones()) {
6016 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6017 phone.setImsRegistrationState(registered);
6018 }
6019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 } finally {
6021 Binder.restoreCallingIdentity(identity);
6022 }
Wink Saville36469e72014-06-11 15:17:00 -07006023 }
6024
6025 /**
Stuart Scott54788802015-03-30 13:18:01 -07006026 * Set the network selection mode to automatic.
6027 *
6028 */
6029 @Override
6030 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6032 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033
6034 final long identity = Binder.clearCallingIdentity();
6035 try {
shilufc958392020-01-20 11:36:01 -08006036 if (!isActiveSubscription(subId)) {
6037 return;
6038 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006040 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6041 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 } finally {
6043 Binder.restoreCallingIdentity(identity);
6044 }
Stuart Scott54788802015-03-30 13:18:01 -07006045 }
6046
Jack Yud10cdd42020-09-28 20:28:01 -07006047 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006048 * Ask the radio to connect to the input network and change selection mode to manual.
6049 *
6050 * @param subId the id of the subscription.
6051 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6052 * the operator to attach to.
6053 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6054 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6055 * normal network selection next time.
6056 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006057 */
6058 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006059 public boolean setNetworkSelectionModeManual(
6060 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6062 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006063
6064 if (!isActiveSubscription(subId)) {
6065 return false;
6066 }
6067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 final long identity = Binder.clearCallingIdentity();
6069 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006070 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006072 if (DBG) {
6073 log("setNetworkSelectionModeManual: subId: " + subId
6074 + " operator: " + operatorInfo);
6075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6077 } finally {
6078 Binder.restoreCallingIdentity(identity);
6079 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006080 }
shilu84f6e8b2019-12-19 13:58:01 -08006081 /**
6082 * Get the manual network selection
6083 *
6084 * @param subId the id of the subscription.
6085 *
6086 * @return the previously saved user selected PLMN
6087 */
6088 @Override
6089 public String getManualNetworkSelectionPlmn(int subId) {
6090 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006091 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006092 mApp, subId, "getManualNetworkSelectionPlmn");
6093
6094 final long identity = Binder.clearCallingIdentity();
6095 try {
6096 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006097 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006098 }
6099
6100 final Phone phone = getPhone(subId);
6101 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006102 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006103 }
6104 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6105 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6106 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6107 } finally {
6108 Binder.restoreCallingIdentity(identity);
6109 }
6110 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006111
6112 /**
6113 * Scans for available networks.
6114 */
6115 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006116 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6117 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6119 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006120 LocationAccessPolicy.LocationPermissionResult locationResult =
6121 LocationAccessPolicy.checkLocationPermission(mApp,
6122 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6123 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006124 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006125 .setCallingPid(Binder.getCallingPid())
6126 .setCallingUid(Binder.getCallingUid())
6127 .setMethod("getCellNetworkScanResults")
6128 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006129 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6130 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006131 .build());
6132 switch (locationResult) {
6133 case DENIED_HARD:
6134 throw new SecurityException("Not allowed to access scan results -- location");
6135 case DENIED_SOFT:
6136 return null;
6137 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138
Pengquan Menga1bb6272018-09-06 09:59:22 -07006139 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140 try {
6141 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006142 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006147 }
6148
6149 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006150 * Get the call forwarding info, given the call forwarding reason.
6151 */
6152 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006153 public void getCallForwarding(int subId, int callForwardingReason,
6154 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006155 enforceReadPrivilegedPermission("getCallForwarding");
6156 long identity = Binder.clearCallingIdentity();
6157 try {
6158 if (DBG) {
6159 log("getCallForwarding: subId " + subId
6160 + " callForwardingReason" + callForwardingReason);
6161 }
Hall Liu27d24262020-09-18 19:04:59 -07006162
6163 Phone phone = getPhone(subId);
6164 if (phone == null) {
6165 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006166 callback.onError(
6167 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006168 } catch (RemoteException e) {
6169 // ignore
6170 }
6171 return;
6172 }
6173
6174 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6175 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6176 @Override
6177 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6178 try {
6179 callback.onCallForwardingInfoAvailable(info);
6180 } catch (RemoteException e) {
6181 // ignore
6182 }
6183 }
6184
6185 @Override
6186 public void onError(int error) {
6187 try {
6188 callback.onError(error);
6189 } catch (RemoteException e) {
6190 // ignore
6191 }
6192 }
6193 });
6194 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006195 } finally {
6196 Binder.restoreCallingIdentity(identity);
6197 }
6198 }
6199
6200 /**
6201 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6202 * reason, the number to forward, and the timeout before the forwarding is attempted.
6203 */
6204 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006205 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6206 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006207 enforceModifyPermission();
6208 long identity = Binder.clearCallingIdentity();
6209 try {
6210 if (DBG) {
6211 log("setCallForwarding: subId " + subId
6212 + " callForwardingInfo" + callForwardingInfo);
6213 }
Hall Liu27d24262020-09-18 19:04:59 -07006214
6215 Phone phone = getPhone(subId);
6216 if (phone == null) {
6217 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006218 callback.accept(
6219 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006220 } catch (RemoteException e) {
6221 // ignore
6222 }
6223 return;
6224 }
6225
6226 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6227 FunctionalUtils.ignoreRemoteException(callback::accept));
6228
6229 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006230 } finally {
6231 Binder.restoreCallingIdentity(identity);
6232 }
6233 }
6234
6235 /**
Hall Liu27d24262020-09-18 19:04:59 -07006236 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006237 */
6238 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006239 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006240 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006241 long identity = Binder.clearCallingIdentity();
6242 try {
Hall Liu27d24262020-09-18 19:04:59 -07006243 Phone phone = getPhone(subId);
6244 if (phone == null) {
6245 try {
6246 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6247 } catch (RemoteException e) {
6248 // ignore
6249 }
6250 return;
6251 }
SongFerngWang0e767992021-03-31 22:08:45 +08006252 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6253 PersistableBundle c = configManager.getConfigForSubId(subId);
6254 boolean requireUssd = c.getBoolean(
6255 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006256
Shuo Qian4a594052020-01-23 11:59:30 -08006257 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006258 if (requireUssd) {
6259 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6260 getSubscriptionCarrierId(subId));
6261 String newUssdCommand = "";
6262 try {
6263 newUssdCommand = carrierXmlParser.getFeature(
6264 CarrierXmlParser.FEATURE_CALL_WAITING)
6265 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6266 } catch (NullPointerException e) {
6267 loge("Failed to generate USSD number" + e);
6268 }
6269 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6270 mMainThreadHandler, callback, carrierXmlParser,
6271 CarrierXmlParser.SsEntry.SSAction.QUERY);
6272 final String ussdCommand = newUssdCommand;
6273 Executors.newSingleThreadExecutor().execute(() -> {
6274 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6275 });
6276 } else {
6277 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6278 callback::accept);
6279 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6280 }
Shuo Qian4a594052020-01-23 11:59:30 -08006281 } finally {
6282 Binder.restoreCallingIdentity(identity);
6283 }
6284 }
6285
6286 /**
Hall Liu27d24262020-09-18 19:04:59 -07006287 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006288 */
6289 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006290 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006291 enforceModifyPermission();
6292 long identity = Binder.clearCallingIdentity();
6293 try {
Hall Liu27d24262020-09-18 19:04:59 -07006294 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6295
6296 Phone phone = getPhone(subId);
6297 if (phone == null) {
6298 try {
6299 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6300 } catch (RemoteException e) {
6301 // ignore
6302 }
6303 return;
6304 }
6305
SongFerngWang0e767992021-03-31 22:08:45 +08006306 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6307 PersistableBundle c = configManager.getConfigForSubId(subId);
6308 boolean requireUssd = c.getBoolean(
6309 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006310
SongFerngWang0e767992021-03-31 22:08:45 +08006311 if (DBG) log("getCallWaitingStatus: subId " + subId);
6312 if (requireUssd) {
6313 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6314 getSubscriptionCarrierId(subId));
6315 CarrierXmlParser.SsEntry.SSAction ssAction =
6316 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6317 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6318 String newUssdCommand = "";
6319 try {
6320 newUssdCommand = carrierXmlParser.getFeature(
6321 CarrierXmlParser.FEATURE_CALL_WAITING)
6322 .makeCommand(ssAction, null);
6323 } catch (NullPointerException e) {
6324 loge("Failed to generate USSD number" + e);
6325 }
6326 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6327 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6328 final String ussdCommand = newUssdCommand;
6329 Executors.newSingleThreadExecutor().execute(() -> {
6330 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6331 });
6332 } else {
6333 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6334 FunctionalUtils.ignoreRemoteException(callback::accept));
6335
6336 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6337 }
Shuo Qian4a594052020-01-23 11:59:30 -08006338 } finally {
6339 Binder.restoreCallingIdentity(identity);
6340 }
6341 }
6342
6343 /**
yinxub1bed742017-04-17 11:45:04 -07006344 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006345 *
yinxub1bed742017-04-17 11:45:04 -07006346 * @param subId id of the subscription
6347 * @param request contains the radio access networks with bands/channels to scan
6348 * @param messenger callback messenger for scan results or errors
6349 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006350 * @return the id of the requested scan which can be used to stop the scan.
6351 */
6352 @Override
6353 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006354 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6356 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006357 LocationAccessPolicy.LocationPermissionResult locationResult =
6358 LocationAccessPolicy.checkLocationPermission(mApp,
6359 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6360 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006361 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006362 .setCallingPid(Binder.getCallingPid())
6363 .setCallingUid(Binder.getCallingUid())
6364 .setMethod("requestNetworkScan")
6365 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006366 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6367 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006368 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006369 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006370 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6371 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006372 if (e != null) {
6373 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6374 throw e;
6375 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006376 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006377 return TelephonyScanManager.INVALID_SCAN_ID;
6378 }
6379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 }
Hall Liu912dfd32019-04-25 14:02:26 -07006381 int callingUid = Binder.getCallingUid();
6382 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006383 final long identity = Binder.clearCallingIdentity();
6384 try {
6385 return mNetworkScanRequestTracker.startNetworkScan(
6386 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006387 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006388 } finally {
6389 Binder.restoreCallingIdentity(identity);
6390 }
yinxu504e1392017-04-12 16:03:22 -07006391 }
6392
Hall Liub2ac8ef2019-02-28 15:56:23 -08006393 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006394 NetworkScanRequest request, int subId, String callingPackage) {
6395 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006396 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6397 boolean hasNetworkScanPermission =
6398 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6399 == PERMISSION_GRANTED;
6400
6401 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6402 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6403 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006404 }
6405
6406 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6407 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006408 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6409 return new SecurityException("Specific channels must not be"
6410 + " scanned without location access.");
6411 }
6412 }
6413 }
6414
Hall Liub2ac8ef2019-02-28 15:56:23 -08006415 return null;
6416 }
6417
yinxu504e1392017-04-12 16:03:22 -07006418 /**
6419 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006420 *
6421 * @param subId id of the subscription
6422 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006423 */
6424 @Override
6425 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6427 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428
Hall Liu912dfd32019-04-25 14:02:26 -07006429 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006430 final long identity = Binder.clearCallingIdentity();
6431 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006432 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
yinxu504e1392017-04-12 16:03:22 -07006436 }
6437
6438 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006439 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006440 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006441 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006442 */
6443 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006444 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006445 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006446 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006447 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006448
6449 final long identity = Binder.clearCallingIdentity();
6450 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006451 if (DBG) log("getAllowedNetworkTypesBitmask");
6452 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6453 int networkTypesBitmask = (result != null ? result[0] : -1);
6454 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6455 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006456 } finally {
6457 Binder.restoreCallingIdentity(identity);
6458 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006459 }
6460
6461 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006462 * Get the allowed network types for certain reason.
6463 *
6464 * @param subId the id of the subscription.
6465 * @param reason the reason the allowed network type change is taking place
6466 * @return the allowed network types.
6467 */
6468 @Override
6469 public long getAllowedNetworkTypesForReason(int subId,
6470 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006471 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006472 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006473 final long identity = Binder.clearCallingIdentity();
6474 try {
6475 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6476 } finally {
6477 Binder.restoreCallingIdentity(identity);
6478 }
6479 }
6480
6481 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006482 * Enable/Disable E-UTRA-NR Dual Connectivity
6483 * @param subId subscription id of the sim card
6484 * @param nrDualConnectivityState expected NR dual connectivity state
6485 * This can be passed following states
6486 * <ol>
6487 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6488 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6489 * <li>Disable NR dual connectivity and force secondary cell to be released
6490 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6491 * </ol>
6492 * @return operation result.
6493 */
6494 @Override
6495 public int setNrDualConnectivityState(int subId,
6496 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6498 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006499 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006500 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6501 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6502 }
6503
Sooraj Sasindran37444802020-08-11 10:40:43 -07006504 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6505 final long identity = Binder.clearCallingIdentity();
6506 try {
6507 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6508 nrDualConnectivityState, subId,
6509 workSource);
6510 if (DBG) log("enableNRDualConnectivity result: " + result);
6511 return result;
6512 } finally {
6513 Binder.restoreCallingIdentity(identity);
6514 }
6515 }
6516
6517 /**
6518 * Is E-UTRA-NR Dual Connectivity enabled
6519 * @return true if dual connectivity is enabled else false
6520 */
6521 @Override
6522 public boolean isNrDualConnectivityEnabled(int subId) {
6523 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006524 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006525 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006526 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006527 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6528 return false;
6529 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006530 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6531 final long identity = Binder.clearCallingIdentity();
6532 try {
6533 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6534 null, subId, workSource);
6535 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6536 return isEnabled;
6537 } finally {
6538 Binder.restoreCallingIdentity(identity);
6539 }
6540 }
6541
6542 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006543 * Set the allowed network types of the device and
6544 * provide the reason triggering the allowed network change.
6545 *
6546 * @param subId the id of the subscription.
6547 * @param reason the reason the allowed network type change is taking place
6548 * @param allowedNetworkTypes the allowed network types.
6549 * @return true on success; false on any failure.
6550 */
6551 @Override
6552 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006553 @TelephonyManager.AllowedNetworkTypesReason int reason,
6554 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6556 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006557 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006558 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6559 return false;
6560 }
6561 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6562 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006563 return false;
6564 }
6565
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006566 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6567 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6568
6569
6570 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6571 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6572 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006573 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006574
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006575 final long identity = Binder.clearCallingIdentity();
6576 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006577 Boolean success = (Boolean) sendRequest(
6578 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6579 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6580
6581 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6582 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006583 } finally {
6584 Binder.restoreCallingIdentity(identity);
6585 }
6586 }
6587
6588 /**
Miaoa84611c2019-03-15 09:21:10 +08006589 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006590 *
Miaoa84611c2019-03-15 09:21:10 +08006591 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006592 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006593 * @hide
6594 */
6595 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006596 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006597 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006599 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600 try {
Miaoa84611c2019-03-15 09:21:10 +08006601 if (phone != null) {
6602 return phone.hasMatchedTetherApnSetting();
6603 } else {
6604 return false;
6605 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606 } finally {
6607 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006608 }
Junda Liu475951f2014-11-07 16:45:03 -08006609 }
6610
6611 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006612 * Get the user enabled state of Mobile Data.
6613 *
6614 * TODO: remove and use isUserDataEnabled.
6615 * This can't be removed now because some vendor codes
6616 * calls through ITelephony directly while they should
6617 * use TelephonyManager.
6618 *
6619 * @return true on enabled
6620 */
6621 @Override
6622 public boolean getDataEnabled(int subId) {
6623 return isUserDataEnabled(subId);
6624 }
6625
6626 /**
6627 * Get whether mobile data is enabled per user setting.
6628 *
6629 * There are other factors deciding whether mobile data is actually enabled, but they are
6630 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006631 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006632 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6633 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006634 *
6635 * @return {@code true} if data is enabled else {@code false}
6636 */
6637 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006638 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006639 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006640 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006641 try {
6642 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6643 functionName);
6644 } catch (Exception e) {
6645 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6646 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006647 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006649 mApp, subId, functionName);
6650
Robert Greenwalt646120a2014-05-23 11:54:03 -07006651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652
6653 final long identity = Binder.clearCallingIdentity();
6654 try {
6655 int phoneId = mSubscriptionController.getPhoneId(subId);
6656 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6657 Phone phone = PhoneFactory.getPhone(phoneId);
6658 if (phone != null) {
6659 boolean retVal = phone.isUserDataEnabled();
6660 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6661 return retVal;
6662 } else {
6663 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6664 return false;
6665 }
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006668 }
6669 }
6670
6671 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006672 * Checks if the device is capable of mobile data by considering whether whether the
6673 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6674 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006675 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006676 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006677 */
6678 @Override
6679 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006680 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006681 try {
6682 try {
6683 mApp.enforceCallingOrSelfPermission(
6684 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006685 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006686 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006687 try {
6688 mApp.enforceCallingOrSelfPermission(
6689 android.Manifest.permission.READ_PHONE_STATE,
6690 functionName);
6691 } catch (Exception e2) {
6692 mApp.enforceCallingOrSelfPermission(
6693 permission.READ_BASIC_PHONE_STATE, functionName);
6694 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006695 }
6696 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006697 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699
6700 final long identity = Binder.clearCallingIdentity();
6701 try {
6702 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703 Phone phone = PhoneFactory.getPhone(phoneId);
6704 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006705 boolean retVal;
6706 if (phone.isUsingNewDataStack()) {
6707 retVal = phone.getDataNetworkController().getDataSettingsManager()
6708 .isDataEnabled();
6709 } else {
6710 retVal = phone.getDataEnabledSettings().isDataEnabled();
6711 }
6712 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713 return retVal;
6714 } else {
6715 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6716 return false;
6717 }
6718 } finally {
6719 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006720 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006721 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006722
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006723 /**
6724 * Check if data is enabled for a specific reason
6725 * @param subId Subscription index
6726 * @param reason the reason the data enable change is taking place
6727 * @return {@code true} if the overall data is enabled; {@code false} if not.
6728 */
6729 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006730 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006731 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006732 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006733 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006734 try {
6735 mApp.enforceCallingOrSelfPermission(
6736 android.Manifest.permission.ACCESS_NETWORK_STATE,
6737 functionName);
6738 } catch (Exception e) {
6739 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6740 functionName);
6741 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006742 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006743 try {
6744 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006745 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006746 } catch (Exception e2) {
6747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006748 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006749 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006750 }
6751
6752
6753 final long identity = Binder.clearCallingIdentity();
6754 try {
6755 int phoneId = mSubscriptionController.getPhoneId(subId);
6756 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006757 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006758 + " reason=" + reason);
6759 }
6760 Phone phone = PhoneFactory.getPhone(phoneId);
6761 if (phone != null) {
6762 boolean retVal;
6763 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6764 retVal = phone.isUserDataEnabled();
6765 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006766 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006767 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006768 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006769 return retVal;
6770 } else {
6771 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006772 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006773 + subId + " retVal=false");
6774 }
6775 return false;
6776 }
6777 } finally {
6778 Binder.restoreCallingIdentity(identity);
6779 }
6780 }
6781
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006782 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006783 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006784 if (uid == Process.PHONE_UID) {
6785 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6786 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006787 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6788 }
6789
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006790 //load access rules from carrier configs, and check those as well: b/139133814
6791 SubscriptionController subController = SubscriptionController.getInstance();
6792 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6793 || subController == null) return privilegeFromSim;
6794
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006795 PackageManager pkgMgr = phone.getContext().getPackageManager();
6796 String[] packages = pkgMgr.getPackagesForUid(uid);
6797
6798 final long identity = Binder.clearCallingIdentity();
6799 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006800 int subId = phone.getSubId();
6801 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6802 // A test override is in place for the privileges for this subId, so don't try to
6803 // read the subscription privileges.
6804 return privilegeFromSim;
6805 }
6806 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006807 SubscriptionManager subManager = (SubscriptionManager)
6808 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6809 for (String pkg : packages) {
6810 if (subManager.canManageSubscription(subInfo, pkg)) {
6811 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6812 }
6813 }
6814 return privilegeFromSim;
6815 } finally {
6816 Binder.restoreCallingIdentity(identity);
6817 }
6818 }
6819
6820 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6821 String pkgName) {
6822 //load access rules from carrier configs, and check those as well: b/139133814
6823 SubscriptionController subController = SubscriptionController.getInstance();
6824 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6825 || subController == null) return privilegeFromSim;
6826
6827 final long identity = Binder.clearCallingIdentity();
6828 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006829 int subId = phone.getSubId();
6830 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6831 // A test override is in place for the privileges for this subId, so don't try to
6832 // read the subscription privileges.
6833 return privilegeFromSim;
6834 }
6835 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006836 SubscriptionManager subManager = (SubscriptionManager)
6837 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6838 return subManager.canManageSubscription(subInfo, pkgName)
6839 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6840 } finally {
6841 Binder.restoreCallingIdentity(identity);
6842 }
6843 }
6844
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006845 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006846 public int getCarrierPrivilegeStatus(int subId) {
6847 final Phone phone = getPhone(subId);
6848 if (phone == null) {
6849 loge("getCarrierPrivilegeStatus: Invalid subId");
6850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6851 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006852 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6853 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006854 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006855 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6856 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006857
6858 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006859 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006860 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006861 }
Junda Liu29340342014-07-10 15:23:27 -07006862
6863 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006864 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006865 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006866 final Phone phone = getPhone(subId);
6867 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006868 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006869 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6870 }
6871 UiccProfile profile =
6872 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6873 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006874 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006875 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6876 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006877 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006878 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006879 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006880 }
6881
6882 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006883 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006884 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006885 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006886 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006887 }
6888
6889 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006890 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6891 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006892 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006893 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6894 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006895 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006896 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006897 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006898 }
6899
6900 @Override
6901 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006902 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006903 if (TextUtils.isEmpty(pkgName))
6904 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006905 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6906 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006907 UiccPort port = UiccController.getInstance().getUiccPort(i);
6908 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006909 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006910 continue;
6911 }
6912
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006913 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006914 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006915 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006916 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6917 break;
6918 }
6919 }
6920
6921 return result;
Junda Liu29340342014-07-10 15:23:27 -07006922 }
Derek Tan89e89d42014-07-08 17:00:10 -07006923
6924 @Override
Junda Liue64de782015-04-16 17:19:16 -07006925 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006926 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006927 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6928 loge("phoneId " + phoneId + " is not valid.");
6929 return null;
6930 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006931 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6932 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006933 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006934 return null ;
6935 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006936 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006937 }
6938
Amith Yamasani6e118872016-02-19 12:53:51 -08006939 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006940 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006941 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006942 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006943 List<String> privilegedPackages = new ArrayList<>();
6944 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006945 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006946 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006947 if (port != null) {
6948 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006949 if (packages == null) {
6950 // Only check packages in user 0 for now
6951 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006952 PackageManager.MATCH_DISABLED_COMPONENTS
6953 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006954 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006955 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006956 }
6957 for (int p = packages.size() - 1; p >= 0; p--) {
6958 PackageInfo pkgInfo = packages.get(p);
6959 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006960 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6961 port.getCarrierPrivilegeStatus(pkgInfo),
6962 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006963 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006964 privilegedPackages.add(pkgInfo.packageName);
6965 }
6966 }
6967 }
6968 }
6969 return privilegedPackages;
6970 }
6971
chen xuf7e9fe82019-05-09 19:31:02 -07006972 @Override
6973 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006974 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6975
6976 final long identity = Binder.clearCallingIdentity();
6977
chen xuf7e9fe82019-05-09 19:31:02 -07006978 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006979 try {
6980 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6981 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6982 }
6983 } finally {
6984 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006985 }
6986 return privilegedPackages;
6987 }
6988
Wink Savilleb564aae2014-10-23 10:18:09 -07006989 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006990 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006991 UiccPort port = phone == null ? null : phone.getUiccPort();
6992 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006993 return null;
6994 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006995 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006996 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006997 return null;
6998 }
6999 return iccId;
7000 }
7001
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007002 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007003 public void setCallComposerStatus(int subId, int status) {
7004 enforceModifyPermission();
7005
7006 final long identity = Binder.clearCallingIdentity();
7007 try {
7008 Phone phone = getPhone(subId);
7009 if (phone != null) {
7010 Phone defaultPhone = phone.getImsPhone();
7011 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7012 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7013 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007014 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7015 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007016 }
7017 }
Shuo Qian284ae752020-12-22 19:10:14 -08007018 } catch (ImsException e) {
7019 throw new ServiceSpecificException(e.getCode());
7020 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007021 Binder.restoreCallingIdentity(identity);
7022 }
7023 }
7024
7025 @Override
7026 public int getCallComposerStatus(int subId) {
7027 enforceReadPrivilegedPermission("getCallComposerStatus");
7028
7029 final long identity = Binder.clearCallingIdentity();
7030 try {
7031 Phone phone = getPhone(subId);
7032 if (phone != null) {
7033 Phone defaultPhone = phone.getImsPhone();
7034 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7035 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7036 return imsPhone.getCallComposerStatus();
7037 }
7038 }
7039 } finally {
7040 Binder.restoreCallingIdentity(identity);
7041 }
7042 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7043 }
7044
7045 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007046 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7047 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007048 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007049 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 final long identity = Binder.clearCallingIdentity();
7052 try {
7053 final String iccId = getIccId(subId);
7054 final Phone phone = getPhone(subId);
7055 if (phone == null) {
7056 return false;
7057 }
7058 final String subscriberId = phone.getSubscriberId();
7059
7060 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007061 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 + subscriberId + " to " + number);
7063 }
7064
7065 if (TextUtils.isEmpty(iccId)) {
7066 return false;
7067 }
7068
7069 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7070
7071 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7072 if (alphaTag == null) {
7073 editor.remove(alphaTagPrefKey);
7074 } else {
7075 editor.putString(alphaTagPrefKey, alphaTag);
7076 }
7077
7078 // Record both the line number and IMSI for this ICCID, since we need to
7079 // track all merged IMSIs based on line number
7080 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7081 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7082 if (number == null) {
7083 editor.remove(numberPrefKey);
7084 editor.remove(subscriberPrefKey);
7085 } else {
7086 editor.putString(numberPrefKey, number);
7087 editor.putString(subscriberPrefKey, subscriberId);
7088 }
7089
7090 editor.commit();
7091 return true;
7092 } finally {
7093 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007094 }
Derek Tan7226c842014-07-02 17:42:23 -07007095 }
7096
7097 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007098 public String getLine1NumberForDisplay(int subId, String callingPackage,
7099 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007100 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007102 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007103 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007104 return null;
7105 }
Derek Tan97ebb422014-09-05 16:55:38 -07007106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 final long identity = Binder.clearCallingIdentity();
7108 try {
7109 String iccId = getIccId(subId);
7110 if (iccId != null) {
7111 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7112 if (DBG_MERGE) {
7113 log("getLine1NumberForDisplay returning "
7114 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7115 }
7116 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007117 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7119 return null;
7120 } finally {
7121 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007122 }
Derek Tan7226c842014-07-02 17:42:23 -07007123 }
7124
7125 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007126 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7127 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007129 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007130 return null;
7131 }
Derek Tan97ebb422014-09-05 16:55:38 -07007132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133 final long identity = Binder.clearCallingIdentity();
7134 try {
7135 String iccId = getIccId(subId);
7136 if (iccId != null) {
7137 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7138 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7139 }
7140 return null;
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007143 }
Derek Tan7226c842014-07-02 17:42:23 -07007144 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007145
7146 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007147 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7148 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007149 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7150 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007151 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007152 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007153 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007154 return null;
7155 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007156
Jordan Liub49b04b2019-05-06 14:45:15 -07007157 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7158 // the process, where TelephonyManager was instantiated.
7159 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007160 final long identity = Binder.clearCallingIdentity();
7161 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007162 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163 final TelephonyManager tele = TelephonyManager.from(context);
7164 final SubscriptionManager sub = SubscriptionManager.from(context);
7165
7166 // Figure out what subscribers are currently active
7167 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007168
Jordan Liub49b04b2019-05-06 14:45:15 -07007169 // Only consider subs which match the current subId
7170 // This logic can be simplified. See b/131189269 for progress.
7171 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007172 activeSubscriberIds.add(tele.getSubscriberId(subId));
7173 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174
7175 // First pass, find a number override for an active subscriber
7176 String mergeNumber = null;
7177 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7178 for (String key : prefs.keySet()) {
7179 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7180 final String subscriberId = (String) prefs.get(key);
7181 if (activeSubscriberIds.contains(subscriberId)) {
7182 final String iccId = key.substring(
7183 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7184 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7185 mergeNumber = (String) prefs.get(numberKey);
7186 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007187 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007188 + " for active subscriber " + subscriberId);
7189 }
7190 if (!TextUtils.isEmpty(mergeNumber)) {
7191 break;
7192 }
7193 }
7194 }
7195 }
7196
7197 // Shortcut when no active merged subscribers
7198 if (TextUtils.isEmpty(mergeNumber)) {
7199 return null;
7200 }
7201
7202 // Second pass, find all subscribers under that line override
7203 final ArraySet<String> result = new ArraySet<>();
7204 for (String key : prefs.keySet()) {
7205 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7206 final String number = (String) prefs.get(key);
7207 if (mergeNumber.equals(number)) {
7208 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7209 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7210 final String subscriberId = (String) prefs.get(subscriberKey);
7211 if (!TextUtils.isEmpty(subscriberId)) {
7212 result.add(subscriberId);
7213 }
7214 }
7215 }
7216 }
7217
7218 final String[] resultArray = result.toArray(new String[result.size()]);
7219 Arrays.sort(resultArray);
7220 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007221 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007222 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7223 }
7224 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007225 } finally {
7226 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007227 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007228 }
7229
7230 @Override
zoey chen38003472019-12-13 17:16:31 +08007231 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7232 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007233
7234 final long identity = Binder.clearCallingIdentity();
7235 try {
7236 final TelephonyManager telephonyManager = mApp.getSystemService(
7237 TelephonyManager.class);
7238 String subscriberId = telephonyManager.getSubscriberId(subId);
7239 if (subscriberId == null) {
7240 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007241 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007242 + subId);
7243 }
7244 return null;
7245 }
7246
7247 final SubscriptionInfo info = SubscriptionController.getInstance()
7248 .getSubscriptionInfo(subId);
7249 final ParcelUuid groupUuid = info.getGroupUuid();
7250 // If it doesn't belong to any group, return just subscriberId of itself.
7251 if (groupUuid == null) {
7252 return new String[]{subscriberId};
7253 }
7254
7255 // Get all subscriberIds from the group.
7256 final List<String> mergedSubscriberIds = new ArrayList<>();
7257 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007258 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007259 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007260 for (SubscriptionInfo subInfo : groupInfos) {
7261 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7262 if (subscriberId != null) {
7263 mergedSubscriberIds.add(subscriberId);
7264 }
7265 }
7266
7267 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7268 } finally {
7269 Binder.restoreCallingIdentity(identity);
7270
7271 }
7272 }
7273
7274 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007275 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007276 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007277 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278
7279 final long identity = Binder.clearCallingIdentity();
7280 try {
7281 final Phone phone = getPhone(subId);
7282 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7283 } finally {
7284 Binder.restoreCallingIdentity(identity);
7285 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007286 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007287
7288 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007289 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007290 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7291 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007292 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7293 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007294
7295 final long identity = Binder.clearCallingIdentity();
7296 try {
7297 final Phone phone = getPhone(subId);
7298 if (phone == null) {
7299 return false;
7300 }
7301 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7302 cdmaNonRoamingList);
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007305 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007306 }
7307
7308 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007309 @Deprecated
7310 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7311 enforceModifyPermission();
7312
7313 int returnValue = 0;
7314 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007315 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007316 if(result.exception == null) {
7317 if (result.result != null) {
7318 byte[] responseData = (byte[])(result.result);
7319 if(responseData.length > oemResp.length) {
7320 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7321 responseData.length + "bytes. Buffer Size is " +
7322 oemResp.length + "bytes.");
7323 }
7324 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7325 returnValue = responseData.length;
7326 }
7327 } else {
7328 CommandException ex = (CommandException) result.exception;
7329 returnValue = ex.getCommandError().ordinal();
7330 if(returnValue > 0) returnValue *= -1;
7331 }
7332 } catch (RuntimeException e) {
7333 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7334 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7335 if(returnValue > 0) returnValue *= -1;
7336 }
7337
7338 return returnValue;
7339 }
7340
7341 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007342 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007343 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007344 try {
7345 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007346 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007347 mApp, phone.getSubId(), "getRadioAccessFamily");
7348 } catch (SecurityException e) {
7349 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7350 throw e;
7351 }
chen xub97461a2018-10-26 14:17:57 -07007352 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007353 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007354 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007356 final long identity = Binder.clearCallingIdentity();
7357 try {
chen xub97461a2018-10-26 14:17:57 -07007358 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007359 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007360 mApp, phone.getSubId(), "getRadioAccessFamily");
7361 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007362 } finally {
7363 Binder.restoreCallingIdentity(identity);
7364 }
chen xub97461a2018-10-26 14:17:57 -07007365 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007366 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007367
7368 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007369 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007370 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007371 try {
7372 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7373 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007374 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007375 }
7376 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007377 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007378 }
7379 RoleManager rm = mApp.getSystemService(RoleManager.class);
7380 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7381 if (!dialerRoleHolders.contains(callingPackage)) {
7382 throw new SecurityException("App must be the dialer role holder to"
7383 + " upload a call composer pic");
7384 }
7385
7386 Executors.newSingleThreadExecutor().execute(() -> {
7387 ByteArrayOutputStream output = new ByteArrayOutputStream(
7388 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7389 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7390 boolean readUntilEnd = false;
7391 int totalBytesRead = 0;
7392 byte[] buffer = new byte[16 * 1024];
7393 while (true) {
7394 int numRead;
7395 try {
7396 numRead = input.read(buffer);
7397 } catch (IOException e) {
7398 try {
7399 fd.checkError();
7400 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7401 null);
7402 } catch (IOException e1) {
7403 // This means that the other side closed explicitly with an error. If this
7404 // happens, log and ignore.
7405 loge("Remote end of call composer picture pipe closed: " + e1);
7406 }
7407 break;
7408 }
7409 if (numRead == -1) {
7410 readUntilEnd = true;
7411 break;
7412 }
7413 totalBytesRead += numRead;
7414 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7415 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7416 try {
7417 input.close();
7418 } catch (IOException e) {
7419 // ignore
7420 }
7421 break;
7422 }
7423 output.write(buffer, 0, numRead);
7424 }
7425 // Generally, the remote end will close the file descriptors. The only case where we
7426 // close is above, where the picture size is too big.
7427
7428 try {
7429 fd.checkError();
7430 } catch (IOException e) {
7431 loge("Remote end for call composer closed with an error: " + e);
7432 return;
7433 }
7434
Hall Liuaa4211e2021-01-20 15:43:39 -08007435 if (!readUntilEnd) {
7436 loge("Did not finish reading entire image; aborting");
7437 return;
7438 }
Hall Liu82694d52020-12-11 18:22:04 -08007439
Hall Liuaa4211e2021-01-20 15:43:39 -08007440 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7441 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7442 new CallComposerPictureTransfer.Factory() {},
7443 imageData,
7444 (result) -> {
7445 if (result.first != null) {
7446 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7447 Bundle outputResult = new Bundle();
7448 outputResult.putParcelable(
7449 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7450 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7451 outputResult);
7452 } else {
7453 callback.send(result.second, null);
7454 }
7455 }
7456 );
Hall Liu82694d52020-12-11 18:22:04 -08007457 });
7458 }
7459
7460 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007461 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007462 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007463 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464
7465 final long identity = Binder.clearCallingIdentity();
7466 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007467 ImsManager.getInstance(defaultPhone.getContext(),
7468 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 } finally {
7470 Binder.restoreCallingIdentity(identity);
7471 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007472 }
7473
7474 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007475 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007476 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7478 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007479 return false;
7480 }
Svet Ganovb320e182015-04-16 12:30:10 -07007481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 final long identity = Binder.clearCallingIdentity();
7483 try {
7484 // Check the user preference and the system-level IMS setting. Even if the user has
7485 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7486 // In the long run, we may instead need to check if there exists a connection service
7487 // which can support video calling.
7488 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007489 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 return imsManager.isVtEnabledByPlatform()
7491 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7492 && imsManager.isVtEnabledByUser();
7493 } finally {
7494 Binder.restoreCallingIdentity(identity);
7495 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007496 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007497
Andrew Leea1239f22015-03-02 17:44:07 -08007498 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007499 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7500 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007502 mApp, subId, callingPackage, callingFeatureId,
7503 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 return false;
7505 }
7506
7507 final long identity = Binder.clearCallingIdentity();
7508 try {
7509 CarrierConfigManager configManager =
7510 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007511 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7513 } finally {
7514 Binder.restoreCallingIdentity(identity);
7515 }
Andrew Leea1239f22015-03-02 17:44:07 -08007516 }
7517
7518 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007519 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007521 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 return false;
7523 }
7524
7525 final long identity = Binder.clearCallingIdentity();
7526 try {
7527 CarrierConfigManager configManager =
7528 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007529 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7531 } finally {
7532 Binder.restoreCallingIdentity(identity);
7533 }
Andrew Leea1239f22015-03-02 17:44:07 -08007534 }
7535
Andrew Lee9431b832015-03-09 18:46:45 -07007536 @Override
7537 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007538 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007539 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007540 }
7541
7542 @Override
7543 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 final long identity = Binder.clearCallingIdentity();
7545 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007546 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 } finally {
7548 Binder.restoreCallingIdentity(identity);
7549 }
Andrew Lee9431b832015-03-09 18:46:45 -07007550 }
7551
Hall Liuf6668912018-10-31 17:05:23 -07007552 /**
7553 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7554 * support for the feature and device firmware support.
7555 *
7556 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7557 */
7558 @Override
7559 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007561 final Phone phone = getPhone(subscriptionId);
7562 if (phone == null) {
7563 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7564 return false;
7565 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007567 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7569 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007570 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007571 return isCarrierSupported && isDeviceSupported;
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
Hall Liu98187582018-01-22 19:15:32 -08007575 }
7576
Hall Liuf6668912018-10-31 17:05:23 -07007577 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007578 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7579 * RTT setting, will return true if the device and carrier both support RTT.
7580 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007581 */
7582 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 final long identity = Binder.clearCallingIdentity();
7584 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007585 boolean isRttSupported = isRttSupported(subscriptionId);
7586 boolean isUserRttSettingOn = Settings.Secure.getInt(
7587 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7588 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7589 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7590 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 } finally {
7592 Binder.restoreCallingIdentity(identity);
7593 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007594 }
7595
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007596 @Deprecated
7597 @Override
7598 public String getDeviceId(String callingPackage) {
7599 return getDeviceIdWithFeature(callingPackage, null);
7600 }
7601
Sanket Padawe7310cc72015-01-14 09:53:20 -08007602 /**
7603 * Returns the unique device ID of phone, for example, the IMEI for
7604 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7605 *
7606 * <p>Requires Permission:
7607 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7608 */
7609 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007610 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007611 try {
7612 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7613 } catch (SecurityException se) {
7614 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7615 throw new SecurityException("Package " + callingPackage + " does not belong to "
7616 + Binder.getCallingUid());
7617 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007618 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007619 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007620 return null;
7621 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007622 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007623 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007624 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007625 return null;
7626 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007627
7628 final long identity = Binder.clearCallingIdentity();
7629 try {
7630 return phone.getDeviceId();
7631 } finally {
7632 Binder.restoreCallingIdentity(identity);
7633 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007634 }
7635
Ping Sunc67b7c22016-03-02 19:16:45 +08007636 /**
7637 * {@hide}
7638 * Returns the IMS Registration Status on a particular subid
7639 *
7640 * @param subId
7641 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007642 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007643 Phone phone = getPhone(subId);
7644 if (phone != null) {
7645 return phone.isImsRegistered();
7646 } else {
7647 return false;
7648 }
7649 }
7650
Santos Cordon7a1885b2015-02-03 11:15:19 -08007651 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007652 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007653 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007654 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007655 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007656 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7657 }
7658 final long identity = Binder.clearCallingIdentity();
7659 try {
7660 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7661 } finally {
7662 Binder.restoreCallingIdentity(identity);
7663 }
7664 }
7665
7666 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007667 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007668 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007669 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007670 mApp,
7671 subscriptionId,
7672 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007673 final long identity = Binder.clearCallingIdentity();
7674 try {
7675 Phone phone = getPhone(subscriptionId);
7676 if (phone == null) {
7677 return null;
7678 }
7679 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7680 } finally {
7681 Binder.restoreCallingIdentity(identity);
7682 }
7683 }
7684
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007685 /**
7686 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007687 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007688 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007689 final long identity = Binder.clearCallingIdentity();
7690 try {
7691 Phone phone = getPhone(subId);
7692 if (phone != null) {
7693 return phone.isWifiCallingEnabled();
7694 } else {
7695 return false;
7696 }
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007699 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007700 }
7701
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007702 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007703 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007704 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007705 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007706 final long identity = Binder.clearCallingIdentity();
7707 try {
7708 Phone phone = getPhone(subId);
7709 if (phone != null) {
7710 return phone.isVideoEnabled();
7711 } else {
7712 return false;
7713 }
7714 } finally {
7715 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007716 }
7717 }
7718
7719 /**
7720 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7721 * defined in {@link ImsRegistrationImplBase}.
7722 */
7723 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724 final long identity = Binder.clearCallingIdentity();
7725 try {
7726 Phone phone = getPhone(subId);
7727 if (phone != null) {
7728 return phone.getImsRegistrationTech();
7729 } else {
7730 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7731 }
7732 } finally {
7733 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007734 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007735 }
7736
Stuart Scott8eef64f2015-04-08 15:13:54 -07007737 @Override
7738 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007739 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007740 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7741 return;
7742 }
Kai Shif70f46f2021-03-03 13:59:46 -08007743 Phone defaultPhone = getDefaultPhone();
7744 if (defaultPhone != null) {
7745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7746 mApp, getDefaultPhone().getSubId(), "factoryReset");
7747 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007748 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007749
Svet Ganovcc087f82015-05-12 20:35:54 -07007750 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007751 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7752 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007753 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007754 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007755 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007756 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007757 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007758 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007759 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007760 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007761 // There has been issues when Sms raw table somehow stores orphan
7762 // fragments. They lead to garbled message when new fragments come
7763 // in and combined with those stale ones. In case this happens again,
7764 // user can reset all network settings which will clean up this table.
7765 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007766 // Clean up IMS settings as well here.
7767 int slotId = getSlotIndex(subId);
7768 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7769 ImsManager.getInstance(mApp, slotId).factoryReset();
7770 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007771
Kai Shif70f46f2021-03-03 13:59:46 -08007772 if (defaultPhone == null) {
7773 return;
7774 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007775 // Erase modem config if erase modem on network setting is enabled.
7776 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7777 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7778 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007779 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007780 }
Kai Shif70f46f2021-03-03 13:59:46 -08007781
7782 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007783 } finally {
7784 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007785 }
7786 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007787
SongFerngWangfd89b102021-05-27 22:44:54 +08007788 @VisibleForTesting
7789 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7790 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7791 return;
7792 }
7793 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7794 RILConstants.PREFERRED_NETWORK_MODE);
7795 SubscriptionManager.setSubscriptionProperty(subId,
7796 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7797 "user=" + defaultNetworkType);
7798 phone.loadAllowedNetworksFromSubscriptionDatabase();
7799 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7800 defaultNetworkType, null);
7801 }
7802
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007803 private void cleanUpSmsRawTable(Context context) {
7804 ContentResolver resolver = context.getContentResolver();
7805 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7806 resolver.delete(uri, null, null);
7807 }
7808
Narayan Kamath1c496c22015-04-16 14:40:19 +01007809 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007810 public String getSimLocaleForSubscriber(int subId) {
7811 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7812 final Phone phone = getPhone(subId);
7813 if (phone == null) {
7814 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007815 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007816 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007817 final long identity = Binder.clearCallingIdentity();
7818 try {
chen xu5d3637b2019-01-21 23:31:38 -08007819 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007820 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007821 if (info == null) {
7822 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7823 return null;
7824 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825 // Try and fetch the locale from the carrier properties or from the SIM language
7826 // preferences (EF-PL and EF-LI)...
7827 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007828 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007829 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7830 if (localeFromDefaultSim != null) {
7831 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7832 if (DBG) log("Using locale from subId: " + subId + " locale: "
7833 + localeFromDefaultSim);
7834 return localeFromDefaultSim.toLanguageTag();
7835 } else {
7836 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837 }
7838 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007840 // The SIM language preferences only store a language (e.g. fr = French), not an
7841 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7842 // the SIM and carrier preferences does not include a country we add the country
7843 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007844 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007846 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007847 return mccLocale.toLanguageTag();
7848 }
7849
7850 if (DBG) log("No locale found - returning null");
7851 return null;
7852 } finally {
7853 Binder.restoreCallingIdentity(identity);
7854 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007855 }
7856
7857 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007858 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007859 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007860 }
7861
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007862 /**
7863 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7864 */
7865 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007866 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007867 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007868 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007869
Chenjie Yu1ba97252018-01-11 18:16:20 -08007870 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007871 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007872
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007873 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007874 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7875 * representing the state of the modem.
7876 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007877 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7878 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007879 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007880 */
7881 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007882 public void requestModemActivityInfo(ResultReceiver result) {
7883 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007884 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885
7886 final long identity = Binder.clearCallingIdentity();
7887 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007888 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007889 } finally {
7890 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007891 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007892 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007893
Siddharth Rayb8114062018-06-17 15:02:38 -07007894 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7895 // less than total activity duration.
7896 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7897 if (info == null) {
7898 return false;
7899 }
7900 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007901 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7902 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7903
Siddharth Rayb8114062018-06-17 15:02:38 -07007904 return (info.isValid()
7905 && (info.getSleepTimeMillis() <= activityDurationMs)
7906 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007907 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007908 && (totalTxTimeMs <= activityDurationMs));
7909 }
7910
Jack Yu85bd38a2015-11-09 11:34:32 -08007911 /**
7912 * {@hide}
7913 * Returns the service state information on specified subscription.
7914 */
7915 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007916 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7917 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007919 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007920 return null;
7921 }
7922
Hall Liuf19c44f2018-11-27 14:38:17 -08007923 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7924 LocationAccessPolicy.checkLocationPermission(mApp,
7925 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7926 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007927 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007928 .setCallingPid(Binder.getCallingPid())
7929 .setCallingUid(Binder.getCallingUid())
7930 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007931 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007932 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007933 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7934 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007935 .build());
7936
7937 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7938 LocationAccessPolicy.checkLocationPermission(mApp,
7939 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7940 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007941 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007942 .setCallingPid(Binder.getCallingPid())
7943 .setCallingUid(Binder.getCallingUid())
7944 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007945 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007946 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007947 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7948 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007949 .build());
7950 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7951 boolean hasFinePermission =
7952 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7953 boolean hasCoarsePermission =
7954 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7955
Jack Yu479f40e2020-10-27 21:29:25 -07007956 final Phone phone = getPhone(subId);
7957 if (phone == null) {
7958 return null;
7959 }
7960
Jordan Liu0f2bc442020-11-18 16:47:37 -08007961 final long identity = Binder.clearCallingIdentity();
7962
Jack Yu479f40e2020-10-27 21:29:25 -07007963 boolean isCallingPackageDataService = phone.getDataServicePackages()
7964 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007965 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007966 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7967 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7968 Rlog.d(LOG_TAG,
7969 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7970 return null;
7971 }
7972
Hall Liuf19c44f2018-11-27 14:38:17 -08007973 ServiceState ss = phone.getServiceState();
7974
7975 // Scrub out the location info in ServiceState depending on what level of access
7976 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007977 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007978 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7979 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007980 } finally {
7981 Binder.restoreCallingIdentity(identity);
7982 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007983 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007984
7985 /**
7986 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7987 *
7988 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7989 * voicemail ringtone.
7990 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7991 * PhoneAccount.
7992 */
7993 @Override
7994 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007995 final long identity = Binder.clearCallingIdentity();
7996 try {
7997 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7998 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007999 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008000 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008001
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008002 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8003 } finally {
8004 Binder.restoreCallingIdentity(identity);
8005 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008006 }
8007
8008 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008009 * Sets the per-account voicemail ringtone.
8010 *
8011 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8012 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8013 *
8014 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8015 * voicemail ringtone.
8016 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8017 * PhoneAccount.
8018 */
8019 @Override
8020 public void setVoicemailRingtoneUri(String callingPackage,
8021 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008022 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008023 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008024 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8025 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8027 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8028 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008030
8031 final long identity = Binder.clearCallingIdentity();
8032 try {
8033 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8034 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008035 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008036 }
8037 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008040 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008041 }
8042
8043 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008044 * Returns whether vibration is set for voicemail notification in Phone settings.
8045 *
8046 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8047 * voicemail vibration setting.
8048 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8049 */
8050 @Override
8051 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052 final long identity = Binder.clearCallingIdentity();
8053 try {
8054 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8055 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008056 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008057 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008059 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8060 } finally {
8061 Binder.restoreCallingIdentity(identity);
8062 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008063 }
8064
Youhan Wange64578a2016-05-02 15:32:42 -07008065 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008066 * Sets the per-account voicemail vibration.
8067 *
8068 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8069 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8070 *
8071 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8072 * voicemail vibration setting.
8073 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8074 * specific PhoneAccount.
8075 */
8076 @Override
8077 public void setVoicemailVibrationEnabled(String callingPackage,
8078 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008079 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008080 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008081 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8082 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8084 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8085 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008086 }
8087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008088 final long identity = Binder.clearCallingIdentity();
8089 try {
8090 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8091 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008092 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093 }
8094 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8095 } finally {
8096 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008097 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008098 }
8099
8100 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008101 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8102 *
8103 * @throws SecurityException if the caller does not have the required permission
8104 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008105 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008106 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008107 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008108 }
8109
8110 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008111 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8112 * permission.
8113 *
8114 * @throws SecurityException if the caller does not have the required permission
8115 */
8116 private void enforceSendSmsPermission() {
8117 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8118 }
8119
8120 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008121 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008122 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008123 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008124 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008125 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126 final long identity = Binder.clearCallingIdentity();
8127 try {
8128 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008129 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008130 if (componentName == null) {
8131 throw new SecurityException(
8132 "Caller not current active visual voicemail package[null]");
8133 }
8134 String vvmPackage = componentName.getPackageName();
8135 if (!callingPackage.equals(vvmPackage)) {
8136 throw new SecurityException("Caller not current active visual voicemail package["
8137 + vvmPackage + "]");
8138 }
8139 } finally {
8140 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008141 }
8142 }
8143
8144 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008145 * Return the application ID for the app type.
8146 *
8147 * @param subId the subscription ID that this request applies to.
8148 * @param appType the uicc app type.
8149 * @return Application ID for specificied app type, or null if no uicc.
8150 */
8151 @Override
8152 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008153 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008154 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155
8156 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008157 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158 if (phone == null) {
8159 return null;
8160 }
8161 String aid = null;
8162 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008163 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008164 .getApplicationByType(appType).getAid();
8165 } catch (Exception e) {
8166 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8167 }
8168 return aid;
8169 } finally {
8170 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008171 }
Youhan Wange64578a2016-05-02 15:32:42 -07008172 }
8173
Youhan Wang4001d252016-05-11 10:29:41 -07008174 /**
8175 * Return the Electronic Serial Number.
8176 *
8177 * @param subId the subscription ID that this request applies to.
8178 * @return ESN or null if error.
8179 */
8180 @Override
8181 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008182 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008183 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184
8185 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008186 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008187 if (phone == null) {
8188 return null;
8189 }
8190 String esn = null;
8191 try {
8192 esn = phone.getEsn();
8193 } catch (Exception e) {
8194 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8195 }
8196 return esn;
8197 } finally {
8198 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008199 }
Youhan Wang4001d252016-05-11 10:29:41 -07008200 }
8201
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008202 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008203 * Return the Preferred Roaming List Version.
8204 *
8205 * @param subId the subscription ID that this request applies to.
8206 * @return PRLVersion or null if error.
8207 */
8208 @Override
8209 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008210 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008211 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008212
8213 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008214 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008215 if (phone == null) {
8216 return null;
8217 }
8218 String cdmaPrlVersion = null;
8219 try {
8220 cdmaPrlVersion = phone.getCdmaPrlVersion();
8221 } catch (Exception e) {
8222 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8223 }
8224 return cdmaPrlVersion;
8225 } finally {
8226 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008227 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008228 }
8229
8230 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008231 * Get snapshot of Telephony histograms
8232 * @return List of Telephony histograms
8233 * @hide
8234 */
8235 @Override
8236 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8238 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008239
8240 final long identity = Binder.clearCallingIdentity();
8241 try {
8242 return RIL.getTelephonyRILTimingHistograms();
8243 } finally {
8244 Binder.restoreCallingIdentity(identity);
8245 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008246 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008247
8248 /**
8249 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008250 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8251 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008252 * Require system privileges. In the future we may add this to carrier APIs.
8253 *
Michele Berionne482f8202018-11-27 18:57:59 -08008254 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008255 */
8256 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008257 @TelephonyManager.SetCarrierRestrictionResult
8258 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008259 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008260 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008261
Michele Berionne482f8202018-11-27 18:57:59 -08008262 if (carrierRestrictionRules == null) {
8263 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008264 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008266 final long identity = Binder.clearCallingIdentity();
8267 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008268 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008269 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270 } finally {
8271 Binder.restoreCallingIdentity(identity);
8272 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008273 }
8274
8275 /**
8276 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008277 * Get the allowed carrier list and the excluded carrier list, including the priority between
8278 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008279 * Require system privileges. In the future we may add this to carrier APIs.
8280 *
Michele Berionne482f8202018-11-27 18:57:59 -08008281 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008282 */
8283 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008284 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008285 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008286 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287
8288 final long identity = Binder.clearCallingIdentity();
8289 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008290 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8291 if (response instanceof CarrierRestrictionRules) {
8292 return (CarrierRestrictionRules) response;
8293 }
8294 // Response is an Exception of some kind,
8295 // which is signalled to the user as a NULL retval
8296 return null;
8297 } catch (Exception e) {
8298 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8299 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 } finally {
8301 Binder.restoreCallingIdentity(identity);
8302 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008303 }
8304
fionaxu59545b42016-05-25 15:53:37 -07008305 /**
fionaxu59545b42016-05-25 15:53:37 -07008306 * Action set from carrier signalling broadcast receivers to enable/disable radio
8307 * @param subId the subscription ID that this action applies to.
8308 * @param enabled control enable or disable radio.
8309 * {@hide}
8310 */
8311 @Override
8312 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8313 enforceModifyPermission();
8314 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315
8316 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008317 if (phone == null) {
8318 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8319 return;
8320 }
8321 try {
8322 phone.carrierActionSetRadioEnabled(enabled);
8323 } catch (Exception e) {
8324 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008325 } finally {
8326 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008327 }
8328 }
8329
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008330 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008331 * Enable or disable Voice over NR (VoNR)
8332 * @param subId the subscription ID that this action applies to.
8333 * @param enabled enable or disable VoNR.
8334 * @return operation result.
8335 */
8336 @Override
8337 public int setVoNrEnabled(int subId, boolean enabled) {
8338 enforceModifyPermission();
8339 final Phone phone = getPhone(subId);
8340
8341 final long identity = Binder.clearCallingIdentity();
8342 if (phone == null) {
8343 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8344 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8345 }
8346
8347 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8348 try {
8349 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8350 workSource);
8351 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008352
8353 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8354 if (DBG) {
8355 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8356 }
8357 SubscriptionManager.setSubscriptionProperty(
8358 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8359 (enabled ? "1" : "0"));
8360 }
8361
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008362 return result;
8363 } finally {
8364 Binder.restoreCallingIdentity(identity);
8365 }
8366 }
8367
8368 /**
8369 * Is voice over NR enabled
8370 * @return true if VoNR is enabled else false
8371 */
8372 @Override
8373 public boolean isVoNrEnabled(int subId) {
8374 enforceReadPrivilegedPermission("isVoNrEnabled");
8375 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8376 final long identity = Binder.clearCallingIdentity();
8377 try {
8378 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8379 null, subId, workSource);
8380 if (DBG) log("isVoNrEnabled: " + isEnabled);
8381 return isEnabled;
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
8385 }
8386
8387 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008388 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8389 * network status based on which carrier apps could apply actions accordingly,
8390 * enable/disable default url handler for example.
8391 *
8392 * @param subId the subscription ID that this action applies to.
8393 * @param report control start/stop reporting the default network status.
8394 * {@hide}
8395 */
8396 @Override
8397 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8398 enforceModifyPermission();
8399 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008400
8401 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008402 if (phone == null) {
8403 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8404 return;
8405 }
8406 try {
8407 phone.carrierActionReportDefaultNetworkStatus(report);
8408 } catch (Exception e) {
8409 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008410 } finally {
8411 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008412 }
8413 }
8414
8415 /**
fionaxud9622282017-07-17 17:51:30 -07008416 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8417 * @param subId the subscription ID that this action applies to.
8418 * {@hide}
8419 */
8420 @Override
8421 public void carrierActionResetAll(int subId) {
8422 enforceModifyPermission();
8423 final Phone phone = getPhone(subId);
8424 if (phone == null) {
8425 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8426 return;
8427 }
8428 try {
8429 phone.carrierActionResetAll();
8430 } catch (Exception e) {
8431 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8432 }
8433 }
8434
8435 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008436 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8437 * bug report is being generated.
8438 */
8439 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008440 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008441 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8442 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008443 writer.println("Permission Denial: can't dump Phone from pid="
8444 + Binder.getCallingPid()
8445 + ", uid=" + Binder.getCallingUid()
8446 + "without permission "
8447 + android.Manifest.permission.DUMP);
8448 return;
8449 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008450 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008451 }
Jack Yueb89b242016-06-22 13:27:47 -07008452
Brad Ebingerdac2f002018-04-03 15:17:52 -07008453 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008454 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8455 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8456 @NonNull String[] args) {
8457 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8458 this, in.getFileDescriptor(), out.getFileDescriptor(),
8459 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008460 }
8461
Jack Yueb89b242016-06-22 13:27:47 -07008462 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008463 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008464 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008465 * @param reason the reason the data enable change is taking place
8466 * @param enabled True if enabling the data, otherwise disabling.
8467 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008468 */
8469 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008470 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008471 boolean enabled) {
8472 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8473 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8474 try {
8475 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008476 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008477 } catch (SecurityException se) {
8478 enforceModifyPermission();
8479 }
8480 } else {
8481 enforceModifyPermission();
8482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008483
8484 final long identity = Binder.clearCallingIdentity();
8485 try {
8486 Phone phone = getPhone(subId);
8487 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008488 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8489 phone.carrierActionSetMeteredApnsEnabled(enabled);
8490 } else {
8491 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008493 }
8494 } finally {
8495 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008496 }
8497 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008498
8499 /**
8500 * Get Client request stats
8501 * @return List of Client Request Stats
8502 * @hide
8503 */
8504 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008505 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8506 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008507 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008508 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008509 return null;
8510 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008511 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 if (phone != null) {
8516 return phone.getClientRequestStats();
8517 }
8518
8519 return null;
8520 } finally {
8521 Binder.restoreCallingIdentity(identity);
8522 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008523 }
8524
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008525 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008526 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008527 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008528 }
Jack Yueb4124c2017-02-16 15:32:43 -08008529
8530 /**
Grace Chen70990072017-03-24 17:21:30 -07008531 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008532 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008533 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008534 * @param state State of SIM (power down, power up, pass through)
8535 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8536 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8537 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008538 *
8539 **/
8540 @Override
Grace Chen70990072017-03-24 17:21:30 -07008541 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008542 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008543 Phone phone = PhoneFactory.getPhone(slotIndex);
8544
vagdeviaf9a5b92018-08-15 16:01:53 -07008545 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8546
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008547 final long identity = Binder.clearCallingIdentity();
8548 try {
8549 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008550 phone.setSimPowerState(state, null, workSource);
8551 }
8552 } finally {
8553 Binder.restoreCallingIdentity(identity);
8554 }
8555 }
8556
8557 /**
8558 * Set SIM card power state.
8559 *
8560 * @param slotIndex SIM slot id.
8561 * @param state State of SIM (power down, power up, pass through)
8562 * @param callback callback to trigger after success or failure
8563 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8564 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8565 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8566 *
8567 **/
8568 @Override
8569 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8570 IIntegerConsumer callback) {
8571 enforceModifyPermission();
8572 Phone phone = PhoneFactory.getPhone(slotIndex);
8573
8574 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8575
8576 final long identity = Binder.clearCallingIdentity();
8577 try {
8578 if (phone != null) {
8579 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8580 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008581 }
8582 } finally {
8583 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008584 }
8585 }
Shuo Qiandd210312017-04-12 22:11:33 +00008586
Tyler Gunn65d45c22017-06-05 11:22:26 -07008587 private boolean isUssdApiAllowed(int subId) {
8588 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008589 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008590 if (configManager == null) {
8591 return false;
8592 }
8593 PersistableBundle pb = configManager.getConfigForSubId(subId);
8594 if (pb == null) {
8595 return false;
8596 }
8597 return pb.getBoolean(
8598 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8599 }
8600
Shuo Qiandd210312017-04-12 22:11:33 +00008601 /**
8602 * Check if phone is in emergency callback mode
8603 * @return true if phone is in emergency callback mode
8604 * @param subId sub id
8605 */
goneil9c5f4872017-12-05 14:07:56 -08008606 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008607 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008608 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008609 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008610
8611 final long identity = Binder.clearCallingIdentity();
8612 try {
8613 if (phone != null) {
8614 return phone.isInEcm();
8615 } else {
8616 return false;
8617 }
8618 } finally {
8619 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008620 }
8621 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008622
8623 /**
8624 * Get the current signal strength information for the given subscription.
8625 * Because this information is not updated when the device is in a low power state
8626 * it should not be relied-upon to be current.
8627 * @param subId Subscription index
8628 * @return the most recent cached signal strength info from the modem
8629 */
8630 @Override
8631 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008632 final long identity = Binder.clearCallingIdentity();
8633 try {
8634 Phone p = getPhone(subId);
8635 if (p == null) {
8636 return null;
8637 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008639 return p.getSignalStrength();
8640 } finally {
8641 Binder.restoreCallingIdentity(identity);
8642 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008643 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008644
Pengquan Meng77b7f132018-08-22 14:49:57 -07008645 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008646 * Get the current modem radio state for the given slot.
8647 * @param slotIndex slot index.
8648 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008649 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008650 * @return the current radio power state from the modem
8651 */
8652 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008653 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008654 Phone phone = PhoneFactory.getPhone(slotIndex);
8655 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8657 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008658 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8659 }
8660
8661 final long identity = Binder.clearCallingIdentity();
8662 try {
8663 return phone.getRadioPowerState();
8664 } finally {
8665 Binder.restoreCallingIdentity(identity);
8666 }
8667 }
8668 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8669 }
8670
8671 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008672 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8673 *
8674 * <p>Requires one of the following permissions:
8675 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008676 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008677 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8678 * privileges.
8679 *
8680 * @param subId subscription id
8681 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8682 * {@code false}.
8683 */
8684 @Override
8685 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008686 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008687 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008688 try {
8689 mApp.enforceCallingOrSelfPermission(
8690 android.Manifest.permission.ACCESS_NETWORK_STATE,
8691 functionName);
8692 } catch (Exception e) {
8693 mApp.enforceCallingOrSelfPermission(
8694 permission.READ_BASIC_PHONE_STATE, functionName);
8695 }
Shuo Qian093013d2020-08-13 15:42:55 -07008696 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008697 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008698 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008699 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008700
Pengquan Menga1bb6272018-09-06 09:59:22 -07008701 boolean isEnabled = false;
8702 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008703 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008704 Phone phone = getPhone(subId);
8705 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008706 } finally {
8707 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008708 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008709 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008710 }
8711
8712
8713 /**
8714 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8715 *
8716 * <p> Requires permission:
8717 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8718 * privileges.
8719 *
8720 * @param subId subscription id
8721 * @param isEnabled {@code true} means enable, {@code false} means disable.
8722 */
8723 @Override
8724 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8726 mApp, subId, "setDataRoamingEnabled");
8727
Pengquan Menga1bb6272018-09-06 09:59:22 -07008728 final long identity = Binder.clearCallingIdentity();
8729 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008730 Phone phone = getPhone(subId);
8731 if (phone != null) {
8732 phone.setDataRoamingEnabled(isEnabled);
8733 }
8734 } finally {
8735 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008736 }
8737 }
8738
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008739 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008740 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008741 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008742 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008743 mApp, subId, "isManualNetworkSelectionAllowed");
8744
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008745 boolean isAllowed = true;
8746 final long identity = Binder.clearCallingIdentity();
8747 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008748 Phone phone = getPhone(subId);
8749 if (phone != null) {
8750 isAllowed = phone.isCspPlmnEnabled();
8751 }
8752 } finally {
8753 Binder.restoreCallingIdentity(identity);
8754 }
8755 return isAllowed;
8756 }
8757
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008758 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8759 UiccProfile profile = port.getUiccProfile();
8760 if (profile == null ||
8761 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8762 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8763 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008764 }
8765 return true;
8766 }
8767
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008768 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008769 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008770 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008771 mApp.getSystemService(AppOpsManager.class)
8772 .checkPackage(Binder.getCallingUid(), callingPackage);
8773
Jordan Liu1e142fc2019-04-22 15:10:43 -07008774 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008775 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008776 try {
8777 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008778 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008779 } catch (SecurityException e) {
8780 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8781 // has carrier privileges on an active UICC
8782 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8783 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008784 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008785 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008786 }
sandeepjsb6c87872021-09-27 15:34:44 +00008787 // checking compatibility, if calling app's target SDK is T and beyond.
8788 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8789 Binder.getCallingUid())) {
8790 isIccIdAccessRestricted = true;
8791 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008792 final long identity = Binder.clearCallingIdentity();
8793 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008794 UiccController uiccController = UiccController.getInstance();
8795 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008796 if (hasReadPermission) {
8797 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008798 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008799
8800 // Remove private info if the caller doesn't have access
8801 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8802 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008803 //setting the value after compatibility check
8804 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008805 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8806 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008807 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008808 if (card == null) {
8809 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008810 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008811 continue;
8812 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008813 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8814 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008815 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008816 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008817 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008818 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8819 for (UiccPortInfo portInfo : portInfos) {
8820 UiccPort port = uiccController.getUiccPortForSlot(
8821 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8822 if (port == null) {
8823 // assume no access if port is null
8824 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8825 continue;
8826 }
8827 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8828 uiccPortInfos.add(portInfo);
8829 } else {
8830 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8831 }
8832 }
8833 filteredInfos.add(new UiccCardInfo(
8834 cardInfo.isEuicc(),
8835 cardInfo.getCardId(),
8836 null,
8837 cardInfo.getPhysicalSlotIndex(),
8838 cardInfo.isRemovable(),
8839 cardInfo.isMultipleEnabledProfilesSupported(),
8840 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008841 }
8842 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008843 } finally {
8844 Binder.restoreCallingIdentity(identity);
8845 }
8846 }
8847
sandeepjsb6c87872021-09-27 15:34:44 +00008848 /**
8849 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8850 * generally private and require carrier privileges to view.
8851 *
8852 * @hide
8853 */
8854 @NonNull
8855 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8856 List<UiccPortInfo> portinfo = new ArrayList<>();
8857 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8858 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8859 }
8860 return new UiccCardInfo(
8861 cardInfo.isEuicc(),
8862 cardInfo.getCardId(),
8863 null,
8864 cardInfo.getPhysicalSlotIndex(),
8865 cardInfo.isRemovable(),
8866 cardInfo.isMultipleEnabledProfilesSupported(),
8867 portinfo
8868 );
8869 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008870
sandeepjsb6c87872021-09-27 15:34:44 +00008871 /**
8872 * @hide
8873 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8874 * These values are generally private and require carrier privileges to view.
8875 */
8876 @NonNull
8877 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8878 return new UiccPortInfo(
8879 UiccPortInfo.ICCID_REDACTED,
8880 portInfo.getPortIndex(),
8881 portInfo.getLogicalSlotIndex(),
8882 portInfo.isActive()
8883 );
8884 }
8885 @Override
8886 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008887 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008888 mApp.getSystemService(AppOpsManager.class)
8889 .checkPackage(Binder.getCallingUid(), callingPackage);
8890
8891 boolean hasReadPermission = false;
8892 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008893
8894 try {
8895 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8896 hasReadPermission = true;
8897 } catch (SecurityException e) {
8898 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8899 // has carrier privileges on an active UICC
8900 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8901 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8902 hasReadPermission = true;
8903 }
8904 }
8905
8906 // checking compatibility, if calling app's target SDK is T and beyond.
8907 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8908 Binder.getCallingUid())) {
8909 isLogicalSlotAccessRestricted = true;
8910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008911 final long identity = Binder.clearCallingIdentity();
8912 try {
8913 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8914 if (slots == null) {
8915 Rlog.i(LOG_TAG, "slots is null.");
8916 return null;
8917 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008918 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8919 for (int i = 0; i < slots.length; i++) {
8920 UiccSlot slot = slots[i];
8921 if (slot == null) {
8922 continue;
8923 }
8924
Jordan Liu7be7e652019-05-06 18:55:02 +00008925 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008926 UiccCard card = slot.getUiccCard();
8927 if (card != null) {
8928 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008929 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008930 cardId = slot.getEid();
8931 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008932 // If cardId is null, use iccId of default port as cardId. Check if has
8933 // read permission otherwise set to null.(card is null which means no
8934 // carrier permission)
8935 cardId = hasReadPermission ? slot.getIccId(
8936 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008937 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008938 }
8939
Jordan Liu857451f2019-05-09 16:35:35 -07008940 if (cardId != null) {
8941 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8942 // if cardId is an EID, it's all digits so this is fine
8943 cardId = IccUtils.stripTrailingFs(cardId);
8944 }
8945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008946 int cardState = 0;
8947 switch (slot.getCardState()) {
8948 case CARDSTATE_ABSENT:
8949 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8950 break;
8951 case CARDSTATE_PRESENT:
8952 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8953 break;
8954 case CARDSTATE_ERROR:
8955 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8956 break;
8957 case CARDSTATE_RESTRICTED:
8958 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8959 break;
8960 default:
8961 break;
8962
8963 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008964 List<UiccPortInfo> portInfos = new ArrayList<>();
8965 int[] portIndexes = slot.getPortList();
8966 for (int portIdx : portIndexes) {
8967 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8968 callingPackage, hasReadPermission));
8969 if (slot.isPortActive(portIdx)) {
8970 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8971 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8972 port.getPhoneId(), true));
8973 } else {
8974 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8975 }
8976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008977 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008978 slot.isEuicc(),
8979 cardId,
8980 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008981 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008982 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008983 //setting the value after compatibility check
8984 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008985 }
8986 return infos;
8987 } finally {
8988 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008989 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008990 }
8991
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008992 /* Returns null if doesn't have read permission or carrier privilege access. */
8993 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8994 boolean hasReadPermission) {
8995 String iccId = slot.getIccId(portIndex);
8996 if (hasReadPermission) { // if has read permission
8997 return iccId;
8998 } else {
8999 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9000 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9001 // if no read permission, checking carrier privilege access
9002 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9003 return iccId;
9004 }
9005 }
9006 }
9007 // No read permission or carrier privilege access.
9008 return UiccPortInfo.ICCID_REDACTED;
9009 }
9010
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009011 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009012 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009013 public boolean switchSlots(int[] physicalSlots) {
9014 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009015
9016 final long identity = Binder.clearCallingIdentity();
9017 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009018 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9019 for (int i = 0; i < physicalSlots.length; i++) {
9020 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9021 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9022 physicalSlots[i], i));
9023 }
9024 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009025 } finally {
9026 Binder.restoreCallingIdentity(identity);
9027 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009028 }
Jack Yu4c988042018-02-27 15:30:01 -08009029
9030 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009031 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9032 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9033 enforceModifyPermission();
9034
9035 final long identity = Binder.clearCallingIdentity();
9036 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009037 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009038 } finally {
9039 Binder.restoreCallingIdentity(identity);
9040 }
9041 }
9042
9043 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009044 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 return UiccController.getInstance().getCardIdForDefaultEuicc();
9048 } finally {
9049 Binder.restoreCallingIdentity(identity);
9050 }
9051 }
9052
Pengquan Meng85728fb2018-03-12 16:31:21 -07009053 /**
goneil47ffb6e2018-04-06 15:40:58 -07009054 * A test API to reload the UICC profile.
9055 *
9056 * <p>Requires that the calling app has permission
9057 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9058 * @hide
9059 */
9060 @Override
9061 public void refreshUiccProfile(int subId) {
9062 enforceModifyPermission();
9063
9064 final long identity = Binder.clearCallingIdentity();
9065 try {
9066 Phone phone = getPhone(subId);
9067 if (phone == null) {
9068 return;
9069 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009070 UiccPort uiccPort = phone.getUiccPort();
9071 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009072 return;
9073 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009074 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009075 if (uiccProfile == null) {
9076 return;
9077 }
9078 uiccProfile.refresh();
9079 } finally {
9080 Binder.restoreCallingIdentity(identity);
9081 }
9082 }
9083
9084 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009085 * Returns false if the mobile data is disabled by default, otherwise return true.
9086 */
9087 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009088 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009089 }
9090
9091 /**
9092 * Returns true if the data roaming is enabled by default, i.e the system property
9093 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9094 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9095 */
9096 private boolean getDefaultDataRoamingEnabled(int subId) {
9097 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009098 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009099 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009100 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9101 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9102 return isDataRoamingEnabled;
9103 }
9104
9105 /**
9106 * Returns the default network type for the given {@code subId}, if the default network type is
9107 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9108 */
9109 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009110 List<Integer> list = TelephonyProperties.default_network();
9111 int phoneId = mSubscriptionController.getPhoneId(subId);
9112 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9113 return list.get(phoneId);
9114 }
9115 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009116 }
fionaxua13278b2018-03-21 00:08:13 -07009117
9118 @Override
9119 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009120 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009121 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009122
9123 final long identity = Binder.clearCallingIdentity();
9124 try {
9125 final Phone phone = getPhone(subId);
9126 if (phone == null) {
9127 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9128 return;
9129 }
chen xueaba88a2019-03-15 13:15:10 -07009130 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9131 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009132 if (carrierPrivilegeRules == null) {
9133 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9134 } else {
9135 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9136 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009137 } finally {
9138 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009139 }
fionaxua13278b2018-03-21 00:08:13 -07009140 }
9141
9142 @Override
9143 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009144 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009145
9146 final long identity = Binder.clearCallingIdentity();
9147 try {
9148 final Phone phone = getPhone(subId);
9149 if (phone == null) {
9150 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9151 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9152 }
9153 return phone.getCarrierIdListVersion();
9154 } finally {
9155 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009156 }
fionaxua13278b2018-03-21 00:08:13 -07009157 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009158
9159 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009160 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9161 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009162 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009163 mApp, subId, callingPackage, callingFeatureId,
9164 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009165 return -1;
9166 }
9167
9168 final long identity = Binder.clearCallingIdentity();
9169 try {
9170 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9171 } finally {
9172 Binder.restoreCallingIdentity(identity);
9173 }
9174 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009175
9176 @Override
9177 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009178 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009179 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009180 mApp, subId, "getCdmaRoamingMode");
9181
9182 final long identity = Binder.clearCallingIdentity();
9183 try {
9184 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9185 } finally {
9186 Binder.restoreCallingIdentity(identity);
9187 }
9188 }
9189
9190 @Override
9191 public boolean setCdmaRoamingMode(int subId, int mode) {
9192 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9193 mApp, subId, "setCdmaRoamingMode");
9194
9195 final long identity = Binder.clearCallingIdentity();
9196 try {
9197 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9198 } finally {
9199 Binder.restoreCallingIdentity(identity);
9200 }
9201 }
9202
9203 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009204 public int getCdmaSubscriptionMode(int subId) {
9205 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009206 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009207 mApp, subId, "getCdmaSubscriptionMode");
9208
9209 final long identity = Binder.clearCallingIdentity();
9210 try {
9211 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9212 } finally {
9213 Binder.restoreCallingIdentity(identity);
9214 }
9215 }
9216
9217 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009218 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9220 mApp, subId, "setCdmaSubscriptionMode");
9221
9222 final long identity = Binder.clearCallingIdentity();
9223 try {
9224 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9225 } finally {
9226 Binder.restoreCallingIdentity(identity);
9227 }
9228 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009229
sqianc5eccab2018-10-19 18:46:41 -07009230 @Override
sqian8c685422019-02-22 15:55:18 -08009231 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009232 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009233 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009234 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9235 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009236 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9237 }
9238 final long identity = Binder.clearCallingIdentity();
9239 try {
sqian854d44b2018-12-12 16:48:18 -08009240 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9241 for (Phone phone: PhoneFactory.getPhones()) {
9242 if (phone.getEmergencyNumberTracker() != null
9243 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9244 emergencyNumberListInternal.put(
9245 phone.getSubId(),
9246 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9247 }
sqian11b7a0e2018-12-05 18:48:28 -08009248 }
sqian854d44b2018-12-12 16:48:18 -08009249 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009250 } finally {
9251 Binder.restoreCallingIdentity(identity);
9252 }
sqianc5eccab2018-10-19 18:46:41 -07009253 }
9254
9255 @Override
sqian8c685422019-02-22 15:55:18 -08009256 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009257 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009258 if (!exactMatch) {
9259 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009260 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009261 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009262 }
9263 final long identity = Binder.clearCallingIdentity();
9264 try {
sqian854d44b2018-12-12 16:48:18 -08009265 for (Phone phone: PhoneFactory.getPhones()) {
9266 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009267 && phone.getEmergencyNumberTracker()
9268 .isEmergencyNumber(number, exactMatch)) {
9269 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009270 }
sqian11b7a0e2018-12-05 18:48:28 -08009271 }
9272 return false;
9273 } finally {
9274 Binder.restoreCallingIdentity(identity);
9275 }
9276 }
9277
sqianf4ca7ed2019-01-15 18:32:07 -08009278 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009279 * Start emergency callback mode for GsmCdmaPhone for testing.
9280 */
9281 @Override
9282 public void startEmergencyCallbackMode() {
9283 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9284 "startEmergencyCallbackMode");
9285 enforceModifyPermission();
9286 final long identity = Binder.clearCallingIdentity();
9287 try {
9288 for (Phone phone : PhoneFactory.getPhones()) {
9289 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9290 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9291 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9292 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9293 gsmCdmaPhone.obtainMessage(
9294 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9295 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9296 }
9297 }
9298 } finally {
9299 Binder.restoreCallingIdentity(identity);
9300 }
9301 }
9302
9303 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009304 * Update emergency number list for test mode.
9305 */
9306 @Override
9307 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9308 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9309 "updateEmergencyNumberListTestMode");
9310
9311 final long identity = Binder.clearCallingIdentity();
9312 try {
9313 for (Phone phone: PhoneFactory.getPhones()) {
9314 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9315 if (tracker != null) {
9316 tracker.executeEmergencyNumberTestModeCommand(action, num);
9317 }
9318 }
9319 } finally {
9320 Binder.restoreCallingIdentity(identity);
9321 }
9322 }
9323
9324 /**
9325 * Get the full emergency number list for test mode.
9326 */
9327 @Override
9328 public List<String> getEmergencyNumberListTestMode() {
9329 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9330 "getEmergencyNumberListTestMode");
9331
9332 final long identity = Binder.clearCallingIdentity();
9333 try {
9334 Set<String> emergencyNumbers = new HashSet<>();
9335 for (Phone phone: PhoneFactory.getPhones()) {
9336 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9337 if (tracker != null) {
9338 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9339 emergencyNumbers.add(num.getNumber());
9340 }
9341 }
9342 }
9343 return new ArrayList<>(emergencyNumbers);
9344 } finally {
9345 Binder.restoreCallingIdentity(identity);
9346 }
9347 }
9348
chen xud6b45bd2018-10-30 22:27:10 -07009349 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009350 public int getEmergencyNumberDbVersion(int subId) {
9351 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9352
9353 final long identity = Binder.clearCallingIdentity();
9354 try {
9355 final Phone phone = getPhone(subId);
9356 if (phone == null) {
9357 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9358 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9359 }
9360 return phone.getEmergencyNumberDbVersion();
9361 } finally {
9362 Binder.restoreCallingIdentity(identity);
9363 }
9364 }
9365
9366 @Override
9367 public void notifyOtaEmergencyNumberDbInstalled() {
9368 enforceModifyPermission();
9369
9370 final long identity = Binder.clearCallingIdentity();
9371 try {
9372 for (Phone phone: PhoneFactory.getPhones()) {
9373 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9374 if (tracker != null) {
9375 tracker.updateOtaEmergencyNumberDatabase();
9376 }
9377 }
9378 } finally {
9379 Binder.restoreCallingIdentity(identity);
9380 }
9381 }
9382
9383 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009384 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009385 enforceActiveEmergencySessionPermission();
9386
9387 final long identity = Binder.clearCallingIdentity();
9388 try {
9389 for (Phone phone: PhoneFactory.getPhones()) {
9390 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9391 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009392 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9393 }
9394 }
9395 } finally {
9396 Binder.restoreCallingIdentity(identity);
9397 }
9398 }
9399
9400 @Override
9401 public void resetOtaEmergencyNumberDbFilePath() {
9402 enforceActiveEmergencySessionPermission();
9403
9404 final long identity = Binder.clearCallingIdentity();
9405 try {
9406 for (Phone phone: PhoneFactory.getPhones()) {
9407 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9408 if (tracker != null) {
9409 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009410 }
9411 }
9412 } finally {
9413 Binder.restoreCallingIdentity(identity);
9414 }
9415 }
9416
9417 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009418 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9419 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9420 Phone phone = getPhone(subId);
9421 if (phone == null) {
9422 return null;
9423 }
9424 final long identity = Binder.clearCallingIdentity();
9425 try {
9426 UiccProfile profile = UiccController.getInstance()
9427 .getUiccProfileForPhone(phone.getPhoneId());
9428 if (profile != null) {
9429 return profile.getCertsFromCarrierPrivilegeAccessRules();
9430 }
9431 } finally {
9432 Binder.restoreCallingIdentity(identity);
9433 }
9434 return null;
9435 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009436
9437 /**
9438 * Enable or disable a modem stack.
9439 */
9440 @Override
9441 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9442 enforceModifyPermission();
9443
9444 final long identity = Binder.clearCallingIdentity();
9445 try {
9446 Phone phone = PhoneFactory.getPhone(slotIndex);
9447 if (phone == null) {
9448 return false;
9449 } else {
9450 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9451 }
9452 } finally {
9453 Binder.restoreCallingIdentity(identity);
9454 }
9455 }
Michelecea4cf22018-12-21 15:00:11 -08009456
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009457 /**
9458 * Whether a modem stack is enabled or not.
9459 */
9460 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009461 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9462 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009463 Phone phone = PhoneFactory.getPhone(slotIndex);
9464 if (phone == null) return false;
9465
9466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009467 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9468 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009469 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9470 }
9471
9472 final long identity = Binder.clearCallingIdentity();
9473 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009474 try {
9475 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9476 } catch (NoSuchElementException ex) {
9477 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9478 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009479 } finally {
9480 Binder.restoreCallingIdentity(identity);
9481 }
9482 }
9483
Michelecea4cf22018-12-21 15:00:11 -08009484 @Override
Michele0ea7d782019-03-19 14:58:42 -07009485 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009486 enforceModifyPermission();
9487
9488 final long identity = Binder.clearCallingIdentity();
9489 try {
9490 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009491 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009492 .commit();
9493 } finally {
9494 Binder.restoreCallingIdentity(identity);
9495 }
9496 }
9497
9498 @Override
Michele0ea7d782019-03-19 14:58:42 -07009499 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009500 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009501 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009502 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9503 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009504 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009505 }
Michelecea4cf22018-12-21 15:00:11 -08009506
9507 final long identity = Binder.clearCallingIdentity();
9508 try {
Michele0ea7d782019-03-19 14:58:42 -07009509 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009510 } finally {
9511 Binder.restoreCallingIdentity(identity);
9512 }
9513 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009514
Michele0ea7d782019-03-19 14:58:42 -07009515 @TelephonyManager.IsMultiSimSupportedResult
9516 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009517 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9518 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9519 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009520 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9521 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009522 }
9523 // Check if the hardware supports multisim functionality. If usage of multisim is not
9524 // supported by the modem, indicate that it is restricted.
9525 PhoneCapability staticCapability =
9526 mPhoneConfigurationManager.getStaticPhoneCapability();
9527 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009528 loge("isMultiSimSupportedInternal: no static configuration available");
9529 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009530 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009531 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009532 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9533 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009534 }
9535 // Check if support of multiple SIMs is restricted by carrier
9536 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009537 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009538 }
9539
Michele0ea7d782019-03-19 14:58:42 -07009540 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009541 }
9542
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009543 /**
9544 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009545 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9546 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9547 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009548 * @param numOfSims number of active sims we want to switch to
9549 */
9550 @Override
9551 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009552 if (numOfSims == 1) {
9553 enforceModifyPermission();
9554 } else {
9555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9556 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9557 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009558 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009559
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009560 try {
Michele30b57b22019-03-01 12:01:14 -08009561 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009562 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009563 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9564 return;
9565 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009566 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9567 } finally {
9568 Binder.restoreCallingIdentity(identity);
9569 }
9570 }
9571
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009572 @Override
9573 public boolean isApplicationOnUicc(int subId, int appType) {
9574 enforceReadPrivilegedPermission("isApplicationOnUicc");
9575 Phone phone = getPhone(subId);
9576 if (phone == null) {
9577 return false;
9578 }
9579 final long identity = Binder.clearCallingIdentity();
9580 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009581 UiccPort uiccPort = phone.getUiccPort();
9582 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009583 return false;
9584 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009585 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009586 if (uiccProfile == null) {
9587 return false;
9588 }
9589 if (TelephonyManager.APPTYPE_SIM <= appType
9590 && appType <= TelephonyManager.APPTYPE_ISIM) {
9591 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9592 }
9593 return false;
9594 } finally {
9595 Binder.restoreCallingIdentity(identity);
9596 }
9597 }
9598
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009599 /**
chen xub4baa772019-04-03 10:23:41 -07009600 * Get whether making changes to modem configurations will trigger reboot.
9601 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009602 */
9603 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009604 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9605 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009606 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009607 mApp, subId, callingPackage, callingFeatureId,
9608 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009609 return false;
9610 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009611 final long identity = Binder.clearCallingIdentity();
9612 try {
9613 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9614 } finally {
9615 Binder.restoreCallingIdentity(identity);
9616 }
9617 }
9618
Nathan Harold29f5f052019-02-15 13:41:57 -08009619 private void updateModemStateMetrics() {
9620 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9621 // TODO: check the state for each modem if the api is ready.
9622 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9623 }
9624
Pengquan Meng3889a572019-01-23 11:16:29 -08009625 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009626 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009627 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009628 // Verify that the callingPackage belongs to the calling UID
9629 mApp.getSystemService(AppOpsManager.class)
9630 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009631 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009632 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009633 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009634 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9635 if (slotInfos != null) {
9636 for (int i = 0; i < slotInfos.length; i++) {
9637 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9638 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9639 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9640 portInfo.getLogicalSlotIndex()));
9641 }
9642 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009643 }
9644 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009645 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009646 } finally {
9647 Binder.restoreCallingIdentity(identity);
9648 }
9649 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009650
9651 /**
9652 * Get the IRadio HAL Version
9653 */
9654 @Override
9655 public int getRadioHalVersion() {
9656 Phone phone = getDefaultPhone();
9657 if (phone == null) return -1;
9658 HalVersion hv = phone.getHalVersion();
9659 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9660 return hv.major * 100 + hv.minor;
9661 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009662
9663 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009664 * Get the current calling package name.
9665 * @return the current calling package name
9666 */
9667 @Override
9668 public String getCurrentPackageName() {
9669 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9670 }
9671
9672 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009673 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9674 * corresponding network requests on a subId.
9675 *
9676 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009677 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009678 * 2) APN is un-metered for this subscription, or
9679 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009680 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009681 *
9682 * @return whether data is allowed for a apn type.
9683 *
9684 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009685 */
9686 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009687 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009688 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9689 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009690
9691 // Now that all security checks passes, perform the operation as ourselves.
9692 final long identity = Binder.clearCallingIdentity();
9693 try {
9694 Phone phone = getPhone(subId);
9695 if (phone == null) return false;
9696
Jack Yu41407ee2019-05-13 16:54:09 -07009697 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009698 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9699 } finally {
9700 Binder.restoreCallingIdentity(identity);
9701 }
9702 }
9703
9704 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009705 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009706 enforceReadPrivilegedPermission("isApnMetered");
9707
9708 // Now that all security checks passes, perform the operation as ourselves.
9709 final long identity = Binder.clearCallingIdentity();
9710 try {
9711 Phone phone = getPhone(subId);
9712 if (phone == null) return true; // By default return true.
9713
Jack Yu41407ee2019-05-13 16:54:09 -07009714 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009715 } finally {
9716 Binder.restoreCallingIdentity(identity);
9717 }
9718 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009719
9720 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009721 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9722 int subscriptionId, IBooleanConsumer resultCallback) {
9723 enforceModifyPermission();
9724 long token = Binder.clearCallingIdentity();
9725 try {
9726 Phone phone = getPhone(subscriptionId);
9727 if (phone == null) {
9728 try {
9729 if (resultCallback != null) {
9730 resultCallback.accept(false);
9731 }
9732 } catch (RemoteException e) {
9733 // ignore
9734 }
9735 return;
9736 }
9737 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9738 Pair.create(specifiers, (x) -> {
9739 try {
9740 if (resultCallback != null) {
9741 resultCallback.accept(x);
9742 }
9743 } catch (RemoteException e) {
9744 // ignore
9745 }
9746 });
9747 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9748 } finally {
9749 Binder.restoreCallingIdentity(token);
9750 }
9751 }
9752
9753 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009754 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9755 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009756 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009757 mApp, subId, "getSystemSelectionChannels");
9758 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9759 final long identity = Binder.clearCallingIdentity();
9760 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009761 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9762 if (result instanceof IllegalStateException) {
9763 throw (IllegalStateException) result;
9764 }
9765 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009766 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9767 return specifiers;
9768 } finally {
9769 Binder.restoreCallingIdentity(identity);
9770 }
9771 }
9772
9773 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009774 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009775 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009776 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9777 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9778 if (iccRecords == null) {
9779 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9780 return false;
9781 }
9782 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9783 }
9784
9785 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009786 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9787 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009788 if (callingPackage == null) {
9789 callingPackage = getCurrentPackageName();
9790 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009791 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9792 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009793 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9794 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009795 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9796 }
9797 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9798 Intent intent = new Intent();
9799 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9800 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9801 // Bring up choose default SMS subscription dialog right now
9802 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9803 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9804 mApp.startActivity(intent);
9805 }
chen xud5ca2d52019-05-28 15:20:57 -07009806
9807 @Override
9808 public String getMmsUAProfUrl(int subId) {
9809 //TODO investigate if this API should require proper permission check in R b/133791609
9810 final long identity = Binder.clearCallingIdentity();
9811 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009812 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9813 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9814 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9815 return carrierUAProfUrl;
9816 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009817 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9818 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009819 } finally {
9820 Binder.restoreCallingIdentity(identity);
9821 }
9822 }
9823
9824 @Override
9825 public String getMmsUserAgent(int subId) {
9826 //TODO investigate if this API should require proper permission check in R b/133791609
9827 final long identity = Binder.clearCallingIdentity();
9828 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009829 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9830 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9831 if (!TextUtils.isEmpty(carrierUserAgent)) {
9832 return carrierUserAgent;
9833 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009834 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9835 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009836 } finally {
9837 Binder.restoreCallingIdentity(identity);
9838 }
9839 }
Jack Yub07d4972019-05-28 16:12:25 -07009840
9841 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009842 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9843 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009844
Jack Yub07d4972019-05-28 16:12:25 -07009845 final long identity = Binder.clearCallingIdentity();
9846 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009847 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009848 if (phone == null) return false;
9849
Hall Liua62f5da2020-09-25 10:42:19 -07009850 switch (policy) {
9851 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9852 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9853 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9854 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9855 default:
9856 throw new IllegalArgumentException(policy + " is not a valid policy");
9857 }
Jack Yub07d4972019-05-28 16:12:25 -07009858 } finally {
9859 Binder.restoreCallingIdentity(identity);
9860 }
9861 }
9862
9863 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009864 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009865 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009866 enforceModifyPermission();
9867
changbettyd5c246e2019-12-24 15:40:37 +08009868 final long identity = Binder.clearCallingIdentity();
9869 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009870 Phone phone = getPhone(subscriptionId);
9871 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009872
Hall Liua62f5da2020-09-25 10:42:19 -07009873 switch (policy) {
9874 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9875 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9876 break;
9877 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9878 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9879 break;
9880 default:
9881 throw new IllegalArgumentException(policy + " is not a valid policy");
9882 }
changbettyd5c246e2019-12-24 15:40:37 +08009883 } finally {
9884 Binder.restoreCallingIdentity(identity);
9885 }
9886 }
9887
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009888 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009889 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009890 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9891 * otherwise.
9892 */
9893 @Override
9894 public void setCepEnabled(boolean isCepEnabled) {
9895 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9896
9897 final long identity = Binder.clearCallingIdentity();
9898 try {
9899 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9900 for (Phone phone : PhoneFactory.getPhones()) {
9901 Phone defaultPhone = phone.getImsPhone();
9902 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9903 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9904 ImsPhoneCallTracker imsPhoneCallTracker =
9905 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9906 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9907 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9908 + imsPhone.getMsisdn());
9909 }
9910 }
9911 } finally {
9912 Binder.restoreCallingIdentity(identity);
9913 }
9914 }
allenwtsu46dcc572020-01-08 18:24:03 +08009915
9916 /**
9917 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9918 *
9919 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9920 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9921 * before being read.
9922 */
9923 @Override
9924 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9925 isCompressed) {
9926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9927 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009928 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9929 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9930 }
9931 if (!isImsAvailableOnDevice()) {
9932 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9933 "IMS not available on device.");
9934 }
9935
9936 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009937 try {
Hui Wang761a6682020-10-31 05:12:53 +00009938 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9939 } finally {
9940 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009941 }
9942 }
zoey chene02881a2019-12-30 16:11:23 +08009943
9944 @Override
9945 public boolean isIccLockEnabled(int subId) {
9946 enforceReadPrivilegedPermission("isIccLockEnabled");
9947
9948 // Now that all security checks passes, perform the operation as ourselves.
9949 final long identity = Binder.clearCallingIdentity();
9950 try {
9951 Phone phone = getPhone(subId);
9952 if (phone != null && phone.getIccCard() != null) {
9953 return phone.getIccCard().getIccLockEnabled();
9954 } else {
9955 return false;
9956 }
9957 } finally {
9958 Binder.restoreCallingIdentity(identity);
9959 }
9960 }
9961
9962 /**
9963 * Set the ICC pin lock enabled or disabled.
9964 *
9965 * @return an integer representing the status of IccLock enabled or disabled in the following
9966 * three cases:
9967 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9968 * successfully.
9969 * - Positive number and zero for remaining password attempts.
9970 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9971 *
9972 */
9973 @Override
9974 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9975 enforceModifyPermission();
9976
9977 Phone phone = getPhone(subId);
9978 if (phone == null) {
9979 return 0;
9980 }
9981 // Now that all security checks passes, perform the operation as ourselves.
9982 final long identity = Binder.clearCallingIdentity();
9983 try {
9984 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9985 new Pair<Boolean, String>(enabled, password), phone, null);
9986 return attemptsRemaining;
9987
9988 } catch (Exception e) {
9989 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9990 } finally {
9991 Binder.restoreCallingIdentity(identity);
9992 }
9993 return 0;
9994 }
9995
9996 /**
9997 * Change the ICC password used in ICC pin lock.
9998 *
9999 * @return an integer representing the status of IccLock changed in the following three cases:
10000 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10001 * - Positive number and zero for remaining password attempts.
10002 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10003 *
10004 */
10005 @Override
10006 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10007 enforceModifyPermission();
10008
10009 Phone phone = getPhone(subId);
10010 if (phone == null) {
10011 return 0;
10012 }
10013 // Now that all security checks passes, perform the operation as ourselves.
10014 final long identity = Binder.clearCallingIdentity();
10015 try {
10016 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10017 new Pair<String, String>(oldPassword, newPassword), phone, null);
10018 return attemptsRemaining;
10019
10020 } catch (Exception e) {
10021 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10022 } finally {
10023 Binder.restoreCallingIdentity(identity);
10024 }
10025 return 0;
10026 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010027
10028 /**
10029 * Request for receiving user activity notification
10030 */
10031 @Override
10032 public void requestUserActivityNotification() {
10033 if (!mNotifyUserActivity.get()
10034 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10035 mNotifyUserActivity.set(true);
10036 }
10037 }
10038
10039 /**
10040 * Called when userActivity is signalled in the power manager.
10041 * This is safe to call from any thread, with any window manager locks held or not.
10042 */
10043 @Override
10044 public void userActivity() {
10045 // ***************************************
10046 // * Inherited from PhoneWindowManager *
10047 // ***************************************
10048 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10049 // WITH ITS LOCKS HELD.
10050 //
10051 // This code must be VERY careful about the locks
10052 // it acquires.
10053 // In fact, the current code acquires way too many,
10054 // and probably has lurking deadlocks.
10055
10056 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10057 throw new SecurityException("Only the OS may call notifyUserActivity()");
10058 }
10059
10060 if (mNotifyUserActivity.getAndSet(false)) {
10061 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10062 USER_ACTIVITY_NOTIFICATION_DELAY);
10063 }
10064 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010065
10066 @Override
10067 public boolean canConnectTo5GInDsdsMode() {
10068 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10069 }
Jack Yud10cdd42020-09-28 20:28:01 -070010070
10071 @Override
10072 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10073 String callingFeatureId) {
10074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10075 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10076 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10077 }
10078
10079 Phone phone = getPhone(subId);
10080 if (phone == null) {
10081 throw new RuntimeException("phone is not available");
10082 }
10083 // Now that all security checks passes, perform the operation as ourselves.
10084 final long identity = Binder.clearCallingIdentity();
10085 try {
10086 return phone.getEquivalentHomePlmns();
10087 } finally {
10088 Binder.restoreCallingIdentity(identity);
10089 }
10090 }
Daniel Bright59e67312020-11-13 11:49:37 -080010091
10092 @Override
10093 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010094 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10095 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010096 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010097 if (radioInterfaceCapabilities == null) {
10098 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010099 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010100 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010101 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010102
Hui Wang641e81c2020-10-12 12:14:23 -070010103 @Override
10104 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10105 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010106 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10107 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10108 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10109 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10110 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010111 if (DBG) {
10112 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10113 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10114 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10115 }
10116
10117 if (!SubscriptionManager.isValidSubscriptionId(subId)
10118 || appType < TelephonyManager.APPTYPE_UNKNOWN
10119 || appType > TelephonyManager.APPTYPE_ISIM
10120 || nafUrl == null || securityProtocol == null || callback == null) {
10121 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10122 if (callback != null) {
10123 try {
10124 callback.onAuthenticationFailure(
10125 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10126 } catch (RemoteException exception) {
10127 log("Fail to notify onAuthenticationFailure due to " + exception);
10128 }
10129 return;
10130 }
10131 }
10132
10133 final long token = Binder.clearCallingIdentity();
10134 try {
10135 getGbaManager(subId).bootstrapAuthenticationRequest(
10136 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10137 forceBootStrapping, callback));
10138 } finally {
10139 Binder.restoreCallingIdentity(token);
10140 }
10141 }
10142
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010143 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010144 * Attempts to set the radio power state for all phones for thermal reason.
10145 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010146 * requested radio power state will actually be set. See {@link
10147 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10148 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010149 * @param enable {@code true} if trying to turn radio on.
10150 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10151 * false}.
10152 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010153 private boolean setRadioPowerForThermal(boolean enable) {
10154 boolean isPhoneAvailable = false;
10155 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10156 Phone phone = PhoneFactory.getPhone(i);
10157 if (phone != null) {
10158 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10159 isPhoneAvailable = true;
10160 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010161 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010162
10163 // return true if successfully informed the phone object about the thermal radio power
10164 // request.
10165 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010166 }
10167
10168 private int handleDataThrottlingRequest(int subId,
10169 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010170 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10171 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10172 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10173 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10174 throw new IllegalArgumentException("modem does not support data throttling");
10175 }
10176
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010177 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10178 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010179 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010180 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10181 }
10182
10183 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10184
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010185 if (isDataThrottlingSupported) {
10186 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010187 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010188 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10189 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10190 } else if (thermalMitigationResult
10191 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010192 log("Modem likely does not support data throttling on secondary carrier. Data " +
10193 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10194 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010195 }
10196 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010197 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010198
10199 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010200 }
10201
Jack Nudelman644b91a2021-03-12 14:09:48 -080010202 private static List<String> getThermalMitigationAllowlist(Context context) {
10203 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10204 for (String pckg : context.getResources()
10205 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10206 sThermalMitigationAllowlistedPackages.add(pckg);
10207 }
10208 }
10209
10210 return sThermalMitigationAllowlistedPackages;
10211 }
10212
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010213 private boolean isAnyPhoneInEmergencyState() {
10214 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10215 if (tm.isInEmergencyCall()) {
10216 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10217 return true;
10218 }
10219 for (Phone phone : PhoneFactory.getPhones()) {
10220 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10221 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10222 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10223 + phone.isInEcm());
10224 return true;
10225 }
10226 }
10227
10228 return false;
10229 }
10230
Jack Nudelman644b91a2021-03-12 14:09:48 -080010231 /**
10232 * Used by shell commands to add an authorized package name for thermal mitigation.
10233 * @param packageName name of package to be allowlisted
10234 * @param context
10235 */
10236 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10237 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10238 sThermalMitigationAllowlistedPackages.add(packageName);
10239 }
10240
10241 /**
10242 * Used by shell commands to remove an authorized package name for thermal mitigation.
10243 * @param packageName name of package to remove from allowlist
10244 * @param context
10245 */
10246 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10247 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10248 sThermalMitigationAllowlistedPackages.remove(packageName);
10249 }
10250
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010251 /**
10252 * Thermal mitigation request to control functionalities at modem.
10253 *
10254 * @param subId the id of the subscription.
10255 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010256 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010257 *
10258 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10259 */
10260 @Override
10261 @ThermalMitigationResult
10262 public int sendThermalMitigationRequest(
10263 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010264 ThermalMitigationRequest thermalMitigationRequest,
10265 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010266 enforceModifyPermission();
10267
Jack Nudelman644b91a2021-03-12 14:09:48 -080010268 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10269 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10270 .contains(callingPackage)) {
10271 throw new SecurityException("Calling package must be configured in the device config. "
10272 + "calling package: " + callingPackage);
10273 }
10274
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10276 final long identity = Binder.clearCallingIdentity();
10277
10278 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10279 try {
10280 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10281 switch (thermalMitigationAction) {
10282 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10283 thermalMitigationResult =
10284 handleDataThrottlingRequest(subId,
10285 thermalMitigationRequest.getDataThrottlingRequest());
10286 break;
10287 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10288 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10289 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10290 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10291 }
10292
10293 // Ensure that radio is on. If not able to power on due to phone being
10294 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010295 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010296 thermalMitigationResult =
10297 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10298 break;
10299 }
10300
10301 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10302 false);
10303 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10304 break;
10305 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10306 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10307 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10308 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10309 }
10310
10311 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10312 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010313 Phone phone = getPhone(subId);
10314 if (phone == null) {
10315 thermalMitigationResult =
10316 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10317 break;
10318 }
10319
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010320 TelephonyConnectionService service =
10321 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010322 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010323 Log.e(LOG_TAG, "An emergency call is pending");
10324 thermalMitigationResult =
10325 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10326 break;
10327 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010328 thermalMitigationResult =
10329 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10330 break;
10331 }
10332 } else {
10333 thermalMitigationResult =
10334 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10335 break;
10336 }
10337
10338 // Turn radio off. If not able to power off due to phone being unavailable,
10339 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010340 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010341 thermalMitigationResult =
10342 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10343 break;
10344 }
10345 thermalMitigationResult =
10346 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10347 break;
10348 default:
10349 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10350 + "not exist. Requested action: " + thermalMitigationAction);
10351 }
10352 } catch (IllegalArgumentException e) {
10353 throw e;
10354 } catch (Exception e) {
10355 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10356 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10357 } finally {
10358 Binder.restoreCallingIdentity(identity);
10359 }
10360
10361 if (DBG) {
10362 log("thermalMitigationRequest returning with thermalMitigationResult: "
10363 + thermalMitigationResult);
10364 }
10365
10366 return thermalMitigationResult;
10367 }
Hui Wang641e81c2020-10-12 12:14:23 -070010368
10369 /**
10370 * Set the GbaService Package Name that Telephony will bind to.
10371 *
10372 * @param subId The sim that the GbaService is associated with.
10373 * @param packageName The name of the package to be replaced with.
10374 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10375 */
10376 @Override
10377 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10378 enforceModifyPermission();
10379
10380 final long identity = Binder.clearCallingIdentity();
10381 try {
10382 return getGbaManager(subId).overrideServicePackage(packageName);
10383 } finally {
10384 Binder.restoreCallingIdentity(identity);
10385 }
10386 }
10387
10388 /**
10389 * Return the package name of the currently bound GbaService.
10390 *
10391 * @param subId The sim that the GbaService is associated with.
10392 * @return the package name of the GbaService configuration, null if GBA is not supported.
10393 */
10394 @Override
10395 public String getBoundGbaService(int subId) {
10396 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10397
10398 final long identity = Binder.clearCallingIdentity();
10399 try {
10400 return getGbaManager(subId).getServicePackage();
10401 } finally {
10402 Binder.restoreCallingIdentity(identity);
10403 }
10404 }
10405
10406 /**
10407 * Set the release time for telephony to unbind GbaService.
10408 *
10409 * @param subId The sim that the GbaService is associated with.
10410 * @param interval The release time to unbind GbaService by millisecond.
10411 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10412 */
10413 @Override
10414 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10415 enforceModifyPermission();
10416
10417 final long identity = Binder.clearCallingIdentity();
10418 try {
10419 return getGbaManager(subId).overrideReleaseTime(interval);
10420 } finally {
10421 Binder.restoreCallingIdentity(identity);
10422 }
10423 }
10424
10425 /**
10426 * Return the release time for telephony to unbind GbaService.
10427 *
10428 * @param subId The sim that the GbaService is associated with.
10429 * @return The release time to unbind GbaService by millisecond.
10430 */
10431 @Override
10432 public int getGbaReleaseTime(int subId) {
10433 enforceReadPrivilegedPermission("getGbaReleaseTime");
10434
10435 final long identity = Binder.clearCallingIdentity();
10436 try {
10437 return getGbaManager(subId).getReleaseTime();
10438 } finally {
10439 Binder.restoreCallingIdentity(identity);
10440 }
10441 }
10442
10443 private GbaManager getGbaManager(int subId) {
10444 GbaManager instance = GbaManager.getInstance(subId);
10445 if (instance == null) {
10446 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10447 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10448 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10449 }
10450 return instance;
10451 }
Hui Wang761a6682020-10-31 05:12:53 +000010452
10453 /**
10454 * indicate whether the device and the carrier can support
10455 * RCS VoLTE single registration.
10456 */
10457 @Override
10458 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010459 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10460 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10461 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10462 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010463
10464 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10465 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10466 }
10467
10468 final long identity = Binder.clearCallingIdentity();
10469 try {
10470 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10471 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010472 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10473 if (isCapable != null) {
10474 return isCapable;
10475 }
Hui Wang761a6682020-10-31 05:12:53 +000010476 }
Hui Wang67af90e2021-06-04 16:57:15 -070010477 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10478 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010479 } finally {
10480 Binder.restoreCallingIdentity(identity);
10481 }
10482 }
10483
10484 /**
10485 * Register RCS provisioning callback.
10486 */
10487 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010488 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010489 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010490 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010491 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010492 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10493 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010494
10495 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10496 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10497 }
10498 if (!isImsAvailableOnDevice()) {
10499 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10500 "IMS not available on device.");
10501 }
10502
10503 final long identity = Binder.clearCallingIdentity();
10504 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010505 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010506 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010507 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10508 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010509 }
Hui Wang761a6682020-10-31 05:12:53 +000010510 } finally {
10511 Binder.restoreCallingIdentity(identity);
10512 }
10513 }
10514
10515 /**
10516 * Unregister RCS provisioning callback.
10517 */
10518 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010519 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010520 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010521 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010522 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010523 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10524 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010525
10526 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10527 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10528 }
10529 if (!isImsAvailableOnDevice()) {
10530 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10531 "IMS not available on device.");
10532 }
10533
10534 final long identity = Binder.clearCallingIdentity();
10535 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010536 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010537 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010538 } finally {
10539 Binder.restoreCallingIdentity(identity);
10540 }
10541 }
10542
10543 /**
10544 * trigger RCS reconfiguration.
10545 */
10546 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010547 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10548 "triggerRcsReconfiguration",
10549 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010550
10551 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10552 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10553 }
10554 if (!isImsAvailableOnDevice()) {
10555 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10556 "IMS not available on device.");
10557 }
10558
10559 final long identity = Binder.clearCallingIdentity();
10560 try {
10561 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10562 } finally {
10563 Binder.restoreCallingIdentity(identity);
10564 }
10565 }
10566
10567 /**
10568 * Provide the client configuration parameters of the RCS application.
10569 */
10570 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010571 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10572 "setRcsClientConfiguration",
10573 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010574
10575 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10576 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10577 }
10578 if (!isImsAvailableOnDevice()) {
10579 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10580 "IMS not available on device.");
10581 }
10582
10583 final long identity = Binder.clearCallingIdentity();
10584
10585 try {
10586 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10587 if (configBinder == null) {
10588 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010589 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10590 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010591 } else {
10592 configBinder.setRcsClientConfiguration(rcc);
10593 }
joonhunshin3e154242021-09-17 06:33:39 +000010594
10595 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10596 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010597 } catch (RemoteException e) {
10598 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010599 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10600 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010601 } finally {
10602 Binder.restoreCallingIdentity(identity);
10603 }
10604 }
10605
10606 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010607 * Enables or disables the test mode for RCS VoLTE single registration.
10608 */
10609 @Override
10610 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10611 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10612 "setRcsSingleRegistrationTestModeEnabled");
10613
10614 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10615 }
10616
10617 /**
10618 * Gets the test mode for RCS VoLTE single registration.
10619 */
10620 @Override
10621 public boolean getRcsSingleRegistrationTestModeEnabled() {
10622 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10623 "getRcsSingleRegistrationTestModeEnabled");
10624
10625 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10626 }
10627
10628 /**
Hui Wang761a6682020-10-31 05:12:53 +000010629 * Overrides the config of RCS VoLTE single registration enabled for the device.
10630 */
10631 @Override
10632 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10633 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10634 "setDeviceSingleRegistrationEnabledOverride");
10635 enforceModifyPermission();
10636
10637 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10638 : Boolean.parseBoolean(enabledStr);
10639 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010640 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010641 }
10642
10643 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010644 * Sends a device to device communication message. Only usable via shell.
10645 * @param message message to send.
10646 * @param value message value.
10647 */
10648 @Override
10649 public void sendDeviceToDeviceMessage(int message, int value) {
10650 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010651 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010652 enforceModifyPermission();
10653
10654 final long identity = Binder.clearCallingIdentity();
10655 try {
10656 TelephonyConnectionService service =
10657 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10658 if (service == null) {
10659 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10660 return;
10661 }
10662 service.sendTestDeviceToDeviceMessage(message, value);
10663 } finally {
10664 Binder.restoreCallingIdentity(identity);
10665 }
10666 }
10667
Tyler Gunnbabbda02021-02-10 11:05:02 -080010668 /**
10669 * Sets the specified device to device transport active.
10670 * @param transport The transport to set active.
10671 */
10672 @Override
10673 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10674 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10675 "setActiveDeviceToDeviceTransport");
10676 enforceModifyPermission();
10677
10678 final long identity = Binder.clearCallingIdentity();
10679 try {
10680 TelephonyConnectionService service =
10681 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10682 if (service == null) {
10683 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10684 return;
10685 }
10686 service.setActiveDeviceToDeviceTransport(transport);
10687 } finally {
10688 Binder.restoreCallingIdentity(identity);
10689 }
10690 }
Tyler Gunn92479152021-01-20 16:30:10 -080010691
Tyler Gunnd4339262021-05-03 14:46:49 -070010692 @Override
10693 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10694 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10695 "setDeviceToDeviceForceEnabled");
10696
10697 final long identity = Binder.clearCallingIdentity();
10698 try {
10699 Arrays.stream(PhoneFactory.getPhones()).forEach(
10700 p -> {
10701 Phone thePhone = p.getImsPhone();
10702 if (thePhone != null && thePhone instanceof ImsPhone) {
10703 ImsPhone imsPhone = (ImsPhone) thePhone;
10704 CallTracker tracker = imsPhone.getCallTracker();
10705 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10706 ImsPhoneCallTracker imsPhoneCallTracker =
10707 (ImsPhoneCallTracker) tracker;
10708 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10709 }
10710 }
10711 }
10712 );
10713 } finally {
10714 Binder.restoreCallingIdentity(identity);
10715 }
10716 }
10717
Tyler Gunn92479152021-01-20 16:30:10 -080010718 /**
Hui Wang761a6682020-10-31 05:12:53 +000010719 * Gets the config of RCS VoLTE single registration enabled for the device.
10720 */
10721 @Override
10722 public boolean getDeviceSingleRegistrationEnabled() {
10723 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10724 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10725 }
10726
10727 /**
10728 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10729 */
10730 @Override
10731 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10732 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10733 "setCarrierSingleRegistrationEnabledOverride");
10734 enforceModifyPermission();
10735
10736 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10737 : Boolean.parseBoolean(enabledStr);
10738 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10739 subId, enabled);
10740 }
10741
10742 /**
10743 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10744 */
10745 @Override
10746 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10747 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10748 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10749 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010750
10751 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010752 * Overrides the ims feature validation result
10753 */
10754 @Override
10755 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10756 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10757 "setImsFeatureValidationOverride");
10758
10759 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10760 : Boolean.parseBoolean(enabledStr);
10761 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10762 subId, enabled);
10763 }
10764
10765 /**
10766 * Gets the ims feature validation override value
10767 */
10768 @Override
10769 public boolean getImsFeatureValidationOverride(int subId) {
10770 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10771 "getImsFeatureValidationOverride");
10772 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10773 }
10774
10775 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010776 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10777 * their mobile plan.
10778 */
10779 @Override
10780 public String getMobileProvisioningUrl() {
10781 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10782 final long identity = Binder.clearCallingIdentity();
10783 try {
10784 return getDefaultPhone().getMobileProvisioningUrl();
10785 } finally {
10786 Binder.restoreCallingIdentity(identity);
10787 }
10788 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010789
James.cf Linbcdf8b32021-01-14 16:44:13 +080010790 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010791 * Get the EAB contact from the EAB database.
10792 */
10793 @Override
10794 public String getContactFromEab(String contact) {
10795 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10796 enforceModifyPermission();
10797 final long identity = Binder.clearCallingIdentity();
10798 try {
10799 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10800 } finally {
10801 Binder.restoreCallingIdentity(identity);
10802 }
10803 }
10804
10805 /**
Calvin Pana1434322021-07-01 19:27:01 +080010806 * Get the EAB capability from the EAB database.
10807 */
10808 @Override
10809 public String getCapabilityFromEab(String contact) {
10810 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10811 enforceModifyPermission();
10812 final long identity = Binder.clearCallingIdentity();
10813 try {
10814 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10815 } finally {
10816 Binder.restoreCallingIdentity(identity);
10817 }
10818 }
10819
10820 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010821 * Remove the EAB contacts from the EAB database.
10822 */
10823 @Override
10824 public int removeContactFromEab(int subId, String contacts) {
10825 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10826 enforceModifyPermission();
10827 final long identity = Binder.clearCallingIdentity();
10828 try {
10829 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10830 } finally {
10831 Binder.restoreCallingIdentity(identity);
10832 }
10833 }
10834
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010835 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010836 public boolean getDeviceUceEnabled() {
10837 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10838 final long identity = Binder.clearCallingIdentity();
10839 try {
10840 return mApp.getDeviceUceEnabled();
10841 } finally {
10842 Binder.restoreCallingIdentity(identity);
10843 }
10844 }
10845
10846 @Override
10847 public void setDeviceUceEnabled(boolean isEnabled) {
10848 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10849 final long identity = Binder.clearCallingIdentity();
10850 try {
10851 mApp.setDeviceUceEnabled(isEnabled);
10852 } finally {
10853 Binder.restoreCallingIdentity(identity);
10854 }
10855 }
10856
Brad Ebinger14d467f2021-02-12 06:18:28 +000010857 /**
10858 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10859 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10860 */
10861 // Used for SHELL command only right now.
10862 @Override
10863 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10864 List<String> featureTags) {
10865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10866 "addUceRegistrationOverrideShell");
10867 final long identity = Binder.clearCallingIdentity();
10868 try {
10869 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10870 new ArraySet<>(featureTags));
10871 } catch (ImsException e) {
10872 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10873 } finally {
10874 Binder.restoreCallingIdentity(identity);
10875 }
10876 }
10877
10878 /**
10879 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10880 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10881 */
10882 // Used for SHELL command only right now.
10883 @Override
10884 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10885 List<String> featureTags) {
10886 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10887 "removeUceRegistrationOverrideShell");
10888 final long identity = Binder.clearCallingIdentity();
10889 try {
10890 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10891 new ArraySet<>(featureTags));
10892 } catch (ImsException e) {
10893 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10894 } finally {
10895 Binder.restoreCallingIdentity(identity);
10896 }
10897 }
10898
10899 /**
10900 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10901 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10902 */
10903 // Used for SHELL command only right now.
10904 @Override
10905 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10906 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10907 "clearUceRegistrationOverrideShell");
10908 final long identity = Binder.clearCallingIdentity();
10909 try {
10910 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10911 } catch (ImsException e) {
10912 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10913 } finally {
10914 Binder.restoreCallingIdentity(identity);
10915 }
10916 }
10917
10918 /**
10919 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10920 */
10921 // Used for SHELL command only right now.
10922 @Override
10923 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10924 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10925 "getLatestRcsContactUceCapabilityShell");
10926 final long identity = Binder.clearCallingIdentity();
10927 try {
10928 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10929 } catch (ImsException e) {
10930 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10931 } finally {
10932 Binder.restoreCallingIdentity(identity);
10933 }
10934 }
10935
10936 /**
10937 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10938 * device does not have an active PUBLISH.
10939 */
10940 // Used for SHELL command only right now.
10941 @Override
10942 public String getLastUcePidfXmlShell(int subId) {
10943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10944 final long identity = Binder.clearCallingIdentity();
10945 try {
10946 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10947 } catch (ImsException e) {
10948 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10949 } finally {
10950 Binder.restoreCallingIdentity(identity);
10951 }
10952 }
10953
James.cf Line8713a42021-04-29 16:04:26 +080010954 /**
10955 * Remove UCE requests cannot be sent to the network status.
10956 */
10957 // Used for SHELL command only right now.
10958 @Override
10959 public boolean removeUceRequestDisallowedStatus(int subId) {
10960 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10961 final long identity = Binder.clearCallingIdentity();
10962 try {
10963 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10964 } catch (ImsException e) {
10965 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10966 } finally {
10967 Binder.restoreCallingIdentity(identity);
10968 }
10969 }
10970
James.cf Lin18bb9002021-05-25 01:37:38 +080010971 /**
10972 * Remove UCE requests cannot be sent to the network status.
10973 */
10974 // Used for SHELL command only.
10975 @Override
10976 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10977 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10978 final long identity = Binder.clearCallingIdentity();
10979 try {
10980 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10981 } catch (ImsException e) {
10982 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10983 } finally {
10984 Binder.restoreCallingIdentity(identity);
10985 }
10986 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010987
James.cf Lin4b784aa2021-01-31 03:25:15 +080010988 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010989 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10990 String callingPackage) {
10991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10992 mApp, subId, "setSignalStrengthUpdateRequest");
10993
10994 final int callingUid = Binder.getCallingUid();
10995 // Verify that tha callingPackage belongs to the calling UID
10996 mApp.getSystemService(AppOpsManager.class)
10997 .checkPackage(callingUid, callingPackage);
10998
Rambo Wang3607f502021-02-01 21:51:40 -080010999 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011000
11001 final long identity = Binder.clearCallingIdentity();
11002 try {
11003 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11004 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11005
11006 if (result instanceof IllegalStateException) {
11007 throw (IllegalStateException) result;
11008 }
11009 } finally {
11010 Binder.restoreCallingIdentity(identity);
11011 }
11012 }
11013
11014 @Override
11015 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11016 String callingPackage) {
11017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11018 mApp, subId, "clearSignalStrengthUpdateRequest");
11019
11020 final int callingUid = Binder.getCallingUid();
11021 // Verify that tha callingPackage belongs to the calling UID
11022 mApp.getSystemService(AppOpsManager.class)
11023 .checkPackage(callingUid, callingPackage);
11024
11025 final long identity = Binder.clearCallingIdentity();
11026 try {
11027 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11028 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11029
11030 if (result instanceof IllegalStateException) {
11031 throw (IllegalStateException) result;
11032 }
11033 } finally {
11034 Binder.restoreCallingIdentity(identity);
11035 }
11036 }
11037
Rambo Wang3607f502021-02-01 21:51:40 -080011038 private static void validateSignalStrengthUpdateRequest(Context context,
11039 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011040 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11041 // phone/system process do not have further restriction on request
11042 return;
11043 }
11044
11045 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011046 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011047 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011048 context.enforceCallingOrSelfPermission(
11049 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11050 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011051 }
11052
11053 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11054 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11055 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11056 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11057 || info.isEnabled()) {
11058 throw new IllegalArgumentException(
11059 "Only system can set hide fields in SignalThresholdInfo");
11060 }
11061
11062 // Thresholds length for each RAN need in range. This has been validated in
11063 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11064 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11065 final int[] thresholds = info.getThresholds();
11066 Objects.requireNonNull(thresholds);
11067 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11068 || thresholds.length
11069 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11070 throw new IllegalArgumentException(
11071 "thresholds length is out of range: " + thresholds.length);
11072 }
11073 }
11074 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011075
11076 /**
11077 * Gets the current phone capability.
11078 *
11079 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11080 * @return the PhoneCapability which describes the data connection capability of modem.
11081 * It's used to evaluate possible phone config change, for example from single
11082 * SIM device to multi-SIM device.
11083 */
11084 @Override
11085 public PhoneCapability getPhoneCapability() {
11086 enforceReadPrivilegedPermission("getPhoneCapability");
11087 final long identity = Binder.clearCallingIdentity();
11088 try {
11089 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11090 } finally {
11091 Binder.restoreCallingIdentity(identity);
11092 }
11093 }
Michele Berionne5e411512020-11-13 02:36:59 +000011094
11095 /**
11096 * Prepare TelephonyManager for an unattended reboot. The reboot is
11097 * required to be done shortly after the API is invoked.
11098 */
11099 @Override
11100 @TelephonyManager.PrepareUnattendedRebootResult
11101 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011102 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011103 enforceRebootPermission();
11104
11105 final long identity = Binder.clearCallingIdentity();
11106 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011107 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011108 } finally {
11109 Binder.restoreCallingIdentity(identity);
11110 }
11111 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011112
11113 /**
11114 * Request to get the current slicing configuration including URSP rules and
11115 * NSSAIs (configured, allowed and rejected).
11116 *
11117 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11118 */
11119 @Override
11120 public void getSlicingConfig(ResultReceiver callback) {
11121 enforceReadPrivilegedPermission("getSlicingConfig");
11122
11123 final long identity = Binder.clearCallingIdentity();
11124 try {
11125 Phone phone = getDefaultPhone();
11126 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11127 } finally {
11128 Binder.restoreCallingIdentity(identity);
11129 }
11130 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011131
11132 /**
11133 * Register an IMS connection state callback
11134 */
11135 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011136 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11137 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011138 if (feature == ImsFeature.FEATURE_MMTEL) {
11139 // ImsMmTelManager
11140 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11141 TelephonyPermissions
11142 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11143 mApp, subId, "registerImsStateCallback");
11144 } else if (feature == ImsFeature.FEATURE_RCS) {
11145 // ImsRcsManager or SipDelegateManager
11146 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11147 Binder.getCallingUid(), "registerImsStateCallback",
11148 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11149 Manifest.permission.READ_PRECISE_PHONE_STATE,
11150 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11151 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11152 }
11153
11154 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11155 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11156 "IMS not available on device.");
11157 }
11158
11159 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11160 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11161 }
11162
11163 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11164 if (controller == null) {
11165 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11166 "IMS not available on device.");
11167 }
11168
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011169 if (callingPackage == null) {
11170 callingPackage = getCurrentPackageName();
11171 }
11172
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011173 final long token = Binder.clearCallingIdentity();
11174 try {
11175 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011176 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011177 } catch (ImsException e) {
11178 throw new ServiceSpecificException(e.getCode());
11179 } finally {
11180 Binder.restoreCallingIdentity(token);
11181 }
11182 }
11183
11184 /**
11185 * Unregister an IMS connection state callback
11186 */
11187 @Override
11188 public void unregisterImsStateCallback(IImsStateCallback cb) {
11189 final long token = Binder.clearCallingIdentity();
11190 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11191 if (controller == null) {
11192 return;
11193 }
11194 try {
11195 controller.unregisterImsStateCallback(cb);
11196 } finally {
11197 Binder.restoreCallingIdentity(token);
11198 }
11199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011200}