blob: 38cf872b8c133449de79cccd39157f52d9886e0a [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) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005085 mApp, subId, callingPackage, callingFeatureId,
5086 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005087 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5088 }
5089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
5092 final Phone phone = getPhone(subId);
5093 if (phone != null) {
5094 return phone.getServiceState().getDataNetworkType();
5095 } else {
5096 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5097 }
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005101 }
5102
5103 /**
Wink Saville36469e72014-06-11 15:17:00 -07005104 * Returns the Voice network type for a subId
5105 */
5106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005107 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5108 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005110 mApp, subId, callingPackage, callingFeatureId,
5111 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005112 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5113 }
5114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 final Phone phone = getPhone(subId);
5118 if (phone != null) {
5119 return phone.getServiceState().getVoiceNetworkType();
5120 } else {
5121 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5122 }
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005126 }
5127
5128 /**
5129 * @return true if a ICC card is present
5130 */
5131 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005132 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005133 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5134 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005135 }
5136
5137 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005138 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005139 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005140 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005141 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 final Phone phone = PhoneFactory.getPhone(slotIndex);
5145 if (phone != null) {
5146 return phone.getIccCard().hasIccCard();
5147 } else {
5148 return false;
5149 }
5150 } finally {
5151 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005153 }
5154
5155 /**
5156 * Return if the current radio is LTE on CDMA. This
5157 * is a tri-state return value as for a period of time
5158 * the mode may be unknown.
5159 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005160 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005161 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005162 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005163 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005164 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005165 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5166 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5167 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005168 }
5169
Sanket Padawe356d7632015-06-22 14:03:32 -07005170 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005171 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5172 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005173 try {
5174 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5175 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005176 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5177 }
5178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 final long identity = Binder.clearCallingIdentity();
5180 try {
5181 final Phone phone = getPhone(subId);
5182 if (phone == null) {
5183 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5184 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005185 return TelephonyProperties.lte_on_cdma_device()
5186 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 }
5188 } finally {
5189 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005190 }
Wink Saville36469e72014-06-11 15:17:00 -07005191 }
5192
Wink Saville36469e72014-06-11 15:17:00 -07005193 /**
5194 * {@hide}
5195 * Returns Default subId, 0 in the case of single standby.
5196 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005197 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005198 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005199 }
5200
Shishir Agrawala9f32182016-04-12 12:00:16 -07005201 private int getSlotForDefaultSubscription() {
5202 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5203 }
5204
Wink Savilleb564aae2014-10-23 10:18:09 -07005205 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005206 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005207 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005208
Pengquan Menge92a50d2018-09-21 15:54:48 -07005209 private boolean isActiveSubscription(int subId) {
5210 return mSubscriptionController.isActiveSubId(subId);
5211 }
5212
Ihab Awadf2177b72013-11-25 13:33:23 -08005213 /**
5214 * @see android.telephony.TelephonyManager.WifiCallingChoices
5215 */
5216 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 final long identity = Binder.clearCallingIdentity();
5218 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005219 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5221 getWhenToMakeWifiCallsDefaultPreference());
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
5224 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005225 }
5226
5227 /**
5228 * @see android.telephony.TelephonyManager.WifiCallingChoices
5229 */
5230 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005234 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005239 }
5240
Sailesh Nepald1e68152013-12-12 19:08:02 -08005241 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005242 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005243 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005244 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005245
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005246 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5247 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5248 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005249 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005250 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5251 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005252 }
5253 return PhoneFactory.getPhone(phoneId);
5254 }
5255
Shishir Agrawal566b7612013-10-28 14:41:00 -07005256 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005257 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5258 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5260 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005262 if (DBG) {
5263 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5264 }
5265 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5266 p2);
5267 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005268
Jordan Liu4c733742019-02-28 12:03:40 -08005269
5270 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005271 public IccOpenLogicalChannelResponse iccOpenLogicalChannelByPort(
5272 int slotIndex, int portIndex, String callingPackage, String aid, int p2) {
Jordan Liu4c733742019-02-28 12:03:40 -08005273 enforceModifyPermission();
5274 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5275 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005276 log("iccOpenLogicalChannelByPort: slot=" + slotIndex + " port=" + portIndex + " aid="
5277 + aid + " p2=" + p2);
Jordan Liu4c733742019-02-28 12:03:40 -08005278 }
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005279 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotPortIndexOrThrowException(
5280 slotIndex, portIndex), callingPackage, aid, p2);
Jordan Liu4c733742019-02-28 12:03:40 -08005281 }
5282
5283 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5284 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 final long identity = Binder.clearCallingIdentity();
5286 try {
5287 if (TextUtils.equals(ISDR_AID, aid)) {
5288 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005289 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5290 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 if (bestComponent == null
5292 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5293 loge("The calling package is not allowed to access ISD-R.");
5294 throw new SecurityException(
5295 "The calling package is not allowed to access ISD-R.");
5296 }
Derek Tan740e1672017-06-27 14:56:27 -07005297 }
Derek Tan740e1672017-06-27 14:56:27 -07005298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005300 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5301 null /* workSource */);
5302 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005303 return response;
5304 } finally {
5305 Binder.restoreCallingIdentity(identity);
5306 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005307 }
5308
5309 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005310 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5312 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005313 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5314 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5315 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005316
Jordan Liu4c733742019-02-28 12:03:40 -08005317 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005318 public boolean iccCloseLogicalChannelByPort(int slotIndex, int portIndex, int channel) {
Jordan Liu4c733742019-02-28 12:03:40 -08005319 enforceModifyPermission();
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005320 if (DBG) log("iccCloseLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5321 + portIndex + " chnl=" + channel);
5322 return iccCloseLogicalChannelWithPermission(
5323 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel);
Jordan Liu4c733742019-02-28 12:03:40 -08005324 }
5325
5326 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 final long identity = Binder.clearCallingIdentity();
5328 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 if (channel < 0) {
5330 return false;
5331 }
Jordan Liu4c733742019-02-28 12:03:40 -08005332 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5333 null /* workSource */);
5334 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 return success;
5336 } finally {
5337 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005338 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005339 }
5340
5341 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005342 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005343 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5345 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005346 if (DBG) {
5347 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5348 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5349 + p3 + " data=" + data);
5350 }
5351 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5352 command, p1, p2, p3, data);
5353 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005354
Jordan Liu4c733742019-02-28 12:03:40 -08005355 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005356 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5357 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005358 enforceModifyPermission();
5359 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005360 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5361 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5362 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005363 }
5364 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005365 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5366 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005367 }
5368
5369 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5370 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 final long identity = Binder.clearCallingIdentity();
5372 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005373 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 return "";
5375 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005378 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5379 null /* workSource */);
5380 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382 // Append the returned status code to the end of the response payload.
5383 String s = Integer.toHexString(
5384 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5385 if (response.payload != null) {
5386 s = IccUtils.bytesToHexString(response.payload) + s;
5387 }
5388 return s;
5389 } finally {
5390 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005391 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005392 }
Jake Hambye994d462014-02-03 13:10:13 -08005393
Evan Charltonc66da362014-05-16 14:06:40 -07005394 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005395 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5396 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5398 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005400 if (DBG) {
5401 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5402 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5403 }
5404 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5405 cla, command, p1, p2, p3, data);
5406 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005407
Jordan Liu4c733742019-02-28 12:03:40 -08005408 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005409 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5410 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005411 enforceModifyPermission();
5412 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5413 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005414 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5415 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5416 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005417 }
5418
5419 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005420 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5421 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005422 }
5423
5424 // open APDU basic channel assuming the caller has sufficient permissions
5425 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5426 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005427 final long identity = Binder.clearCallingIdentity();
5428 try {
5429 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5430 && TextUtils.equals(ISDR_AID, data)) {
5431 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005432 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5433 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 if (bestComponent == null
5435 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5436 loge("The calling package is not allowed to select ISD-R.");
5437 throw new SecurityException(
5438 "The calling package is not allowed to select ISD-R.");
5439 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005440 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005443 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5444 null /* workSource */);
5445 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 // Append the returned status code to the end of the response payload.
5448 String s = Integer.toHexString(
5449 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5450 if (response.payload != null) {
5451 s = IccUtils.bytesToHexString(response.payload) + s;
5452 }
5453 return s;
5454 } finally {
5455 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005456 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005457 }
5458
5459 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005460 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005461 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5463 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 if (DBG) {
5468 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5469 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5470 }
5471
5472 IccIoResult response =
5473 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5474 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5475 subId);
5476
5477 if (DBG) {
5478 log("Exchange SIM_IO [R]" + response);
5479 }
5480
5481 byte[] result = null;
5482 int length = 2;
5483 if (response.payload != null) {
5484 length = 2 + response.payload.length;
5485 result = new byte[length];
5486 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5487 } else {
5488 result = new byte[length];
5489 }
5490
5491 result[length - 1] = (byte) response.sw2;
5492 result[length - 2] = (byte) response.sw1;
5493 return result;
5494 } finally {
5495 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005496 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005497 }
5498
Nathan Haroldb3014052017-01-25 15:57:32 -08005499 /**
5500 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5501 * on a particular subscription
5502 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005503 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5504 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005506 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005507 return null;
5508 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509
5510 final long identity = Binder.clearCallingIdentity();
5511 try {
5512 if (appType != TelephonyManager.APPTYPE_USIM
5513 && appType != TelephonyManager.APPTYPE_SIM) {
5514 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5515 return null;
5516 }
5517 Object response = sendRequest(
5518 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5519 if (response instanceof String[]) {
5520 return (String[]) response;
5521 }
yincheng zhao2737e882019-09-06 17:06:54 -07005522 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005524 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 } finally {
5526 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005527 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005528 }
5529
yincheng zhao2737e882019-09-06 17:06:54 -07005530 /**
5531 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5532 * subscription.
5533 *
5534 * @param subId the id of the subscription.
5535 * @param appType the uicc app type, must be USIM or SIM.
5536 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5537 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005538 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005539 * @return number of fplmns that is successfully written to the SIM.
5540 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005541 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5542 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5544 mApp, subId, "setForbiddenPlmns");
5545
yincheng zhao2737e882019-09-06 17:06:54 -07005546 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5547 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5548 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5549 }
5550 if (fplmns == null) {
5551 throw new IllegalArgumentException("Fplmn List provided is null");
5552 }
5553 for (String fplmn : fplmns) {
5554 if (!CellIdentity.isValidPlmn(fplmn)) {
5555 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5556 }
5557 }
5558 final long identity = Binder.clearCallingIdentity();
5559 try {
5560 Object response = sendRequest(
5561 CMD_SET_FORBIDDEN_PLMNS,
5562 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5563 subId);
5564 return (int) response;
5565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
5568 }
5569
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005570 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005571 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5573 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 final long identity = Binder.clearCallingIdentity();
5576 try {
5577 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5578 if (response.payload == null) {
5579 return "";
5580 }
Evan Charltonc66da362014-05-16 14:06:40 -07005581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 // Append the returned status code to the end of the response payload.
5583 String s = Integer.toHexString(
5584 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5585 s = IccUtils.bytesToHexString(response.payload) + s;
5586 return s;
5587 } finally {
5588 Binder.restoreCallingIdentity(identity);
5589 }
Evan Charltonc66da362014-05-16 14:06:40 -07005590 }
5591
Jake Hambye994d462014-02-03 13:10:13 -08005592 /**
5593 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5594 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5595 *
5596 * @param itemID the ID of the item to read
5597 * @return the NV item as a String, or null on error.
5598 */
5599 @Override
5600 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005601 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5603 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604
5605 final long identity = Binder.clearCallingIdentity();
5606 try {
5607 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005608 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5610 return value;
5611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
Jake Hambye994d462014-02-03 13:10:13 -08005614 }
5615
5616 /**
5617 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5618 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5619 *
5620 * @param itemID the ID of the item to read
5621 * @param itemValue the value to write, as a String
5622 * @return true on success; false on any failure
5623 */
5624 @Override
5625 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005626 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5628 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629
5630 final long identity = Binder.clearCallingIdentity();
5631 try {
5632 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5633 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005634 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5636 return success;
5637 } finally {
5638 Binder.restoreCallingIdentity(identity);
5639 }
Jake Hambye994d462014-02-03 13:10:13 -08005640 }
5641
5642 /**
5643 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5644 * Used for device configuration by some CDMA operators.
5645 *
5646 * @param preferredRoamingList byte array containing the new PRL
5647 * @return true on success; false on any failure
5648 */
5649 @Override
5650 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5652 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653
5654 final long identity = Binder.clearCallingIdentity();
5655 try {
5656 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5657 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5658 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5659 return success;
5660 } finally {
5661 Binder.restoreCallingIdentity(identity);
5662 }
Jake Hambye994d462014-02-03 13:10:13 -08005663 }
5664
5665 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005666 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005667 * Used for device configuration by some CDMA operators.
5668 *
chen xu6dac5ab2018-10-26 17:39:23 -07005669 * @param slotIndex - device slot.
5670 *
Jake Hambye994d462014-02-03 13:10:13 -08005671 * @return true on success; false on any failure
5672 */
5673 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005674 public boolean resetModemConfig(int slotIndex) {
5675 Phone phone = PhoneFactory.getPhone(slotIndex);
5676 if (phone != null) {
5677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5678 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679
chen xu6dac5ab2018-10-26 17:39:23 -07005680 final long identity = Binder.clearCallingIdentity();
5681 try {
5682 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5683 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5684 return success;
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 }
chen xu6dac5ab2018-10-26 17:39:23 -07005689 return false;
5690 }
5691
5692 /**
5693 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5694 *
5695 * @param slotIndex - device slot.
5696 *
5697 * @return true on success; false on any failure
5698 */
5699 @Override
5700 public boolean rebootModem(int slotIndex) {
5701 Phone phone = PhoneFactory.getPhone(slotIndex);
5702 if (phone != null) {
5703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5704 mApp, phone.getSubId(), "rebootModem");
5705
5706 final long identity = Binder.clearCallingIdentity();
5707 try {
5708 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5709 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5710 return success;
5711 } finally {
5712 Binder.restoreCallingIdentity(identity);
5713 }
5714 }
5715 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005716 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005717
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005718 public String[] getPcscfAddress(String apnType, String callingPackage,
5719 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005720 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005721 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5722 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005723 return new String[0];
5724 }
5725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 final long identity = Binder.clearCallingIdentity();
5727 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005728 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729 } finally {
5730 Binder.restoreCallingIdentity(identity);
5731 }
Wink Saville36469e72014-06-11 15:17:00 -07005732 }
5733
Brad Ebinger51f743a2017-01-23 13:50:20 -08005734 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005735 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5736 * {@link #disableIms(int)}.
5737 * @param slotIndex device slot.
5738 */
5739 public void resetIms(int slotIndex) {
5740 enforceModifyPermission();
5741
5742 final long identity = Binder.clearCallingIdentity();
5743 try {
5744 if (mImsResolver == null) {
5745 // may happen if the does not support IMS.
5746 return;
5747 }
5748 mImsResolver.disableIms(slotIndex);
5749 mImsResolver.enableIms(slotIndex);
5750 } finally {
5751 Binder.restoreCallingIdentity(identity);
5752 }
5753 }
5754
5755 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005756 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5757 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005758 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005759 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761
5762 final long identity = Binder.clearCallingIdentity();
5763 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005764 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005765 // may happen if the device does not support IMS.
5766 return;
5767 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005768 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005772 }
5773
5774 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005775 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5776 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005777 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005778 public void disableIms(int slotId) {
5779 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005783 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005784 // may happen if the device does not support IMS.
5785 return;
5786 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005787 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788 } finally {
5789 Binder.restoreCallingIdentity(identity);
5790 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005791 }
5792
5793 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005794 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5795 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005796 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005797 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005798 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800
5801 final long identity = Binder.clearCallingIdentity();
5802 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005803 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005804 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5805 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005806 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005807 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 } finally {
5809 Binder.restoreCallingIdentity(identity);
5810 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005811 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005812 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005813 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5814 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005815 @Override
5816 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005817 enforceModifyPermission();
5818
5819 final long identity = Binder.clearCallingIdentity();
5820 try {
5821 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005822 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005823 } finally {
5824 Binder.restoreCallingIdentity(identity);
5825 }
5826 }
5827
5828 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005829 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005830 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005831 */
5832 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005834
5835 final long identity = Binder.clearCallingIdentity();
5836 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005837 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005838 // may happen if the device does not support IMS.
5839 return null;
5840 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005841 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 } finally {
5843 Binder.restoreCallingIdentity(identity);
5844 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005845 }
5846
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005847 /**
5848 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005849 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005850 */
5851 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5852 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005853
5854 final long identity = Binder.clearCallingIdentity();
5855 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005856 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005857 // may happen if the device does not support IMS.
5858 return null;
5859 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005860 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005861 } finally {
5862 Binder.restoreCallingIdentity(identity);
5863 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005864 }
5865
Brad Ebinger884c07b2018-02-15 16:17:40 -08005866 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005867 * Sets the ImsService Package Name that Telephony will bind to.
5868 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005869 * @param slotIndex the slot ID that the ImsService should bind for.
5870 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005871 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005872 * @param featureTypes An integer array of feature types associated with a packageName.
5873 * @param packageName The name of the package that the current configuration will be replaced
5874 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005875 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005876 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005877 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5878 int[] featureTypes, String packageName) {
5879 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5880 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5882 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005883 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005884
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005885 final long identity = Binder.clearCallingIdentity();
5886 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005887 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005888 // may happen if the device does not support IMS.
5889 return false;
5890 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005891 Map<Integer, String> featureConfig = new HashMap<>();
5892 for (int featureType : featureTypes) {
5893 featureConfig.put(featureType, packageName);
5894 }
5895 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5896 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 } finally {
5898 Binder.restoreCallingIdentity(identity);
5899 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005900 }
5901
5902 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005903 * Clears any carrier ImsService overrides for the slot index specified that were previously
5904 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5905 *
5906 * This should only be used for testing.
5907 *
5908 * @param slotIndex the slot ID that the ImsService should bind for.
5909 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5910 */
5911 @Override
5912 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5913 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5914 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5915 "clearCarrierImsServiceOverride");
5916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5917 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5918 "clearCarrierImsServiceOverride");
5919
5920 final long identity = Binder.clearCallingIdentity();
5921 try {
5922 if (mImsResolver == null) {
5923 // may happen if the device does not support IMS.
5924 return false;
5925 }
5926 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5927 } finally {
5928 Binder.restoreCallingIdentity(identity);
5929 }
5930 }
5931
5932 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005933 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005934 *
5935 * @param slotId The slot that the ImsService is associated with.
5936 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5937 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005938 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005939 * @return the package name of the ImsService configuration.
5940 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005941 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5942 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005943 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005944 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005945 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005946 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5947 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 final long identity = Binder.clearCallingIdentity();
5950 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005951 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005952 // may happen if the device does not support IMS.
5953 return "";
5954 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005955 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005956 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5957 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 } finally {
5959 Binder.restoreCallingIdentity(identity);
5960 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005961 }
5962
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005963 /**
5964 * Get the MmTelFeature state associated with the requested subscription id.
5965 * @param subId The subscription that the MmTelFeature is associated with.
5966 * @param callback A callback with an integer containing the
5967 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5968 */
5969 @Override
5970 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5971 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5972 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5973 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5974 "IMS not available on device.");
5975 }
5976 final long token = Binder.clearCallingIdentity();
5977 try {
5978 int slotId = getSlotIndex(subId);
5979 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5980 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5981 + subId + "'");
5982 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5983 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005984 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005985 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5986 try {
5987 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5988 } catch (RemoteException e) {
5989 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5990 + "Ignore");
5991 }
5992 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005993 } catch (ImsException e) {
5994 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005995 } finally {
5996 Binder.restoreCallingIdentity(token);
5997 }
5998 }
5999
Daniel Brightbb5840b2021-01-12 15:48:18 -08006000 /**
6001 * Sets the ims registration state on all valid {@link Phone}s.
6002 */
6003 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005
6006 final long identity = Binder.clearCallingIdentity();
6007 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006008 // NOTE: Before S, this method only set the default phone.
6009 for (final Phone phone : PhoneFactory.getPhones()) {
6010 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6011 phone.setImsRegistrationState(registered);
6012 }
6013 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 } finally {
6015 Binder.restoreCallingIdentity(identity);
6016 }
Wink Saville36469e72014-06-11 15:17:00 -07006017 }
6018
6019 /**
Stuart Scott54788802015-03-30 13:18:01 -07006020 * Set the network selection mode to automatic.
6021 *
6022 */
6023 @Override
6024 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6026 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027
6028 final long identity = Binder.clearCallingIdentity();
6029 try {
shilufc958392020-01-20 11:36:01 -08006030 if (!isActiveSubscription(subId)) {
6031 return;
6032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006034 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6035 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 } finally {
6037 Binder.restoreCallingIdentity(identity);
6038 }
Stuart Scott54788802015-03-30 13:18:01 -07006039 }
6040
Jack Yud10cdd42020-09-28 20:28:01 -07006041 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006042 * Ask the radio to connect to the input network and change selection mode to manual.
6043 *
6044 * @param subId the id of the subscription.
6045 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6046 * the operator to attach to.
6047 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6048 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6049 * normal network selection next time.
6050 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006051 */
6052 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006053 public boolean setNetworkSelectionModeManual(
6054 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6056 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006057
6058 if (!isActiveSubscription(subId)) {
6059 return false;
6060 }
6061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 final long identity = Binder.clearCallingIdentity();
6063 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006064 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006066 if (DBG) {
6067 log("setNetworkSelectionModeManual: subId: " + subId
6068 + " operator: " + operatorInfo);
6069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6071 } finally {
6072 Binder.restoreCallingIdentity(identity);
6073 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006074 }
shilu84f6e8b2019-12-19 13:58:01 -08006075 /**
6076 * Get the manual network selection
6077 *
6078 * @param subId the id of the subscription.
6079 *
6080 * @return the previously saved user selected PLMN
6081 */
6082 @Override
6083 public String getManualNetworkSelectionPlmn(int subId) {
6084 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006085 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006086 mApp, subId, "getManualNetworkSelectionPlmn");
6087
6088 final long identity = Binder.clearCallingIdentity();
6089 try {
6090 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006091 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006092 }
6093
6094 final Phone phone = getPhone(subId);
6095 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006096 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006097 }
6098 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6099 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6100 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
6104 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006105
6106 /**
6107 * Scans for available networks.
6108 */
6109 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006110 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6111 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6113 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006114 LocationAccessPolicy.LocationPermissionResult locationResult =
6115 LocationAccessPolicy.checkLocationPermission(mApp,
6116 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6117 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006118 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006119 .setCallingPid(Binder.getCallingPid())
6120 .setCallingUid(Binder.getCallingUid())
6121 .setMethod("getCellNetworkScanResults")
6122 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006123 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6124 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006125 .build());
6126 switch (locationResult) {
6127 case DENIED_HARD:
6128 throw new SecurityException("Not allowed to access scan results -- location");
6129 case DENIED_SOFT:
6130 return null;
6131 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132
Pengquan Menga1bb6272018-09-06 09:59:22 -07006133 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 try {
6135 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006136 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 } finally {
6139 Binder.restoreCallingIdentity(identity);
6140 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006141 }
6142
6143 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006144 * Get the call forwarding info, given the call forwarding reason.
6145 */
6146 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006147 public void getCallForwarding(int subId, int callForwardingReason,
6148 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006149 enforceReadPrivilegedPermission("getCallForwarding");
6150 long identity = Binder.clearCallingIdentity();
6151 try {
6152 if (DBG) {
6153 log("getCallForwarding: subId " + subId
6154 + " callForwardingReason" + callForwardingReason);
6155 }
Hall Liu27d24262020-09-18 19:04:59 -07006156
6157 Phone phone = getPhone(subId);
6158 if (phone == null) {
6159 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006160 callback.onError(
6161 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006162 } catch (RemoteException e) {
6163 // ignore
6164 }
6165 return;
6166 }
6167
6168 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6169 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6170 @Override
6171 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6172 try {
6173 callback.onCallForwardingInfoAvailable(info);
6174 } catch (RemoteException e) {
6175 // ignore
6176 }
6177 }
6178
6179 @Override
6180 public void onError(int error) {
6181 try {
6182 callback.onError(error);
6183 } catch (RemoteException e) {
6184 // ignore
6185 }
6186 }
6187 });
6188 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006189 } finally {
6190 Binder.restoreCallingIdentity(identity);
6191 }
6192 }
6193
6194 /**
6195 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6196 * reason, the number to forward, and the timeout before the forwarding is attempted.
6197 */
6198 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006199 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6200 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006201 enforceModifyPermission();
6202 long identity = Binder.clearCallingIdentity();
6203 try {
6204 if (DBG) {
6205 log("setCallForwarding: subId " + subId
6206 + " callForwardingInfo" + callForwardingInfo);
6207 }
Hall Liu27d24262020-09-18 19:04:59 -07006208
6209 Phone phone = getPhone(subId);
6210 if (phone == null) {
6211 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006212 callback.accept(
6213 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006214 } catch (RemoteException e) {
6215 // ignore
6216 }
6217 return;
6218 }
6219
6220 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6221 FunctionalUtils.ignoreRemoteException(callback::accept));
6222
6223 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006224 } finally {
6225 Binder.restoreCallingIdentity(identity);
6226 }
6227 }
6228
6229 /**
Hall Liu27d24262020-09-18 19:04:59 -07006230 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006231 */
6232 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006233 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006234 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006235 long identity = Binder.clearCallingIdentity();
6236 try {
Hall Liu27d24262020-09-18 19:04:59 -07006237 Phone phone = getPhone(subId);
6238 if (phone == null) {
6239 try {
6240 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6241 } catch (RemoteException e) {
6242 // ignore
6243 }
6244 return;
6245 }
SongFerngWang0e767992021-03-31 22:08:45 +08006246 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6247 PersistableBundle c = configManager.getConfigForSubId(subId);
6248 boolean requireUssd = c.getBoolean(
6249 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006250
Shuo Qian4a594052020-01-23 11:59:30 -08006251 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006252 if (requireUssd) {
6253 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6254 getSubscriptionCarrierId(subId));
6255 String newUssdCommand = "";
6256 try {
6257 newUssdCommand = carrierXmlParser.getFeature(
6258 CarrierXmlParser.FEATURE_CALL_WAITING)
6259 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6260 } catch (NullPointerException e) {
6261 loge("Failed to generate USSD number" + e);
6262 }
6263 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6264 mMainThreadHandler, callback, carrierXmlParser,
6265 CarrierXmlParser.SsEntry.SSAction.QUERY);
6266 final String ussdCommand = newUssdCommand;
6267 Executors.newSingleThreadExecutor().execute(() -> {
6268 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6269 });
6270 } else {
6271 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6272 callback::accept);
6273 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6274 }
Shuo Qian4a594052020-01-23 11:59:30 -08006275 } finally {
6276 Binder.restoreCallingIdentity(identity);
6277 }
6278 }
6279
6280 /**
Hall Liu27d24262020-09-18 19:04:59 -07006281 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006282 */
6283 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006284 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006285 enforceModifyPermission();
6286 long identity = Binder.clearCallingIdentity();
6287 try {
Hall Liu27d24262020-09-18 19:04:59 -07006288 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6289
6290 Phone phone = getPhone(subId);
6291 if (phone == null) {
6292 try {
6293 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6294 } catch (RemoteException e) {
6295 // ignore
6296 }
6297 return;
6298 }
6299
SongFerngWang0e767992021-03-31 22:08:45 +08006300 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6301 PersistableBundle c = configManager.getConfigForSubId(subId);
6302 boolean requireUssd = c.getBoolean(
6303 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006304
SongFerngWang0e767992021-03-31 22:08:45 +08006305 if (DBG) log("getCallWaitingStatus: subId " + subId);
6306 if (requireUssd) {
6307 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6308 getSubscriptionCarrierId(subId));
6309 CarrierXmlParser.SsEntry.SSAction ssAction =
6310 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6311 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6312 String newUssdCommand = "";
6313 try {
6314 newUssdCommand = carrierXmlParser.getFeature(
6315 CarrierXmlParser.FEATURE_CALL_WAITING)
6316 .makeCommand(ssAction, null);
6317 } catch (NullPointerException e) {
6318 loge("Failed to generate USSD number" + e);
6319 }
6320 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6321 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6322 final String ussdCommand = newUssdCommand;
6323 Executors.newSingleThreadExecutor().execute(() -> {
6324 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6325 });
6326 } else {
6327 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6328 FunctionalUtils.ignoreRemoteException(callback::accept));
6329
6330 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6331 }
Shuo Qian4a594052020-01-23 11:59:30 -08006332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
6335 }
6336
6337 /**
yinxub1bed742017-04-17 11:45:04 -07006338 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006339 *
yinxub1bed742017-04-17 11:45:04 -07006340 * @param subId id of the subscription
6341 * @param request contains the radio access networks with bands/channels to scan
6342 * @param messenger callback messenger for scan results or errors
6343 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006344 * @return the id of the requested scan which can be used to stop the scan.
6345 */
6346 @Override
6347 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006348 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6350 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006351 LocationAccessPolicy.LocationPermissionResult locationResult =
6352 LocationAccessPolicy.checkLocationPermission(mApp,
6353 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6354 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006355 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006356 .setCallingPid(Binder.getCallingPid())
6357 .setCallingUid(Binder.getCallingUid())
6358 .setMethod("requestNetworkScan")
6359 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006360 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6361 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006362 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006363 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006364 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6365 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006366 if (e != null) {
6367 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6368 throw e;
6369 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006370 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006371 return TelephonyScanManager.INVALID_SCAN_ID;
6372 }
6373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374 }
Hall Liu912dfd32019-04-25 14:02:26 -07006375 int callingUid = Binder.getCallingUid();
6376 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006377 final long identity = Binder.clearCallingIdentity();
6378 try {
6379 return mNetworkScanRequestTracker.startNetworkScan(
6380 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006381 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
yinxu504e1392017-04-12 16:03:22 -07006385 }
6386
Hall Liub2ac8ef2019-02-28 15:56:23 -08006387 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006388 NetworkScanRequest request, int subId, String callingPackage) {
6389 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006390 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6391 boolean hasNetworkScanPermission =
6392 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6393 == PERMISSION_GRANTED;
6394
6395 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6396 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6397 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006398 }
6399
6400 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6401 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006402 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6403 return new SecurityException("Specific channels must not be"
6404 + " scanned without location access.");
6405 }
6406 }
6407 }
6408
Hall Liub2ac8ef2019-02-28 15:56:23 -08006409 return null;
6410 }
6411
yinxu504e1392017-04-12 16:03:22 -07006412 /**
6413 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006414 *
6415 * @param subId id of the subscription
6416 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006417 */
6418 @Override
6419 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6421 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422
Hall Liu912dfd32019-04-25 14:02:26 -07006423 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424 final long identity = Binder.clearCallingIdentity();
6425 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006426 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
yinxu504e1392017-04-12 16:03:22 -07006430 }
6431
6432 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006433 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006434 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006435 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006436 */
6437 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006438 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006439 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006440 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006441 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006442
6443 final long identity = Binder.clearCallingIdentity();
6444 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006445 if (DBG) log("getAllowedNetworkTypesBitmask");
6446 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6447 int networkTypesBitmask = (result != null ? result[0] : -1);
6448 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6449 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006453 }
6454
6455 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006456 * Get the allowed network types for certain reason.
6457 *
6458 * @param subId the id of the subscription.
6459 * @param reason the reason the allowed network type change is taking place
6460 * @return the allowed network types.
6461 */
6462 @Override
6463 public long getAllowedNetworkTypesForReason(int subId,
6464 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006465 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006466 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006467 final long identity = Binder.clearCallingIdentity();
6468 try {
6469 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
6473 }
6474
6475 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006476 * Enable/Disable E-UTRA-NR Dual Connectivity
6477 * @param subId subscription id of the sim card
6478 * @param nrDualConnectivityState expected NR dual connectivity state
6479 * This can be passed following states
6480 * <ol>
6481 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6482 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6483 * <li>Disable NR dual connectivity and force secondary cell to be released
6484 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6485 * </ol>
6486 * @return operation result.
6487 */
6488 @Override
6489 public int setNrDualConnectivityState(int subId,
6490 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6492 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006493 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006494 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6495 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6496 }
6497
Sooraj Sasindran37444802020-08-11 10:40:43 -07006498 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6499 final long identity = Binder.clearCallingIdentity();
6500 try {
6501 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6502 nrDualConnectivityState, subId,
6503 workSource);
6504 if (DBG) log("enableNRDualConnectivity result: " + result);
6505 return result;
6506 } finally {
6507 Binder.restoreCallingIdentity(identity);
6508 }
6509 }
6510
6511 /**
6512 * Is E-UTRA-NR Dual Connectivity enabled
6513 * @return true if dual connectivity is enabled else false
6514 */
6515 @Override
6516 public boolean isNrDualConnectivityEnabled(int subId) {
6517 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006518 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006519 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006520 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006521 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6522 return false;
6523 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006524 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6525 final long identity = Binder.clearCallingIdentity();
6526 try {
6527 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6528 null, subId, workSource);
6529 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6530 return isEnabled;
6531 } finally {
6532 Binder.restoreCallingIdentity(identity);
6533 }
6534 }
6535
6536 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006537 * Set the allowed network types of the device and
6538 * provide the reason triggering the allowed network change.
6539 *
6540 * @param subId the id of the subscription.
6541 * @param reason the reason the allowed network type change is taking place
6542 * @param allowedNetworkTypes the allowed network types.
6543 * @return true on success; false on any failure.
6544 */
6545 @Override
6546 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 @TelephonyManager.AllowedNetworkTypesReason int reason,
6548 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6550 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006551 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006552 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6553 return false;
6554 }
6555 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6556 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006557 return false;
6558 }
6559
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006560 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6561 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6562
6563
6564 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6565 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6566 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006567 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006568
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006569 final long identity = Binder.clearCallingIdentity();
6570 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006571 Boolean success = (Boolean) sendRequest(
6572 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6573 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6574
6575 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6576 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006577 } finally {
6578 Binder.restoreCallingIdentity(identity);
6579 }
6580 }
6581
6582 /**
Miaoa84611c2019-03-15 09:21:10 +08006583 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006584 *
Miaoa84611c2019-03-15 09:21:10 +08006585 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006586 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006587 * @hide
6588 */
6589 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006590 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006591 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006592 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006593 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594 try {
Miaoa84611c2019-03-15 09:21:10 +08006595 if (phone != null) {
6596 return phone.hasMatchedTetherApnSetting();
6597 } else {
6598 return false;
6599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600 } finally {
6601 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006602 }
Junda Liu475951f2014-11-07 16:45:03 -08006603 }
6604
6605 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006606 * Get the user enabled state of Mobile Data.
6607 *
6608 * TODO: remove and use isUserDataEnabled.
6609 * This can't be removed now because some vendor codes
6610 * calls through ITelephony directly while they should
6611 * use TelephonyManager.
6612 *
6613 * @return true on enabled
6614 */
6615 @Override
6616 public boolean getDataEnabled(int subId) {
6617 return isUserDataEnabled(subId);
6618 }
6619
6620 /**
6621 * Get whether mobile data is enabled per user setting.
6622 *
6623 * There are other factors deciding whether mobile data is actually enabled, but they are
6624 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006625 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006626 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006627 *
6628 * @return {@code true} if data is enabled else {@code false}
6629 */
6630 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006631 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006632 try {
6633 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6634 null);
6635 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6637 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639
6640 final long identity = Binder.clearCallingIdentity();
6641 try {
6642 int phoneId = mSubscriptionController.getPhoneId(subId);
6643 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6644 Phone phone = PhoneFactory.getPhone(phoneId);
6645 if (phone != null) {
6646 boolean retVal = phone.isUserDataEnabled();
6647 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6648 return retVal;
6649 } else {
6650 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6651 return false;
6652 }
6653 } finally {
6654 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006655 }
6656 }
6657
6658 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006659 * Checks if the device is capable of mobile data by considering whether whether the
6660 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6661 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006662 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006663 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006664 */
6665 @Override
6666 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006667 try {
6668 try {
6669 mApp.enforceCallingOrSelfPermission(
6670 android.Manifest.permission.ACCESS_NETWORK_STATE,
6671 null);
6672 } catch (Exception e) {
6673 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6674 "isDataEnabled");
6675 }
6676 } catch (Exception e) {
6677 enforceReadPrivilegedPermission("isDataEnabled");
6678 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006679
6680 final long identity = Binder.clearCallingIdentity();
6681 try {
6682 int phoneId = mSubscriptionController.getPhoneId(subId);
6683 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6684 Phone phone = PhoneFactory.getPhone(phoneId);
6685 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006686 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006687 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6688 return retVal;
6689 } else {
6690 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6691 return false;
6692 }
6693 } finally {
6694 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006695 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006696 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006697
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006698 /**
6699 * Check if data is enabled for a specific reason
6700 * @param subId Subscription index
6701 * @param reason the reason the data enable change is taking place
6702 * @return {@code true} if the overall data is enabled; {@code false} if not.
6703 */
6704 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006705 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006706 @TelephonyManager.DataEnabledReason int reason) {
6707 try {
6708 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6709 null);
6710 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006711 try {
6712 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6713 "isDataEnabledForReason");
6714 } catch (Exception e2) {
6715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6716 mApp, subId, "isDataEnabledForReason");
6717 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006718 }
6719
6720
6721 final long identity = Binder.clearCallingIdentity();
6722 try {
6723 int phoneId = mSubscriptionController.getPhoneId(subId);
6724 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006725 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006726 + " reason=" + reason);
6727 }
6728 Phone phone = PhoneFactory.getPhone(phoneId);
6729 if (phone != null) {
6730 boolean retVal;
6731 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6732 retVal = phone.isUserDataEnabled();
6733 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006734 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006735 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006736 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006737 return retVal;
6738 } else {
6739 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006740 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006741 + subId + " retVal=false");
6742 }
6743 return false;
6744 }
6745 } finally {
6746 Binder.restoreCallingIdentity(identity);
6747 }
6748 }
6749
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006750 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006751 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006752 if (uid == Process.PHONE_UID) {
6753 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6754 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006755 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6756 }
6757
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006758 //load access rules from carrier configs, and check those as well: b/139133814
6759 SubscriptionController subController = SubscriptionController.getInstance();
6760 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6761 || subController == null) return privilegeFromSim;
6762
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006763 PackageManager pkgMgr = phone.getContext().getPackageManager();
6764 String[] packages = pkgMgr.getPackagesForUid(uid);
6765
6766 final long identity = Binder.clearCallingIdentity();
6767 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006768 int subId = phone.getSubId();
6769 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6770 // A test override is in place for the privileges for this subId, so don't try to
6771 // read the subscription privileges.
6772 return privilegeFromSim;
6773 }
6774 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006775 SubscriptionManager subManager = (SubscriptionManager)
6776 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6777 for (String pkg : packages) {
6778 if (subManager.canManageSubscription(subInfo, pkg)) {
6779 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6780 }
6781 }
6782 return privilegeFromSim;
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
6785 }
6786 }
6787
6788 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6789 String pkgName) {
6790 //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
6795 final long identity = Binder.clearCallingIdentity();
6796 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006797 int subId = phone.getSubId();
6798 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6799 // A test override is in place for the privileges for this subId, so don't try to
6800 // read the subscription privileges.
6801 return privilegeFromSim;
6802 }
6803 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006804 SubscriptionManager subManager = (SubscriptionManager)
6805 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6806 return subManager.canManageSubscription(subInfo, pkgName)
6807 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6808 } finally {
6809 Binder.restoreCallingIdentity(identity);
6810 }
6811 }
6812
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006813 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006814 public int getCarrierPrivilegeStatus(int subId) {
6815 final Phone phone = getPhone(subId);
6816 if (phone == null) {
6817 loge("getCarrierPrivilegeStatus: Invalid subId");
6818 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6819 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006820 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6821 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006822 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006823 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6824 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006825
6826 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006827 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006828 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006829 }
Junda Liu29340342014-07-10 15:23:27 -07006830
6831 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006832 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006833 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006834 final Phone phone = getPhone(subId);
6835 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006836 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006837 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6838 }
6839 UiccProfile profile =
6840 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6841 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006842 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006843 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6844 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006845 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006846 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006847 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006848 }
6849
6850 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006851 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006852 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006853 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006854 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006855 }
6856
6857 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006858 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6859 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006860 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006861 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6862 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006863 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006864 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006865 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006866 }
6867
6868 @Override
6869 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006870 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006871 if (TextUtils.isEmpty(pkgName))
6872 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006873 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6874 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006875 UiccPort port = UiccController.getInstance().getUiccPort(i);
6876 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006877 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006878 continue;
6879 }
6880
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006881 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006882 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006883 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006884 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6885 break;
6886 }
6887 }
6888
6889 return result;
Junda Liu29340342014-07-10 15:23:27 -07006890 }
Derek Tan89e89d42014-07-08 17:00:10 -07006891
6892 @Override
Junda Liue64de782015-04-16 17:19:16 -07006893 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006894 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006895 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6896 loge("phoneId " + phoneId + " is not valid.");
6897 return null;
6898 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006899 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6900 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006901 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006902 return null ;
6903 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006904 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006905 }
6906
Amith Yamasani6e118872016-02-19 12:53:51 -08006907 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006908 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006909 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006910 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006911 List<String> privilegedPackages = new ArrayList<>();
6912 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006913 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006914 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006915 if (port != null) {
6916 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006917 if (packages == null) {
6918 // Only check packages in user 0 for now
6919 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006920 PackageManager.MATCH_DISABLED_COMPONENTS
6921 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006922 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006923 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006924 }
6925 for (int p = packages.size() - 1; p >= 0; p--) {
6926 PackageInfo pkgInfo = packages.get(p);
6927 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006928 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6929 port.getCarrierPrivilegeStatus(pkgInfo),
6930 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006931 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006932 privilegedPackages.add(pkgInfo.packageName);
6933 }
6934 }
6935 }
6936 }
6937 return privilegedPackages;
6938 }
6939
chen xuf7e9fe82019-05-09 19:31:02 -07006940 @Override
6941 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006942 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6943
6944 final long identity = Binder.clearCallingIdentity();
6945
chen xuf7e9fe82019-05-09 19:31:02 -07006946 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006947 try {
6948 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6949 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6950 }
6951 } finally {
6952 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006953 }
6954 return privilegedPackages;
6955 }
6956
Wink Savilleb564aae2014-10-23 10:18:09 -07006957 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006958 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006959 UiccPort port = phone == null ? null : phone.getUiccPort();
6960 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006961 return null;
6962 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006963 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006964 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006965 return null;
6966 }
6967 return iccId;
6968 }
6969
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006970 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006971 public void setCallComposerStatus(int subId, int status) {
6972 enforceModifyPermission();
6973
6974 final long identity = Binder.clearCallingIdentity();
6975 try {
6976 Phone phone = getPhone(subId);
6977 if (phone != null) {
6978 Phone defaultPhone = phone.getImsPhone();
6979 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6980 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6981 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006982 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6983 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006984 }
6985 }
Shuo Qian284ae752020-12-22 19:10:14 -08006986 } catch (ImsException e) {
6987 throw new ServiceSpecificException(e.getCode());
6988 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006989 Binder.restoreCallingIdentity(identity);
6990 }
6991 }
6992
6993 @Override
6994 public int getCallComposerStatus(int subId) {
6995 enforceReadPrivilegedPermission("getCallComposerStatus");
6996
6997 final long identity = Binder.clearCallingIdentity();
6998 try {
6999 Phone phone = getPhone(subId);
7000 if (phone != null) {
7001 Phone defaultPhone = phone.getImsPhone();
7002 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7003 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7004 return imsPhone.getCallComposerStatus();
7005 }
7006 }
7007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
7010 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7011 }
7012
7013 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007014 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7015 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007016 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007017 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 final long identity = Binder.clearCallingIdentity();
7020 try {
7021 final String iccId = getIccId(subId);
7022 final Phone phone = getPhone(subId);
7023 if (phone == null) {
7024 return false;
7025 }
7026 final String subscriberId = phone.getSubscriberId();
7027
7028 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007029 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030 + subscriberId + " to " + number);
7031 }
7032
7033 if (TextUtils.isEmpty(iccId)) {
7034 return false;
7035 }
7036
7037 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7038
7039 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7040 if (alphaTag == null) {
7041 editor.remove(alphaTagPrefKey);
7042 } else {
7043 editor.putString(alphaTagPrefKey, alphaTag);
7044 }
7045
7046 // Record both the line number and IMSI for this ICCID, since we need to
7047 // track all merged IMSIs based on line number
7048 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7049 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7050 if (number == null) {
7051 editor.remove(numberPrefKey);
7052 editor.remove(subscriberPrefKey);
7053 } else {
7054 editor.putString(numberPrefKey, number);
7055 editor.putString(subscriberPrefKey, subscriberId);
7056 }
7057
7058 editor.commit();
7059 return true;
7060 } finally {
7061 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007062 }
Derek Tan7226c842014-07-02 17:42:23 -07007063 }
7064
7065 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007066 public String getLine1NumberForDisplay(int subId, String callingPackage,
7067 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007068 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007070 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007071 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007072 return null;
7073 }
Derek Tan97ebb422014-09-05 16:55:38 -07007074
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 final long identity = Binder.clearCallingIdentity();
7076 try {
7077 String iccId = getIccId(subId);
7078 if (iccId != null) {
7079 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7080 if (DBG_MERGE) {
7081 log("getLine1NumberForDisplay returning "
7082 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7083 }
7084 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007086 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7087 return null;
7088 } finally {
7089 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007090 }
Derek Tan7226c842014-07-02 17:42:23 -07007091 }
7092
7093 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007094 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7095 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007096 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007097 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007098 return null;
7099 }
Derek Tan97ebb422014-09-05 16:55:38 -07007100
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101 final long identity = Binder.clearCallingIdentity();
7102 try {
7103 String iccId = getIccId(subId);
7104 if (iccId != null) {
7105 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7106 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7107 }
7108 return null;
7109 } finally {
7110 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007111 }
Derek Tan7226c842014-07-02 17:42:23 -07007112 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007113
7114 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007115 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7116 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007117 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7118 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007120 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007121 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007122 return null;
7123 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007124
Jordan Liub49b04b2019-05-06 14:45:15 -07007125 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7126 // the process, where TelephonyManager was instantiated.
7127 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007128 final long identity = Binder.clearCallingIdentity();
7129 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007130 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131 final TelephonyManager tele = TelephonyManager.from(context);
7132 final SubscriptionManager sub = SubscriptionManager.from(context);
7133
7134 // Figure out what subscribers are currently active
7135 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136
Jordan Liub49b04b2019-05-06 14:45:15 -07007137 // Only consider subs which match the current subId
7138 // This logic can be simplified. See b/131189269 for progress.
7139 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007140 activeSubscriberIds.add(tele.getSubscriberId(subId));
7141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142
7143 // First pass, find a number override for an active subscriber
7144 String mergeNumber = null;
7145 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7146 for (String key : prefs.keySet()) {
7147 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7148 final String subscriberId = (String) prefs.get(key);
7149 if (activeSubscriberIds.contains(subscriberId)) {
7150 final String iccId = key.substring(
7151 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7152 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7153 mergeNumber = (String) prefs.get(numberKey);
7154 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007155 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156 + " for active subscriber " + subscriberId);
7157 }
7158 if (!TextUtils.isEmpty(mergeNumber)) {
7159 break;
7160 }
7161 }
7162 }
7163 }
7164
7165 // Shortcut when no active merged subscribers
7166 if (TextUtils.isEmpty(mergeNumber)) {
7167 return null;
7168 }
7169
7170 // Second pass, find all subscribers under that line override
7171 final ArraySet<String> result = new ArraySet<>();
7172 for (String key : prefs.keySet()) {
7173 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7174 final String number = (String) prefs.get(key);
7175 if (mergeNumber.equals(number)) {
7176 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7177 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7178 final String subscriberId = (String) prefs.get(subscriberKey);
7179 if (!TextUtils.isEmpty(subscriberId)) {
7180 result.add(subscriberId);
7181 }
7182 }
7183 }
7184 }
7185
7186 final String[] resultArray = result.toArray(new String[result.size()]);
7187 Arrays.sort(resultArray);
7188 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007189 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7191 }
7192 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007193 } finally {
7194 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007195 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007196 }
7197
7198 @Override
zoey chen38003472019-12-13 17:16:31 +08007199 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7200 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007201
7202 final long identity = Binder.clearCallingIdentity();
7203 try {
7204 final TelephonyManager telephonyManager = mApp.getSystemService(
7205 TelephonyManager.class);
7206 String subscriberId = telephonyManager.getSubscriberId(subId);
7207 if (subscriberId == null) {
7208 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007209 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007210 + subId);
7211 }
7212 return null;
7213 }
7214
7215 final SubscriptionInfo info = SubscriptionController.getInstance()
7216 .getSubscriptionInfo(subId);
7217 final ParcelUuid groupUuid = info.getGroupUuid();
7218 // If it doesn't belong to any group, return just subscriberId of itself.
7219 if (groupUuid == null) {
7220 return new String[]{subscriberId};
7221 }
7222
7223 // Get all subscriberIds from the group.
7224 final List<String> mergedSubscriberIds = new ArrayList<>();
7225 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007226 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007227 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007228 for (SubscriptionInfo subInfo : groupInfos) {
7229 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7230 if (subscriberId != null) {
7231 mergedSubscriberIds.add(subscriberId);
7232 }
7233 }
7234
7235 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238
7239 }
7240 }
7241
7242 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007243 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007244 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007245 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246
7247 final long identity = Binder.clearCallingIdentity();
7248 try {
7249 final Phone phone = getPhone(subId);
7250 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7251 } finally {
7252 Binder.restoreCallingIdentity(identity);
7253 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007254 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007255
7256 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007257 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007258 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7259 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007260 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7261 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007262
7263 final long identity = Binder.clearCallingIdentity();
7264 try {
7265 final Phone phone = getPhone(subId);
7266 if (phone == null) {
7267 return false;
7268 }
7269 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7270 cdmaNonRoamingList);
7271 } finally {
7272 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007273 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007274 }
7275
7276 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007277 @Deprecated
7278 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7279 enforceModifyPermission();
7280
7281 int returnValue = 0;
7282 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007283 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007284 if(result.exception == null) {
7285 if (result.result != null) {
7286 byte[] responseData = (byte[])(result.result);
7287 if(responseData.length > oemResp.length) {
7288 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7289 responseData.length + "bytes. Buffer Size is " +
7290 oemResp.length + "bytes.");
7291 }
7292 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7293 returnValue = responseData.length;
7294 }
7295 } else {
7296 CommandException ex = (CommandException) result.exception;
7297 returnValue = ex.getCommandError().ordinal();
7298 if(returnValue > 0) returnValue *= -1;
7299 }
7300 } catch (RuntimeException e) {
7301 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7302 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7303 if(returnValue > 0) returnValue *= -1;
7304 }
7305
7306 return returnValue;
7307 }
7308
7309 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007310 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007311 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007312 try {
7313 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007314 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007315 mApp, phone.getSubId(), "getRadioAccessFamily");
7316 } catch (SecurityException e) {
7317 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7318 throw e;
7319 }
chen xub97461a2018-10-26 14:17:57 -07007320 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007321 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007322 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 final long identity = Binder.clearCallingIdentity();
7325 try {
chen xub97461a2018-10-26 14:17:57 -07007326 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007327 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007328 mApp, phone.getSubId(), "getRadioAccessFamily");
7329 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 } finally {
7331 Binder.restoreCallingIdentity(identity);
7332 }
chen xub97461a2018-10-26 14:17:57 -07007333 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007334 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007335
7336 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007337 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007338 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007339 try {
7340 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7341 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007342 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007343 }
7344 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007345 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007346 }
7347 RoleManager rm = mApp.getSystemService(RoleManager.class);
7348 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7349 if (!dialerRoleHolders.contains(callingPackage)) {
7350 throw new SecurityException("App must be the dialer role holder to"
7351 + " upload a call composer pic");
7352 }
7353
7354 Executors.newSingleThreadExecutor().execute(() -> {
7355 ByteArrayOutputStream output = new ByteArrayOutputStream(
7356 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7357 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7358 boolean readUntilEnd = false;
7359 int totalBytesRead = 0;
7360 byte[] buffer = new byte[16 * 1024];
7361 while (true) {
7362 int numRead;
7363 try {
7364 numRead = input.read(buffer);
7365 } catch (IOException e) {
7366 try {
7367 fd.checkError();
7368 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7369 null);
7370 } catch (IOException e1) {
7371 // This means that the other side closed explicitly with an error. If this
7372 // happens, log and ignore.
7373 loge("Remote end of call composer picture pipe closed: " + e1);
7374 }
7375 break;
7376 }
7377 if (numRead == -1) {
7378 readUntilEnd = true;
7379 break;
7380 }
7381 totalBytesRead += numRead;
7382 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7383 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7384 try {
7385 input.close();
7386 } catch (IOException e) {
7387 // ignore
7388 }
7389 break;
7390 }
7391 output.write(buffer, 0, numRead);
7392 }
7393 // Generally, the remote end will close the file descriptors. The only case where we
7394 // close is above, where the picture size is too big.
7395
7396 try {
7397 fd.checkError();
7398 } catch (IOException e) {
7399 loge("Remote end for call composer closed with an error: " + e);
7400 return;
7401 }
7402
Hall Liuaa4211e2021-01-20 15:43:39 -08007403 if (!readUntilEnd) {
7404 loge("Did not finish reading entire image; aborting");
7405 return;
7406 }
Hall Liu82694d52020-12-11 18:22:04 -08007407
Hall Liuaa4211e2021-01-20 15:43:39 -08007408 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7409 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7410 new CallComposerPictureTransfer.Factory() {},
7411 imageData,
7412 (result) -> {
7413 if (result.first != null) {
7414 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7415 Bundle outputResult = new Bundle();
7416 outputResult.putParcelable(
7417 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7418 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7419 outputResult);
7420 } else {
7421 callback.send(result.second, null);
7422 }
7423 }
7424 );
Hall Liu82694d52020-12-11 18:22:04 -08007425 });
7426 }
7427
7428 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007429 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007430 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007431 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432
7433 final long identity = Binder.clearCallingIdentity();
7434 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007435 ImsManager.getInstance(defaultPhone.getContext(),
7436 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 } finally {
7438 Binder.restoreCallingIdentity(identity);
7439 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007440 }
7441
7442 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007443 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007444 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7446 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007447 return false;
7448 }
Svet Ganovb320e182015-04-16 12:30:10 -07007449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450 final long identity = Binder.clearCallingIdentity();
7451 try {
7452 // Check the user preference and the system-level IMS setting. Even if the user has
7453 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7454 // In the long run, we may instead need to check if there exists a connection service
7455 // which can support video calling.
7456 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007457 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007458 return imsManager.isVtEnabledByPlatform()
7459 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7460 && imsManager.isVtEnabledByUser();
7461 } finally {
7462 Binder.restoreCallingIdentity(identity);
7463 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007464 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007465
Andrew Leea1239f22015-03-02 17:44:07 -08007466 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007467 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7468 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007470 mApp, subId, callingPackage, callingFeatureId,
7471 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 return false;
7473 }
7474
7475 final long identity = Binder.clearCallingIdentity();
7476 try {
7477 CarrierConfigManager configManager =
7478 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007479 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7481 } finally {
7482 Binder.restoreCallingIdentity(identity);
7483 }
Andrew Leea1239f22015-03-02 17:44:07 -08007484 }
7485
7486 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007487 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007489 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 return false;
7491 }
7492
7493 final long identity = Binder.clearCallingIdentity();
7494 try {
7495 CarrierConfigManager configManager =
7496 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007497 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007498 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7499 } finally {
7500 Binder.restoreCallingIdentity(identity);
7501 }
Andrew Leea1239f22015-03-02 17:44:07 -08007502 }
7503
Andrew Lee9431b832015-03-09 18:46:45 -07007504 @Override
7505 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007506 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007507 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007508 }
7509
7510 @Override
7511 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 final long identity = Binder.clearCallingIdentity();
7513 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007514 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 } finally {
7516 Binder.restoreCallingIdentity(identity);
7517 }
Andrew Lee9431b832015-03-09 18:46:45 -07007518 }
7519
Hall Liuf6668912018-10-31 17:05:23 -07007520 /**
7521 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7522 * support for the feature and device firmware support.
7523 *
7524 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7525 */
7526 @Override
7527 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007529 final Phone phone = getPhone(subscriptionId);
7530 if (phone == null) {
7531 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7532 return false;
7533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007535 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7537 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007538 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 return isCarrierSupported && isDeviceSupported;
7540 } finally {
7541 Binder.restoreCallingIdentity(identity);
7542 }
Hall Liu98187582018-01-22 19:15:32 -08007543 }
7544
Hall Liuf6668912018-10-31 17:05:23 -07007545 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007546 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7547 * RTT setting, will return true if the device and carrier both support RTT.
7548 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007549 */
7550 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 final long identity = Binder.clearCallingIdentity();
7552 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007553 boolean isRttSupported = isRttSupported(subscriptionId);
7554 boolean isUserRttSettingOn = Settings.Secure.getInt(
7555 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7556 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7557 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7558 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007559 } finally {
7560 Binder.restoreCallingIdentity(identity);
7561 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007562 }
7563
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007564 @Deprecated
7565 @Override
7566 public String getDeviceId(String callingPackage) {
7567 return getDeviceIdWithFeature(callingPackage, null);
7568 }
7569
Sanket Padawe7310cc72015-01-14 09:53:20 -08007570 /**
7571 * Returns the unique device ID of phone, for example, the IMEI for
7572 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7573 *
7574 * <p>Requires Permission:
7575 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7576 */
7577 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007578 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007579 try {
7580 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7581 } catch (SecurityException se) {
7582 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7583 throw new SecurityException("Package " + callingPackage + " does not belong to "
7584 + Binder.getCallingUid());
7585 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007586 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007587 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007588 return null;
7589 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007590 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007591 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007592 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007593 return null;
7594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595
7596 final long identity = Binder.clearCallingIdentity();
7597 try {
7598 return phone.getDeviceId();
7599 } finally {
7600 Binder.restoreCallingIdentity(identity);
7601 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007602 }
7603
Ping Sunc67b7c22016-03-02 19:16:45 +08007604 /**
7605 * {@hide}
7606 * Returns the IMS Registration Status on a particular subid
7607 *
7608 * @param subId
7609 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007610 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007611 Phone phone = getPhone(subId);
7612 if (phone != null) {
7613 return phone.isImsRegistered();
7614 } else {
7615 return false;
7616 }
7617 }
7618
Santos Cordon7a1885b2015-02-03 11:15:19 -08007619 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007620 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007621 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007623 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007624 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7625 }
7626 final long identity = Binder.clearCallingIdentity();
7627 try {
7628 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7629 } finally {
7630 Binder.restoreCallingIdentity(identity);
7631 }
7632 }
7633
7634 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007635 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007636 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007637 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007638 mApp,
7639 subscriptionId,
7640 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007641 final long identity = Binder.clearCallingIdentity();
7642 try {
7643 Phone phone = getPhone(subscriptionId);
7644 if (phone == null) {
7645 return null;
7646 }
7647 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7648 } finally {
7649 Binder.restoreCallingIdentity(identity);
7650 }
7651 }
7652
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007653 /**
7654 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007655 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007656 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657 final long identity = Binder.clearCallingIdentity();
7658 try {
7659 Phone phone = getPhone(subId);
7660 if (phone != null) {
7661 return phone.isWifiCallingEnabled();
7662 } else {
7663 return false;
7664 }
7665 } finally {
7666 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007667 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007668 }
7669
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007670 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007671 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007672 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007673 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 final long identity = Binder.clearCallingIdentity();
7675 try {
7676 Phone phone = getPhone(subId);
7677 if (phone != null) {
7678 return phone.isVideoEnabled();
7679 } else {
7680 return false;
7681 }
7682 } finally {
7683 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007684 }
7685 }
7686
7687 /**
7688 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7689 * defined in {@link ImsRegistrationImplBase}.
7690 */
7691 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007692 final long identity = Binder.clearCallingIdentity();
7693 try {
7694 Phone phone = getPhone(subId);
7695 if (phone != null) {
7696 return phone.getImsRegistrationTech();
7697 } else {
7698 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7699 }
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007702 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007703 }
7704
Stuart Scott8eef64f2015-04-08 15:13:54 -07007705 @Override
7706 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007707 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007708 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7709 return;
7710 }
Kai Shif70f46f2021-03-03 13:59:46 -08007711 Phone defaultPhone = getDefaultPhone();
7712 if (defaultPhone != null) {
7713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7714 mApp, getDefaultPhone().getSubId(), "factoryReset");
7715 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007716 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007717
Svet Ganovcc087f82015-05-12 20:35:54 -07007718 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007719 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7720 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007721 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007722 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007723 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007724 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007725 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007726 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007727 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007728 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007729 // There has been issues when Sms raw table somehow stores orphan
7730 // fragments. They lead to garbled message when new fragments come
7731 // in and combined with those stale ones. In case this happens again,
7732 // user can reset all network settings which will clean up this table.
7733 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007734 // Clean up IMS settings as well here.
7735 int slotId = getSlotIndex(subId);
7736 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7737 ImsManager.getInstance(mApp, slotId).factoryReset();
7738 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007739
Kai Shif70f46f2021-03-03 13:59:46 -08007740 if (defaultPhone == null) {
7741 return;
7742 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007743 // Erase modem config if erase modem on network setting is enabled.
7744 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7745 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7746 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007747 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007748 }
Kai Shif70f46f2021-03-03 13:59:46 -08007749
7750 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007751 } finally {
7752 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007753 }
7754 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007755
SongFerngWangfd89b102021-05-27 22:44:54 +08007756 @VisibleForTesting
7757 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7758 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7759 return;
7760 }
7761 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7762 RILConstants.PREFERRED_NETWORK_MODE);
7763 SubscriptionManager.setSubscriptionProperty(subId,
7764 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7765 "user=" + defaultNetworkType);
7766 phone.loadAllowedNetworksFromSubscriptionDatabase();
7767 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7768 defaultNetworkType, null);
7769 }
7770
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007771 private void cleanUpSmsRawTable(Context context) {
7772 ContentResolver resolver = context.getContentResolver();
7773 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7774 resolver.delete(uri, null, null);
7775 }
7776
Narayan Kamath1c496c22015-04-16 14:40:19 +01007777 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007778 public String getSimLocaleForSubscriber(int subId) {
7779 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7780 final Phone phone = getPhone(subId);
7781 if (phone == null) {
7782 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007783 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007784 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007785 final long identity = Binder.clearCallingIdentity();
7786 try {
chen xu5d3637b2019-01-21 23:31:38 -08007787 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007788 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007789 if (info == null) {
7790 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7791 return null;
7792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007793 // Try and fetch the locale from the carrier properties or from the SIM language
7794 // preferences (EF-PL and EF-LI)...
7795 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007796 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007797 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7798 if (localeFromDefaultSim != null) {
7799 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7800 if (DBG) log("Using locale from subId: " + subId + " locale: "
7801 + localeFromDefaultSim);
7802 return localeFromDefaultSim.toLanguageTag();
7803 } else {
7804 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007805 }
7806 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808 // The SIM language preferences only store a language (e.g. fr = French), not an
7809 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7810 // the SIM and carrier preferences does not include a country we add the country
7811 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007812 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007814 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815 return mccLocale.toLanguageTag();
7816 }
7817
7818 if (DBG) log("No locale found - returning null");
7819 return null;
7820 } finally {
7821 Binder.restoreCallingIdentity(identity);
7822 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007823 }
7824
7825 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007826 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007827 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007828 }
7829
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007830 /**
7831 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7832 */
7833 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007834 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007835 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007836 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007837
Chenjie Yu1ba97252018-01-11 18:16:20 -08007838 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007839 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007840
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007841 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007842 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7843 * representing the state of the modem.
7844 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007845 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7846 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007847 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007848 */
7849 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007850 public void requestModemActivityInfo(ResultReceiver result) {
7851 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007852 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853
7854 final long identity = Binder.clearCallingIdentity();
7855 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007856 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857 } finally {
7858 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007859 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007860 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007861
Siddharth Rayb8114062018-06-17 15:02:38 -07007862 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7863 // less than total activity duration.
7864 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7865 if (info == null) {
7866 return false;
7867 }
7868 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007869 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7870 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7871
Siddharth Rayb8114062018-06-17 15:02:38 -07007872 return (info.isValid()
7873 && (info.getSleepTimeMillis() <= activityDurationMs)
7874 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007875 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007876 && (totalTxTimeMs <= activityDurationMs));
7877 }
7878
Jack Yu85bd38a2015-11-09 11:34:32 -08007879 /**
7880 * {@hide}
7881 * Returns the service state information on specified subscription.
7882 */
7883 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007884 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7885 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007887 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007888 return null;
7889 }
7890
Hall Liuf19c44f2018-11-27 14:38:17 -08007891 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7892 LocationAccessPolicy.checkLocationPermission(mApp,
7893 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7894 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007895 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007896 .setCallingPid(Binder.getCallingPid())
7897 .setCallingUid(Binder.getCallingUid())
7898 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007899 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007900 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007901 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7902 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007903 .build());
7904
7905 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7906 LocationAccessPolicy.checkLocationPermission(mApp,
7907 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7908 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007909 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007910 .setCallingPid(Binder.getCallingPid())
7911 .setCallingUid(Binder.getCallingUid())
7912 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007913 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007914 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007915 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7916 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007917 .build());
7918 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7919 boolean hasFinePermission =
7920 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7921 boolean hasCoarsePermission =
7922 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7923
Jack Yu479f40e2020-10-27 21:29:25 -07007924 final Phone phone = getPhone(subId);
7925 if (phone == null) {
7926 return null;
7927 }
7928
Jordan Liu0f2bc442020-11-18 16:47:37 -08007929 final long identity = Binder.clearCallingIdentity();
7930
Jack Yu479f40e2020-10-27 21:29:25 -07007931 boolean isCallingPackageDataService = phone.getDataServicePackages()
7932 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007933 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007934 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7935 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7936 Rlog.d(LOG_TAG,
7937 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7938 return null;
7939 }
7940
Hall Liuf19c44f2018-11-27 14:38:17 -08007941 ServiceState ss = phone.getServiceState();
7942
7943 // Scrub out the location info in ServiceState depending on what level of access
7944 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007945 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007946 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7947 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948 } finally {
7949 Binder.restoreCallingIdentity(identity);
7950 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007951 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007952
7953 /**
7954 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7955 *
7956 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7957 * voicemail ringtone.
7958 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7959 * PhoneAccount.
7960 */
7961 @Override
7962 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963 final long identity = Binder.clearCallingIdentity();
7964 try {
7965 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7966 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007967 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007970 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7971 } finally {
7972 Binder.restoreCallingIdentity(identity);
7973 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007974 }
7975
7976 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007977 * Sets the per-account voicemail ringtone.
7978 *
7979 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7980 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7981 *
7982 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7983 * voicemail ringtone.
7984 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7985 * PhoneAccount.
7986 */
7987 @Override
7988 public void setVoicemailRingtoneUri(String callingPackage,
7989 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007990 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007992 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7993 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7995 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7996 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998
7999 final long identity = Binder.clearCallingIdentity();
8000 try {
8001 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8002 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008003 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008004 }
8005 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8006 } finally {
8007 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008008 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008009 }
8010
8011 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008012 * Returns whether vibration is set for voicemail notification in Phone settings.
8013 *
8014 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8015 * voicemail vibration setting.
8016 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8017 */
8018 @Override
8019 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020 final long identity = Binder.clearCallingIdentity();
8021 try {
8022 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8023 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008024 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008025 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008027 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8028 } finally {
8029 Binder.restoreCallingIdentity(identity);
8030 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008031 }
8032
Youhan Wange64578a2016-05-02 15:32:42 -07008033 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008034 * Sets the per-account voicemail vibration.
8035 *
8036 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8037 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8038 *
8039 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8040 * voicemail vibration setting.
8041 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8042 * specific PhoneAccount.
8043 */
8044 @Override
8045 public void setVoicemailVibrationEnabled(String callingPackage,
8046 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008047 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008048 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008049 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8050 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8052 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8053 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008054 }
8055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056 final long identity = Binder.clearCallingIdentity();
8057 try {
8058 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8059 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008060 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008061 }
8062 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8063 } finally {
8064 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008065 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008066 }
8067
8068 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008069 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8070 *
8071 * @throws SecurityException if the caller does not have the required permission
8072 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008073 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008074 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008075 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008076 }
8077
8078 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008079 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8080 * permission.
8081 *
8082 * @throws SecurityException if the caller does not have the required permission
8083 */
8084 private void enforceSendSmsPermission() {
8085 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8086 }
8087
8088 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008089 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008090 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008091 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008092 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008093 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008094 final long identity = Binder.clearCallingIdentity();
8095 try {
8096 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008097 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098 if (componentName == null) {
8099 throw new SecurityException(
8100 "Caller not current active visual voicemail package[null]");
8101 }
8102 String vvmPackage = componentName.getPackageName();
8103 if (!callingPackage.equals(vvmPackage)) {
8104 throw new SecurityException("Caller not current active visual voicemail package["
8105 + vvmPackage + "]");
8106 }
8107 } finally {
8108 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008109 }
8110 }
8111
8112 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008113 * Return the application ID for the app type.
8114 *
8115 * @param subId the subscription ID that this request applies to.
8116 * @param appType the uicc app type.
8117 * @return Application ID for specificied app type, or null if no uicc.
8118 */
8119 @Override
8120 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008121 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008122 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008123
8124 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008125 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126 if (phone == null) {
8127 return null;
8128 }
8129 String aid = null;
8130 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008131 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132 .getApplicationByType(appType).getAid();
8133 } catch (Exception e) {
8134 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8135 }
8136 return aid;
8137 } finally {
8138 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008139 }
Youhan Wange64578a2016-05-02 15:32:42 -07008140 }
8141
Youhan Wang4001d252016-05-11 10:29:41 -07008142 /**
8143 * Return the Electronic Serial Number.
8144 *
8145 * @param subId the subscription ID that this request applies to.
8146 * @return ESN or null if error.
8147 */
8148 @Override
8149 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008150 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008151 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152
8153 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008154 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155 if (phone == null) {
8156 return null;
8157 }
8158 String esn = null;
8159 try {
8160 esn = phone.getEsn();
8161 } catch (Exception e) {
8162 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8163 }
8164 return esn;
8165 } finally {
8166 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008167 }
Youhan Wang4001d252016-05-11 10:29:41 -07008168 }
8169
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008170 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008171 * Return the Preferred Roaming List Version.
8172 *
8173 * @param subId the subscription ID that this request applies to.
8174 * @return PRLVersion or null if error.
8175 */
8176 @Override
8177 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008178 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008179 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180
8181 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008182 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008183 if (phone == null) {
8184 return null;
8185 }
8186 String cdmaPrlVersion = null;
8187 try {
8188 cdmaPrlVersion = phone.getCdmaPrlVersion();
8189 } catch (Exception e) {
8190 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8191 }
8192 return cdmaPrlVersion;
8193 } finally {
8194 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008195 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008196 }
8197
8198 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008199 * Get snapshot of Telephony histograms
8200 * @return List of Telephony histograms
8201 * @hide
8202 */
8203 @Override
8204 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8206 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008207
8208 final long identity = Binder.clearCallingIdentity();
8209 try {
8210 return RIL.getTelephonyRILTimingHistograms();
8211 } finally {
8212 Binder.restoreCallingIdentity(identity);
8213 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008214 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008215
8216 /**
8217 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008218 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8219 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008220 * Require system privileges. In the future we may add this to carrier APIs.
8221 *
Michele Berionne482f8202018-11-27 18:57:59 -08008222 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008223 */
8224 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008225 @TelephonyManager.SetCarrierRestrictionResult
8226 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008227 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008228 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008229
Michele Berionne482f8202018-11-27 18:57:59 -08008230 if (carrierRestrictionRules == null) {
8231 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008232 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008234 final long identity = Binder.clearCallingIdentity();
8235 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008236 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008237 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 } finally {
8239 Binder.restoreCallingIdentity(identity);
8240 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008241 }
8242
8243 /**
8244 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008245 * Get the allowed carrier list and the excluded carrier list, including the priority between
8246 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008247 * Require system privileges. In the future we may add this to carrier APIs.
8248 *
Michele Berionne482f8202018-11-27 18:57:59 -08008249 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008250 */
8251 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008252 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008253 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008254 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255
8256 final long identity = Binder.clearCallingIdentity();
8257 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008258 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8259 if (response instanceof CarrierRestrictionRules) {
8260 return (CarrierRestrictionRules) response;
8261 }
8262 // Response is an Exception of some kind,
8263 // which is signalled to the user as a NULL retval
8264 return null;
8265 } catch (Exception e) {
8266 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8267 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008268 } finally {
8269 Binder.restoreCallingIdentity(identity);
8270 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008271 }
8272
fionaxu59545b42016-05-25 15:53:37 -07008273 /**
fionaxu59545b42016-05-25 15:53:37 -07008274 * Action set from carrier signalling broadcast receivers to enable/disable radio
8275 * @param subId the subscription ID that this action applies to.
8276 * @param enabled control enable or disable radio.
8277 * {@hide}
8278 */
8279 @Override
8280 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8281 enforceModifyPermission();
8282 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283
8284 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008285 if (phone == null) {
8286 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8287 return;
8288 }
8289 try {
8290 phone.carrierActionSetRadioEnabled(enabled);
8291 } catch (Exception e) {
8292 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 } finally {
8294 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008295 }
8296 }
8297
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008298 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008299 * Enable or disable Voice over NR (VoNR)
8300 * @param subId the subscription ID that this action applies to.
8301 * @param enabled enable or disable VoNR.
8302 * @return operation result.
8303 */
8304 @Override
8305 public int setVoNrEnabled(int subId, boolean enabled) {
8306 enforceModifyPermission();
8307 final Phone phone = getPhone(subId);
8308
8309 final long identity = Binder.clearCallingIdentity();
8310 if (phone == null) {
8311 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8312 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8313 }
8314
8315 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8316 try {
8317 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8318 workSource);
8319 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008320
8321 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8322 if (DBG) {
8323 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8324 }
8325 SubscriptionManager.setSubscriptionProperty(
8326 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8327 (enabled ? "1" : "0"));
8328 }
8329
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008330 return result;
8331 } finally {
8332 Binder.restoreCallingIdentity(identity);
8333 }
8334 }
8335
8336 /**
8337 * Is voice over NR enabled
8338 * @return true if VoNR is enabled else false
8339 */
8340 @Override
8341 public boolean isVoNrEnabled(int subId) {
8342 enforceReadPrivilegedPermission("isVoNrEnabled");
8343 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8344 final long identity = Binder.clearCallingIdentity();
8345 try {
8346 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8347 null, subId, workSource);
8348 if (DBG) log("isVoNrEnabled: " + isEnabled);
8349 return isEnabled;
8350 } finally {
8351 Binder.restoreCallingIdentity(identity);
8352 }
8353 }
8354
8355 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008356 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8357 * network status based on which carrier apps could apply actions accordingly,
8358 * enable/disable default url handler for example.
8359 *
8360 * @param subId the subscription ID that this action applies to.
8361 * @param report control start/stop reporting the default network status.
8362 * {@hide}
8363 */
8364 @Override
8365 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8366 enforceModifyPermission();
8367 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368
8369 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008370 if (phone == null) {
8371 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8372 return;
8373 }
8374 try {
8375 phone.carrierActionReportDefaultNetworkStatus(report);
8376 } catch (Exception e) {
8377 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008378 } finally {
8379 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008380 }
8381 }
8382
8383 /**
fionaxud9622282017-07-17 17:51:30 -07008384 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8385 * @param subId the subscription ID that this action applies to.
8386 * {@hide}
8387 */
8388 @Override
8389 public void carrierActionResetAll(int subId) {
8390 enforceModifyPermission();
8391 final Phone phone = getPhone(subId);
8392 if (phone == null) {
8393 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8394 return;
8395 }
8396 try {
8397 phone.carrierActionResetAll();
8398 } catch (Exception e) {
8399 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8400 }
8401 }
8402
8403 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008404 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8405 * bug report is being generated.
8406 */
8407 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008408 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008409 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8410 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008411 writer.println("Permission Denial: can't dump Phone from pid="
8412 + Binder.getCallingPid()
8413 + ", uid=" + Binder.getCallingUid()
8414 + "without permission "
8415 + android.Manifest.permission.DUMP);
8416 return;
8417 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008418 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008419 }
Jack Yueb89b242016-06-22 13:27:47 -07008420
Brad Ebingerdac2f002018-04-03 15:17:52 -07008421 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008422 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8423 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8424 @NonNull String[] args) {
8425 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8426 this, in.getFileDescriptor(), out.getFileDescriptor(),
8427 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008428 }
8429
Jack Yueb89b242016-06-22 13:27:47 -07008430 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008431 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008432 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008433 * @param reason the reason the data enable change is taking place
8434 * @param enabled True if enabling the data, otherwise disabling.
8435 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008436 */
8437 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008438 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008439 boolean enabled) {
8440 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8441 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8442 try {
8443 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008444 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008445 } catch (SecurityException se) {
8446 enforceModifyPermission();
8447 }
8448 } else {
8449 enforceModifyPermission();
8450 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008451
8452 final long identity = Binder.clearCallingIdentity();
8453 try {
8454 Phone phone = getPhone(subId);
8455 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008456 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8457 phone.carrierActionSetMeteredApnsEnabled(enabled);
8458 } else {
8459 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461 }
8462 } finally {
8463 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008464 }
8465 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008466
8467 /**
8468 * Get Client request stats
8469 * @return List of Client Request Stats
8470 * @hide
8471 */
8472 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008473 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8474 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008476 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008477 return null;
8478 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008479 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008481 final long identity = Binder.clearCallingIdentity();
8482 try {
8483 if (phone != null) {
8484 return phone.getClientRequestStats();
8485 }
8486
8487 return null;
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
8490 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008491 }
8492
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008493 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008494 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008495 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008496 }
Jack Yueb4124c2017-02-16 15:32:43 -08008497
8498 /**
Grace Chen70990072017-03-24 17:21:30 -07008499 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008500 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008501 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008502 * @param state State of SIM (power down, power up, pass through)
8503 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8504 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8505 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008506 *
8507 **/
8508 @Override
Grace Chen70990072017-03-24 17:21:30 -07008509 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008510 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008511 Phone phone = PhoneFactory.getPhone(slotIndex);
8512
vagdeviaf9a5b92018-08-15 16:01:53 -07008513 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8514
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008515 final long identity = Binder.clearCallingIdentity();
8516 try {
8517 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008518 phone.setSimPowerState(state, null, workSource);
8519 }
8520 } finally {
8521 Binder.restoreCallingIdentity(identity);
8522 }
8523 }
8524
8525 /**
8526 * Set SIM card power state.
8527 *
8528 * @param slotIndex SIM slot id.
8529 * @param state State of SIM (power down, power up, pass through)
8530 * @param callback callback to trigger after success or failure
8531 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8532 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8533 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8534 *
8535 **/
8536 @Override
8537 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8538 IIntegerConsumer callback) {
8539 enforceModifyPermission();
8540 Phone phone = PhoneFactory.getPhone(slotIndex);
8541
8542 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8543
8544 final long identity = Binder.clearCallingIdentity();
8545 try {
8546 if (phone != null) {
8547 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8548 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008549 }
8550 } finally {
8551 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008552 }
8553 }
Shuo Qiandd210312017-04-12 22:11:33 +00008554
Tyler Gunn65d45c22017-06-05 11:22:26 -07008555 private boolean isUssdApiAllowed(int subId) {
8556 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008557 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008558 if (configManager == null) {
8559 return false;
8560 }
8561 PersistableBundle pb = configManager.getConfigForSubId(subId);
8562 if (pb == null) {
8563 return false;
8564 }
8565 return pb.getBoolean(
8566 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8567 }
8568
Shuo Qiandd210312017-04-12 22:11:33 +00008569 /**
8570 * Check if phone is in emergency callback mode
8571 * @return true if phone is in emergency callback mode
8572 * @param subId sub id
8573 */
goneil9c5f4872017-12-05 14:07:56 -08008574 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008575 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008576 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008577 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008578
8579 final long identity = Binder.clearCallingIdentity();
8580 try {
8581 if (phone != null) {
8582 return phone.isInEcm();
8583 } else {
8584 return false;
8585 }
8586 } finally {
8587 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008588 }
8589 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008590
8591 /**
8592 * Get the current signal strength information for the given subscription.
8593 * Because this information is not updated when the device is in a low power state
8594 * it should not be relied-upon to be current.
8595 * @param subId Subscription index
8596 * @return the most recent cached signal strength info from the modem
8597 */
8598 @Override
8599 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008600 final long identity = Binder.clearCallingIdentity();
8601 try {
8602 Phone p = getPhone(subId);
8603 if (p == null) {
8604 return null;
8605 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008607 return p.getSignalStrength();
8608 } finally {
8609 Binder.restoreCallingIdentity(identity);
8610 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008611 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008612
Pengquan Meng77b7f132018-08-22 14:49:57 -07008613 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008614 * Get the current modem radio state for the given slot.
8615 * @param slotIndex slot index.
8616 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008617 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008618 * @return the current radio power state from the modem
8619 */
8620 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008621 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008622 Phone phone = PhoneFactory.getPhone(slotIndex);
8623 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8625 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008626 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8627 }
8628
8629 final long identity = Binder.clearCallingIdentity();
8630 try {
8631 return phone.getRadioPowerState();
8632 } finally {
8633 Binder.restoreCallingIdentity(identity);
8634 }
8635 }
8636 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8637 }
8638
8639 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008640 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8641 *
8642 * <p>Requires one of the following permissions:
8643 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8644 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8645 * privileges.
8646 *
8647 * @param subId subscription id
8648 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8649 * {@code false}.
8650 */
8651 @Override
8652 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008653 try {
8654 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8655 null);
8656 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008657 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008658 mApp, subId, "isDataRoamingEnabled");
8659 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008660
Pengquan Menga1bb6272018-09-06 09:59:22 -07008661 boolean isEnabled = false;
8662 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008663 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008664 Phone phone = getPhone(subId);
8665 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008666 } finally {
8667 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008668 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008669 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008670 }
8671
8672
8673 /**
8674 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8675 *
8676 * <p> Requires permission:
8677 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8678 * privileges.
8679 *
8680 * @param subId subscription id
8681 * @param isEnabled {@code true} means enable, {@code false} means disable.
8682 */
8683 @Override
8684 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8686 mApp, subId, "setDataRoamingEnabled");
8687
Pengquan Menga1bb6272018-09-06 09:59:22 -07008688 final long identity = Binder.clearCallingIdentity();
8689 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008690 Phone phone = getPhone(subId);
8691 if (phone != null) {
8692 phone.setDataRoamingEnabled(isEnabled);
8693 }
8694 } finally {
8695 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008696 }
8697 }
8698
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008699 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008700 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008701 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008702 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008703 mApp, subId, "isManualNetworkSelectionAllowed");
8704
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008705 boolean isAllowed = true;
8706 final long identity = Binder.clearCallingIdentity();
8707 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008708 Phone phone = getPhone(subId);
8709 if (phone != null) {
8710 isAllowed = phone.isCspPlmnEnabled();
8711 }
8712 } finally {
8713 Binder.restoreCallingIdentity(identity);
8714 }
8715 return isAllowed;
8716 }
8717
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008718 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8719 UiccProfile profile = port.getUiccProfile();
8720 if (profile == null ||
8721 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8722 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8723 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008724 }
8725 return true;
8726 }
8727
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008728 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008729 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008730 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008731 mApp.getSystemService(AppOpsManager.class)
8732 .checkPackage(Binder.getCallingUid(), callingPackage);
8733
Jordan Liu1e142fc2019-04-22 15:10:43 -07008734 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008735 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008736 try {
8737 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008738 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008739 } catch (SecurityException e) {
8740 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8741 // has carrier privileges on an active UICC
8742 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8743 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008744 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008745 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008746 }
sandeepjsb6c87872021-09-27 15:34:44 +00008747 // checking compatibility, if calling app's target SDK is T and beyond.
8748 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8749 Binder.getCallingUid())) {
8750 isIccIdAccessRestricted = true;
8751 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008752 final long identity = Binder.clearCallingIdentity();
8753 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008754 UiccController uiccController = UiccController.getInstance();
8755 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008756 if (hasReadPermission) {
8757 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008758 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008759
8760 // Remove private info if the caller doesn't have access
8761 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8762 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008763 //setting the value after compatibility check
8764 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008765 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8766 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008767 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008768 if (card == null) {
8769 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008770 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008771 continue;
8772 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008773 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8774 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008775 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008776 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008777 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008778 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8779 for (UiccPortInfo portInfo : portInfos) {
8780 UiccPort port = uiccController.getUiccPortForSlot(
8781 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8782 if (port == null) {
8783 // assume no access if port is null
8784 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8785 continue;
8786 }
8787 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8788 uiccPortInfos.add(portInfo);
8789 } else {
8790 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8791 }
8792 }
8793 filteredInfos.add(new UiccCardInfo(
8794 cardInfo.isEuicc(),
8795 cardInfo.getCardId(),
8796 null,
8797 cardInfo.getPhysicalSlotIndex(),
8798 cardInfo.isRemovable(),
8799 cardInfo.isMultipleEnabledProfilesSupported(),
8800 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008801 }
8802 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008803 } finally {
8804 Binder.restoreCallingIdentity(identity);
8805 }
8806 }
8807
sandeepjsb6c87872021-09-27 15:34:44 +00008808 /**
8809 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8810 * generally private and require carrier privileges to view.
8811 *
8812 * @hide
8813 */
8814 @NonNull
8815 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8816 List<UiccPortInfo> portinfo = new ArrayList<>();
8817 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8818 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8819 }
8820 return new UiccCardInfo(
8821 cardInfo.isEuicc(),
8822 cardInfo.getCardId(),
8823 null,
8824 cardInfo.getPhysicalSlotIndex(),
8825 cardInfo.isRemovable(),
8826 cardInfo.isMultipleEnabledProfilesSupported(),
8827 portinfo
8828 );
8829 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008830
sandeepjsb6c87872021-09-27 15:34:44 +00008831 /**
8832 * @hide
8833 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8834 * These values are generally private and require carrier privileges to view.
8835 */
8836 @NonNull
8837 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8838 return new UiccPortInfo(
8839 UiccPortInfo.ICCID_REDACTED,
8840 portInfo.getPortIndex(),
8841 portInfo.getLogicalSlotIndex(),
8842 portInfo.isActive()
8843 );
8844 }
8845 @Override
8846 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008847 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008848 mApp.getSystemService(AppOpsManager.class)
8849 .checkPackage(Binder.getCallingUid(), callingPackage);
8850
8851 boolean hasReadPermission = false;
8852 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008853
8854 try {
8855 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8856 hasReadPermission = true;
8857 } catch (SecurityException e) {
8858 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8859 // has carrier privileges on an active UICC
8860 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8861 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8862 hasReadPermission = true;
8863 }
8864 }
8865
8866 // checking compatibility, if calling app's target SDK is T and beyond.
8867 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8868 Binder.getCallingUid())) {
8869 isLogicalSlotAccessRestricted = true;
8870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008871 final long identity = Binder.clearCallingIdentity();
8872 try {
8873 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8874 if (slots == null) {
8875 Rlog.i(LOG_TAG, "slots is null.");
8876 return null;
8877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008878 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8879 for (int i = 0; i < slots.length; i++) {
8880 UiccSlot slot = slots[i];
8881 if (slot == null) {
8882 continue;
8883 }
8884
Jordan Liu7be7e652019-05-06 18:55:02 +00008885 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008886 UiccCard card = slot.getUiccCard();
8887 if (card != null) {
8888 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008889 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008890 cardId = slot.getEid();
8891 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008892 // If cardId is null, use iccId of default port as cardId. Check if has
8893 // read permission otherwise set to null.(card is null which means no
8894 // carrier permission)
8895 cardId = hasReadPermission ? slot.getIccId(
8896 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008897 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008898 }
8899
Jordan Liu857451f2019-05-09 16:35:35 -07008900 if (cardId != null) {
8901 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8902 // if cardId is an EID, it's all digits so this is fine
8903 cardId = IccUtils.stripTrailingFs(cardId);
8904 }
8905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008906 int cardState = 0;
8907 switch (slot.getCardState()) {
8908 case CARDSTATE_ABSENT:
8909 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8910 break;
8911 case CARDSTATE_PRESENT:
8912 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8913 break;
8914 case CARDSTATE_ERROR:
8915 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8916 break;
8917 case CARDSTATE_RESTRICTED:
8918 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8919 break;
8920 default:
8921 break;
8922
8923 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008924 List<UiccPortInfo> portInfos = new ArrayList<>();
8925 int[] portIndexes = slot.getPortList();
8926 for (int portIdx : portIndexes) {
8927 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8928 callingPackage, hasReadPermission));
8929 if (slot.isPortActive(portIdx)) {
8930 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8931 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8932 port.getPhoneId(), true));
8933 } else {
8934 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8935 }
8936 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008937 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008938 slot.isEuicc(),
8939 cardId,
8940 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008941 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008942 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008943 //setting the value after compatibility check
8944 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008945 }
8946 return infos;
8947 } finally {
8948 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008949 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008950 }
8951
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008952 /* Returns null if doesn't have read permission or carrier privilege access. */
8953 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8954 boolean hasReadPermission) {
8955 String iccId = slot.getIccId(portIndex);
8956 if (hasReadPermission) { // if has read permission
8957 return iccId;
8958 } else {
8959 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8960 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8961 // if no read permission, checking carrier privilege access
8962 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8963 return iccId;
8964 }
8965 }
8966 }
8967 // No read permission or carrier privilege access.
8968 return UiccPortInfo.ICCID_REDACTED;
8969 }
8970
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008971 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008972 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008973 public boolean switchSlots(int[] physicalSlots) {
8974 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008975
8976 final long identity = Binder.clearCallingIdentity();
8977 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008978 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8979 for (int i = 0; i < physicalSlots.length; i++) {
8980 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8981 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8982 physicalSlots[i], i));
8983 }
8984 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008985 } finally {
8986 Binder.restoreCallingIdentity(identity);
8987 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008988 }
Jack Yu4c988042018-02-27 15:30:01 -08008989
8990 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008991 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8992 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8993 enforceModifyPermission();
8994
8995 final long identity = Binder.clearCallingIdentity();
8996 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008997 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00008998 } finally {
8999 Binder.restoreCallingIdentity(identity);
9000 }
9001 }
9002
9003 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009004 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009005 final long identity = Binder.clearCallingIdentity();
9006 try {
9007 return UiccController.getInstance().getCardIdForDefaultEuicc();
9008 } finally {
9009 Binder.restoreCallingIdentity(identity);
9010 }
9011 }
9012
Pengquan Meng85728fb2018-03-12 16:31:21 -07009013 /**
goneil47ffb6e2018-04-06 15:40:58 -07009014 * A test API to reload the UICC profile.
9015 *
9016 * <p>Requires that the calling app has permission
9017 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9018 * @hide
9019 */
9020 @Override
9021 public void refreshUiccProfile(int subId) {
9022 enforceModifyPermission();
9023
9024 final long identity = Binder.clearCallingIdentity();
9025 try {
9026 Phone phone = getPhone(subId);
9027 if (phone == null) {
9028 return;
9029 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009030 UiccPort uiccPort = phone.getUiccPort();
9031 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009032 return;
9033 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009034 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009035 if (uiccProfile == null) {
9036 return;
9037 }
9038 uiccProfile.refresh();
9039 } finally {
9040 Binder.restoreCallingIdentity(identity);
9041 }
9042 }
9043
9044 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009045 * Returns false if the mobile data is disabled by default, otherwise return true.
9046 */
9047 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009048 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009049 }
9050
9051 /**
9052 * Returns true if the data roaming is enabled by default, i.e the system property
9053 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9054 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9055 */
9056 private boolean getDefaultDataRoamingEnabled(int subId) {
9057 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009058 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009059 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009060 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9061 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9062 return isDataRoamingEnabled;
9063 }
9064
9065 /**
9066 * Returns the default network type for the given {@code subId}, if the default network type is
9067 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9068 */
9069 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009070 List<Integer> list = TelephonyProperties.default_network();
9071 int phoneId = mSubscriptionController.getPhoneId(subId);
9072 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9073 return list.get(phoneId);
9074 }
9075 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009076 }
fionaxua13278b2018-03-21 00:08:13 -07009077
9078 @Override
9079 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009080 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009081 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009082
9083 final long identity = Binder.clearCallingIdentity();
9084 try {
9085 final Phone phone = getPhone(subId);
9086 if (phone == null) {
9087 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9088 return;
9089 }
chen xueaba88a2019-03-15 13:15:10 -07009090 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9091 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009092 if (carrierPrivilegeRules == null) {
9093 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9094 } else {
9095 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9096 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009097 } finally {
9098 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009099 }
fionaxua13278b2018-03-21 00:08:13 -07009100 }
9101
9102 @Override
9103 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009104 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009105
9106 final long identity = Binder.clearCallingIdentity();
9107 try {
9108 final Phone phone = getPhone(subId);
9109 if (phone == null) {
9110 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9111 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9112 }
9113 return phone.getCarrierIdListVersion();
9114 } finally {
9115 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009116 }
fionaxua13278b2018-03-21 00:08:13 -07009117 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009118
9119 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009120 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9121 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009123 mApp, subId, callingPackage, callingFeatureId,
9124 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009125 return -1;
9126 }
9127
9128 final long identity = Binder.clearCallingIdentity();
9129 try {
9130 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9131 } finally {
9132 Binder.restoreCallingIdentity(identity);
9133 }
9134 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009135
9136 @Override
9137 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009138 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009139 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009140 mApp, subId, "getCdmaRoamingMode");
9141
9142 final long identity = Binder.clearCallingIdentity();
9143 try {
9144 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9145 } finally {
9146 Binder.restoreCallingIdentity(identity);
9147 }
9148 }
9149
9150 @Override
9151 public boolean setCdmaRoamingMode(int subId, int mode) {
9152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9153 mApp, subId, "setCdmaRoamingMode");
9154
9155 final long identity = Binder.clearCallingIdentity();
9156 try {
9157 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9158 } finally {
9159 Binder.restoreCallingIdentity(identity);
9160 }
9161 }
9162
9163 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009164 public int getCdmaSubscriptionMode(int subId) {
9165 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009166 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009167 mApp, subId, "getCdmaSubscriptionMode");
9168
9169 final long identity = Binder.clearCallingIdentity();
9170 try {
9171 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9172 } finally {
9173 Binder.restoreCallingIdentity(identity);
9174 }
9175 }
9176
9177 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009178 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9180 mApp, subId, "setCdmaSubscriptionMode");
9181
9182 final long identity = Binder.clearCallingIdentity();
9183 try {
9184 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9185 } finally {
9186 Binder.restoreCallingIdentity(identity);
9187 }
9188 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009189
sqianc5eccab2018-10-19 18:46:41 -07009190 @Override
sqian8c685422019-02-22 15:55:18 -08009191 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009192 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009193 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009194 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9195 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009196 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9197 }
9198 final long identity = Binder.clearCallingIdentity();
9199 try {
sqian854d44b2018-12-12 16:48:18 -08009200 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9201 for (Phone phone: PhoneFactory.getPhones()) {
9202 if (phone.getEmergencyNumberTracker() != null
9203 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9204 emergencyNumberListInternal.put(
9205 phone.getSubId(),
9206 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9207 }
sqian11b7a0e2018-12-05 18:48:28 -08009208 }
sqian854d44b2018-12-12 16:48:18 -08009209 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009210 } finally {
9211 Binder.restoreCallingIdentity(identity);
9212 }
sqianc5eccab2018-10-19 18:46:41 -07009213 }
9214
9215 @Override
sqian8c685422019-02-22 15:55:18 -08009216 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009217 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009218 if (!exactMatch) {
9219 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009220 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009221 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009222 }
9223 final long identity = Binder.clearCallingIdentity();
9224 try {
sqian854d44b2018-12-12 16:48:18 -08009225 for (Phone phone: PhoneFactory.getPhones()) {
9226 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009227 && phone.getEmergencyNumberTracker()
9228 .isEmergencyNumber(number, exactMatch)) {
9229 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009230 }
sqian11b7a0e2018-12-05 18:48:28 -08009231 }
9232 return false;
9233 } finally {
9234 Binder.restoreCallingIdentity(identity);
9235 }
9236 }
9237
sqianf4ca7ed2019-01-15 18:32:07 -08009238 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009239 * Start emergency callback mode for GsmCdmaPhone for testing.
9240 */
9241 @Override
9242 public void startEmergencyCallbackMode() {
9243 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9244 "startEmergencyCallbackMode");
9245 enforceModifyPermission();
9246 final long identity = Binder.clearCallingIdentity();
9247 try {
9248 for (Phone phone : PhoneFactory.getPhones()) {
9249 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9250 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9251 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9252 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9253 gsmCdmaPhone.obtainMessage(
9254 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9255 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9256 }
9257 }
9258 } finally {
9259 Binder.restoreCallingIdentity(identity);
9260 }
9261 }
9262
9263 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009264 * Update emergency number list for test mode.
9265 */
9266 @Override
9267 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9268 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9269 "updateEmergencyNumberListTestMode");
9270
9271 final long identity = Binder.clearCallingIdentity();
9272 try {
9273 for (Phone phone: PhoneFactory.getPhones()) {
9274 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9275 if (tracker != null) {
9276 tracker.executeEmergencyNumberTestModeCommand(action, num);
9277 }
9278 }
9279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
9282 }
9283
9284 /**
9285 * Get the full emergency number list for test mode.
9286 */
9287 @Override
9288 public List<String> getEmergencyNumberListTestMode() {
9289 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9290 "getEmergencyNumberListTestMode");
9291
9292 final long identity = Binder.clearCallingIdentity();
9293 try {
9294 Set<String> emergencyNumbers = new HashSet<>();
9295 for (Phone phone: PhoneFactory.getPhones()) {
9296 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9297 if (tracker != null) {
9298 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9299 emergencyNumbers.add(num.getNumber());
9300 }
9301 }
9302 }
9303 return new ArrayList<>(emergencyNumbers);
9304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
9307 }
9308
chen xud6b45bd2018-10-30 22:27:10 -07009309 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009310 public int getEmergencyNumberDbVersion(int subId) {
9311 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9312
9313 final long identity = Binder.clearCallingIdentity();
9314 try {
9315 final Phone phone = getPhone(subId);
9316 if (phone == null) {
9317 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9318 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9319 }
9320 return phone.getEmergencyNumberDbVersion();
9321 } finally {
9322 Binder.restoreCallingIdentity(identity);
9323 }
9324 }
9325
9326 @Override
9327 public void notifyOtaEmergencyNumberDbInstalled() {
9328 enforceModifyPermission();
9329
9330 final long identity = Binder.clearCallingIdentity();
9331 try {
9332 for (Phone phone: PhoneFactory.getPhones()) {
9333 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9334 if (tracker != null) {
9335 tracker.updateOtaEmergencyNumberDatabase();
9336 }
9337 }
9338 } finally {
9339 Binder.restoreCallingIdentity(identity);
9340 }
9341 }
9342
9343 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009344 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009345 enforceActiveEmergencySessionPermission();
9346
9347 final long identity = Binder.clearCallingIdentity();
9348 try {
9349 for (Phone phone: PhoneFactory.getPhones()) {
9350 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9351 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009352 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9353 }
9354 }
9355 } finally {
9356 Binder.restoreCallingIdentity(identity);
9357 }
9358 }
9359
9360 @Override
9361 public void resetOtaEmergencyNumberDbFilePath() {
9362 enforceActiveEmergencySessionPermission();
9363
9364 final long identity = Binder.clearCallingIdentity();
9365 try {
9366 for (Phone phone: PhoneFactory.getPhones()) {
9367 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9368 if (tracker != null) {
9369 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009370 }
9371 }
9372 } finally {
9373 Binder.restoreCallingIdentity(identity);
9374 }
9375 }
9376
9377 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009378 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9379 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9380 Phone phone = getPhone(subId);
9381 if (phone == null) {
9382 return null;
9383 }
9384 final long identity = Binder.clearCallingIdentity();
9385 try {
9386 UiccProfile profile = UiccController.getInstance()
9387 .getUiccProfileForPhone(phone.getPhoneId());
9388 if (profile != null) {
9389 return profile.getCertsFromCarrierPrivilegeAccessRules();
9390 }
9391 } finally {
9392 Binder.restoreCallingIdentity(identity);
9393 }
9394 return null;
9395 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009396
9397 /**
9398 * Enable or disable a modem stack.
9399 */
9400 @Override
9401 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9402 enforceModifyPermission();
9403
9404 final long identity = Binder.clearCallingIdentity();
9405 try {
9406 Phone phone = PhoneFactory.getPhone(slotIndex);
9407 if (phone == null) {
9408 return false;
9409 } else {
9410 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9411 }
9412 } finally {
9413 Binder.restoreCallingIdentity(identity);
9414 }
9415 }
Michelecea4cf22018-12-21 15:00:11 -08009416
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009417 /**
9418 * Whether a modem stack is enabled or not.
9419 */
9420 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009421 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9422 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009423 Phone phone = PhoneFactory.getPhone(slotIndex);
9424 if (phone == null) return false;
9425
9426 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009427 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9428 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009429 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9430 }
9431
9432 final long identity = Binder.clearCallingIdentity();
9433 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009434 try {
9435 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9436 } catch (NoSuchElementException ex) {
9437 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9438 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009439 } finally {
9440 Binder.restoreCallingIdentity(identity);
9441 }
9442 }
9443
Michelecea4cf22018-12-21 15:00:11 -08009444 @Override
Michele0ea7d782019-03-19 14:58:42 -07009445 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009446 enforceModifyPermission();
9447
9448 final long identity = Binder.clearCallingIdentity();
9449 try {
9450 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009451 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009452 .commit();
9453 } finally {
9454 Binder.restoreCallingIdentity(identity);
9455 }
9456 }
9457
9458 @Override
Michele0ea7d782019-03-19 14:58:42 -07009459 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009460 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009462 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9463 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009464 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009465 }
Michelecea4cf22018-12-21 15:00:11 -08009466
9467 final long identity = Binder.clearCallingIdentity();
9468 try {
Michele0ea7d782019-03-19 14:58:42 -07009469 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009470 } finally {
9471 Binder.restoreCallingIdentity(identity);
9472 }
9473 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009474
Michele0ea7d782019-03-19 14:58:42 -07009475 @TelephonyManager.IsMultiSimSupportedResult
9476 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009477 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9478 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9479 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009480 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9481 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009482 }
9483 // Check if the hardware supports multisim functionality. If usage of multisim is not
9484 // supported by the modem, indicate that it is restricted.
9485 PhoneCapability staticCapability =
9486 mPhoneConfigurationManager.getStaticPhoneCapability();
9487 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009488 loge("isMultiSimSupportedInternal: no static configuration available");
9489 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009490 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009491 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009492 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9493 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009494 }
9495 // Check if support of multiple SIMs is restricted by carrier
9496 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009497 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009498 }
9499
Michele0ea7d782019-03-19 14:58:42 -07009500 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009501 }
9502
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009503 /**
9504 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009505 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9506 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9507 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009508 * @param numOfSims number of active sims we want to switch to
9509 */
9510 @Override
9511 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009512 if (numOfSims == 1) {
9513 enforceModifyPermission();
9514 } else {
9515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9516 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9517 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009518 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009519
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009520 try {
Michele30b57b22019-03-01 12:01:14 -08009521 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009522 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009523 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9524 return;
9525 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009526 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9527 } finally {
9528 Binder.restoreCallingIdentity(identity);
9529 }
9530 }
9531
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009532 @Override
9533 public boolean isApplicationOnUicc(int subId, int appType) {
9534 enforceReadPrivilegedPermission("isApplicationOnUicc");
9535 Phone phone = getPhone(subId);
9536 if (phone == null) {
9537 return false;
9538 }
9539 final long identity = Binder.clearCallingIdentity();
9540 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009541 UiccPort uiccPort = phone.getUiccPort();
9542 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009543 return false;
9544 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009545 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009546 if (uiccProfile == null) {
9547 return false;
9548 }
9549 if (TelephonyManager.APPTYPE_SIM <= appType
9550 && appType <= TelephonyManager.APPTYPE_ISIM) {
9551 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9552 }
9553 return false;
9554 } finally {
9555 Binder.restoreCallingIdentity(identity);
9556 }
9557 }
9558
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009559 /**
chen xub4baa772019-04-03 10:23:41 -07009560 * Get whether making changes to modem configurations will trigger reboot.
9561 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009562 */
9563 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009564 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9565 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009567 mApp, subId, callingPackage, callingFeatureId,
9568 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009569 return false;
9570 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009571 final long identity = Binder.clearCallingIdentity();
9572 try {
9573 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9574 } finally {
9575 Binder.restoreCallingIdentity(identity);
9576 }
9577 }
9578
Nathan Harold29f5f052019-02-15 13:41:57 -08009579 private void updateModemStateMetrics() {
9580 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9581 // TODO: check the state for each modem if the api is ready.
9582 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9583 }
9584
Pengquan Meng3889a572019-01-23 11:16:29 -08009585 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009586 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009587 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009588 // Verify that the callingPackage belongs to the calling UID
9589 mApp.getSystemService(AppOpsManager.class)
9590 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009591 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009592 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009593 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009594 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9595 if (slotInfos != null) {
9596 for (int i = 0; i < slotInfos.length; i++) {
9597 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9598 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9599 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9600 portInfo.getLogicalSlotIndex()));
9601 }
9602 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009603 }
9604 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009605 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009606 } finally {
9607 Binder.restoreCallingIdentity(identity);
9608 }
9609 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009610
9611 /**
9612 * Get the IRadio HAL Version
9613 */
9614 @Override
9615 public int getRadioHalVersion() {
9616 Phone phone = getDefaultPhone();
9617 if (phone == null) return -1;
9618 HalVersion hv = phone.getHalVersion();
9619 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9620 return hv.major * 100 + hv.minor;
9621 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009622
9623 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009624 * Get the current calling package name.
9625 * @return the current calling package name
9626 */
9627 @Override
9628 public String getCurrentPackageName() {
9629 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9630 }
9631
9632 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009633 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9634 * corresponding network requests on a subId.
9635 *
9636 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009637 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009638 * 2) APN is un-metered for this subscription, or
9639 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009640 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009641 *
9642 * @return whether data is allowed for a apn type.
9643 *
9644 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009645 */
9646 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009647 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009648 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9649 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009650
9651 // Now that all security checks passes, perform the operation as ourselves.
9652 final long identity = Binder.clearCallingIdentity();
9653 try {
9654 Phone phone = getPhone(subId);
9655 if (phone == null) return false;
9656
Jack Yu41407ee2019-05-13 16:54:09 -07009657 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009658 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9659 } finally {
9660 Binder.restoreCallingIdentity(identity);
9661 }
9662 }
9663
9664 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009665 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009666 enforceReadPrivilegedPermission("isApnMetered");
9667
9668 // Now that all security checks passes, perform the operation as ourselves.
9669 final long identity = Binder.clearCallingIdentity();
9670 try {
9671 Phone phone = getPhone(subId);
9672 if (phone == null) return true; // By default return true.
9673
Jack Yu41407ee2019-05-13 16:54:09 -07009674 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009679
9680 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009681 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9682 int subscriptionId, IBooleanConsumer resultCallback) {
9683 enforceModifyPermission();
9684 long token = Binder.clearCallingIdentity();
9685 try {
9686 Phone phone = getPhone(subscriptionId);
9687 if (phone == null) {
9688 try {
9689 if (resultCallback != null) {
9690 resultCallback.accept(false);
9691 }
9692 } catch (RemoteException e) {
9693 // ignore
9694 }
9695 return;
9696 }
9697 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9698 Pair.create(specifiers, (x) -> {
9699 try {
9700 if (resultCallback != null) {
9701 resultCallback.accept(x);
9702 }
9703 } catch (RemoteException e) {
9704 // ignore
9705 }
9706 });
9707 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9708 } finally {
9709 Binder.restoreCallingIdentity(token);
9710 }
9711 }
9712
9713 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009714 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9715 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009716 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009717 mApp, subId, "getSystemSelectionChannels");
9718 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9719 final long identity = Binder.clearCallingIdentity();
9720 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009721 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9722 if (result instanceof IllegalStateException) {
9723 throw (IllegalStateException) result;
9724 }
9725 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009726 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9727 return specifiers;
9728 } finally {
9729 Binder.restoreCallingIdentity(identity);
9730 }
9731 }
9732
9733 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009734 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009735 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009736 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9737 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9738 if (iccRecords == null) {
9739 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9740 return false;
9741 }
9742 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9743 }
9744
9745 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009746 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9747 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009748 if (callingPackage == null) {
9749 callingPackage = getCurrentPackageName();
9750 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009751 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9752 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009753 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9754 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009755 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9756 }
9757 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9758 Intent intent = new Intent();
9759 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9760 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9761 // Bring up choose default SMS subscription dialog right now
9762 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9763 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9764 mApp.startActivity(intent);
9765 }
chen xud5ca2d52019-05-28 15:20:57 -07009766
9767 @Override
9768 public String getMmsUAProfUrl(int subId) {
9769 //TODO investigate if this API should require proper permission check in R b/133791609
9770 final long identity = Binder.clearCallingIdentity();
9771 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009772 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9773 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9774 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9775 return carrierUAProfUrl;
9776 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009777 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9778 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009779 } finally {
9780 Binder.restoreCallingIdentity(identity);
9781 }
9782 }
9783
9784 @Override
9785 public String getMmsUserAgent(int subId) {
9786 //TODO investigate if this API should require proper permission check in R b/133791609
9787 final long identity = Binder.clearCallingIdentity();
9788 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009789 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9790 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9791 if (!TextUtils.isEmpty(carrierUserAgent)) {
9792 return carrierUserAgent;
9793 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009794 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9795 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009796 } finally {
9797 Binder.restoreCallingIdentity(identity);
9798 }
9799 }
Jack Yub07d4972019-05-28 16:12:25 -07009800
9801 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009802 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9803 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009804
Jack Yub07d4972019-05-28 16:12:25 -07009805 final long identity = Binder.clearCallingIdentity();
9806 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009807 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009808 if (phone == null) return false;
9809
Hall Liua62f5da2020-09-25 10:42:19 -07009810 switch (policy) {
9811 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9812 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9813 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9814 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9815 default:
9816 throw new IllegalArgumentException(policy + " is not a valid policy");
9817 }
Jack Yub07d4972019-05-28 16:12:25 -07009818 } finally {
9819 Binder.restoreCallingIdentity(identity);
9820 }
9821 }
9822
9823 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009824 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009825 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009826 enforceModifyPermission();
9827
changbettyd5c246e2019-12-24 15:40:37 +08009828 final long identity = Binder.clearCallingIdentity();
9829 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009830 Phone phone = getPhone(subscriptionId);
9831 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009832
Hall Liua62f5da2020-09-25 10:42:19 -07009833 switch (policy) {
9834 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9835 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9836 break;
9837 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9838 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9839 break;
9840 default:
9841 throw new IllegalArgumentException(policy + " is not a valid policy");
9842 }
changbettyd5c246e2019-12-24 15:40:37 +08009843 } finally {
9844 Binder.restoreCallingIdentity(identity);
9845 }
9846 }
9847
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009848 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009849 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009850 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9851 * otherwise.
9852 */
9853 @Override
9854 public void setCepEnabled(boolean isCepEnabled) {
9855 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9856
9857 final long identity = Binder.clearCallingIdentity();
9858 try {
9859 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9860 for (Phone phone : PhoneFactory.getPhones()) {
9861 Phone defaultPhone = phone.getImsPhone();
9862 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9863 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9864 ImsPhoneCallTracker imsPhoneCallTracker =
9865 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9866 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9867 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9868 + imsPhone.getMsisdn());
9869 }
9870 }
9871 } finally {
9872 Binder.restoreCallingIdentity(identity);
9873 }
9874 }
allenwtsu46dcc572020-01-08 18:24:03 +08009875
9876 /**
9877 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9878 *
9879 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9880 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9881 * before being read.
9882 */
9883 @Override
9884 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9885 isCompressed) {
9886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9887 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9889 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9890 }
9891 if (!isImsAvailableOnDevice()) {
9892 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9893 "IMS not available on device.");
9894 }
9895
9896 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009897 try {
Hui Wang761a6682020-10-31 05:12:53 +00009898 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9899 } finally {
9900 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009901 }
9902 }
zoey chene02881a2019-12-30 16:11:23 +08009903
9904 @Override
9905 public boolean isIccLockEnabled(int subId) {
9906 enforceReadPrivilegedPermission("isIccLockEnabled");
9907
9908 // Now that all security checks passes, perform the operation as ourselves.
9909 final long identity = Binder.clearCallingIdentity();
9910 try {
9911 Phone phone = getPhone(subId);
9912 if (phone != null && phone.getIccCard() != null) {
9913 return phone.getIccCard().getIccLockEnabled();
9914 } else {
9915 return false;
9916 }
9917 } finally {
9918 Binder.restoreCallingIdentity(identity);
9919 }
9920 }
9921
9922 /**
9923 * Set the ICC pin lock enabled or disabled.
9924 *
9925 * @return an integer representing the status of IccLock enabled or disabled in the following
9926 * three cases:
9927 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9928 * successfully.
9929 * - Positive number and zero for remaining password attempts.
9930 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9931 *
9932 */
9933 @Override
9934 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9935 enforceModifyPermission();
9936
9937 Phone phone = getPhone(subId);
9938 if (phone == null) {
9939 return 0;
9940 }
9941 // Now that all security checks passes, perform the operation as ourselves.
9942 final long identity = Binder.clearCallingIdentity();
9943 try {
9944 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9945 new Pair<Boolean, String>(enabled, password), phone, null);
9946 return attemptsRemaining;
9947
9948 } catch (Exception e) {
9949 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9950 } finally {
9951 Binder.restoreCallingIdentity(identity);
9952 }
9953 return 0;
9954 }
9955
9956 /**
9957 * Change the ICC password used in ICC pin lock.
9958 *
9959 * @return an integer representing the status of IccLock changed in the following three cases:
9960 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9961 * - Positive number and zero for remaining password attempts.
9962 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9963 *
9964 */
9965 @Override
9966 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9967 enforceModifyPermission();
9968
9969 Phone phone = getPhone(subId);
9970 if (phone == null) {
9971 return 0;
9972 }
9973 // Now that all security checks passes, perform the operation as ourselves.
9974 final long identity = Binder.clearCallingIdentity();
9975 try {
9976 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9977 new Pair<String, String>(oldPassword, newPassword), phone, null);
9978 return attemptsRemaining;
9979
9980 } catch (Exception e) {
9981 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9982 } finally {
9983 Binder.restoreCallingIdentity(identity);
9984 }
9985 return 0;
9986 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009987
9988 /**
9989 * Request for receiving user activity notification
9990 */
9991 @Override
9992 public void requestUserActivityNotification() {
9993 if (!mNotifyUserActivity.get()
9994 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9995 mNotifyUserActivity.set(true);
9996 }
9997 }
9998
9999 /**
10000 * Called when userActivity is signalled in the power manager.
10001 * This is safe to call from any thread, with any window manager locks held or not.
10002 */
10003 @Override
10004 public void userActivity() {
10005 // ***************************************
10006 // * Inherited from PhoneWindowManager *
10007 // ***************************************
10008 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10009 // WITH ITS LOCKS HELD.
10010 //
10011 // This code must be VERY careful about the locks
10012 // it acquires.
10013 // In fact, the current code acquires way too many,
10014 // and probably has lurking deadlocks.
10015
10016 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10017 throw new SecurityException("Only the OS may call notifyUserActivity()");
10018 }
10019
10020 if (mNotifyUserActivity.getAndSet(false)) {
10021 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10022 USER_ACTIVITY_NOTIFICATION_DELAY);
10023 }
10024 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010025
10026 @Override
10027 public boolean canConnectTo5GInDsdsMode() {
10028 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10029 }
Jack Yud10cdd42020-09-28 20:28:01 -070010030
10031 @Override
10032 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10033 String callingFeatureId) {
10034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10035 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10036 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10037 }
10038
10039 Phone phone = getPhone(subId);
10040 if (phone == null) {
10041 throw new RuntimeException("phone is not available");
10042 }
10043 // Now that all security checks passes, perform the operation as ourselves.
10044 final long identity = Binder.clearCallingIdentity();
10045 try {
10046 return phone.getEquivalentHomePlmns();
10047 } finally {
10048 Binder.restoreCallingIdentity(identity);
10049 }
10050 }
Daniel Bright59e67312020-11-13 11:49:37 -080010051
10052 @Override
10053 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010054 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10055 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010056 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010057 if (radioInterfaceCapabilities == null) {
10058 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010059 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010060 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010061 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010062
Hui Wang641e81c2020-10-12 12:14:23 -070010063 @Override
10064 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10065 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010066 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10067 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10068 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10069 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10070 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010071 if (DBG) {
10072 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10073 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10074 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10075 }
10076
10077 if (!SubscriptionManager.isValidSubscriptionId(subId)
10078 || appType < TelephonyManager.APPTYPE_UNKNOWN
10079 || appType > TelephonyManager.APPTYPE_ISIM
10080 || nafUrl == null || securityProtocol == null || callback == null) {
10081 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10082 if (callback != null) {
10083 try {
10084 callback.onAuthenticationFailure(
10085 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10086 } catch (RemoteException exception) {
10087 log("Fail to notify onAuthenticationFailure due to " + exception);
10088 }
10089 return;
10090 }
10091 }
10092
10093 final long token = Binder.clearCallingIdentity();
10094 try {
10095 getGbaManager(subId).bootstrapAuthenticationRequest(
10096 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10097 forceBootStrapping, callback));
10098 } finally {
10099 Binder.restoreCallingIdentity(token);
10100 }
10101 }
10102
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010103 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010104 * Attempts to set the radio power state for all phones for thermal reason.
10105 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010106 * requested radio power state will actually be set. See {@link
10107 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10108 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010109 * @param enable {@code true} if trying to turn radio on.
10110 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10111 * false}.
10112 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010113 private boolean setRadioPowerForThermal(boolean enable) {
10114 boolean isPhoneAvailable = false;
10115 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10116 Phone phone = PhoneFactory.getPhone(i);
10117 if (phone != null) {
10118 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10119 isPhoneAvailable = true;
10120 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010121 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010122
10123 // return true if successfully informed the phone object about the thermal radio power
10124 // request.
10125 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010126 }
10127
10128 private int handleDataThrottlingRequest(int subId,
10129 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010130 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10131 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10132 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10133 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10134 throw new IllegalArgumentException("modem does not support data throttling");
10135 }
10136
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010137 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10138 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010139 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010140 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10141 }
10142
10143 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10144
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010145 if (isDataThrottlingSupported) {
10146 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010147 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010148 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10149 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10150 } else if (thermalMitigationResult
10151 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010152 log("Modem likely does not support data throttling on secondary carrier. Data " +
10153 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10154 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010155 }
10156 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010157 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010158
10159 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010160 }
10161
Jack Nudelman644b91a2021-03-12 14:09:48 -080010162 private static List<String> getThermalMitigationAllowlist(Context context) {
10163 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10164 for (String pckg : context.getResources()
10165 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10166 sThermalMitigationAllowlistedPackages.add(pckg);
10167 }
10168 }
10169
10170 return sThermalMitigationAllowlistedPackages;
10171 }
10172
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010173 private boolean isAnyPhoneInEmergencyState() {
10174 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10175 if (tm.isInEmergencyCall()) {
10176 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10177 return true;
10178 }
10179 for (Phone phone : PhoneFactory.getPhones()) {
10180 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10181 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10182 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10183 + phone.isInEcm());
10184 return true;
10185 }
10186 }
10187
10188 return false;
10189 }
10190
Jack Nudelman644b91a2021-03-12 14:09:48 -080010191 /**
10192 * Used by shell commands to add an authorized package name for thermal mitigation.
10193 * @param packageName name of package to be allowlisted
10194 * @param context
10195 */
10196 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10197 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10198 sThermalMitigationAllowlistedPackages.add(packageName);
10199 }
10200
10201 /**
10202 * Used by shell commands to remove an authorized package name for thermal mitigation.
10203 * @param packageName name of package to remove from allowlist
10204 * @param context
10205 */
10206 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10207 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10208 sThermalMitigationAllowlistedPackages.remove(packageName);
10209 }
10210
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010211 /**
10212 * Thermal mitigation request to control functionalities at modem.
10213 *
10214 * @param subId the id of the subscription.
10215 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010216 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010217 *
10218 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10219 */
10220 @Override
10221 @ThermalMitigationResult
10222 public int sendThermalMitigationRequest(
10223 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010224 ThermalMitigationRequest thermalMitigationRequest,
10225 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010226 enforceModifyPermission();
10227
Jack Nudelman644b91a2021-03-12 14:09:48 -080010228 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10229 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10230 .contains(callingPackage)) {
10231 throw new SecurityException("Calling package must be configured in the device config. "
10232 + "calling package: " + callingPackage);
10233 }
10234
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010235 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10236 final long identity = Binder.clearCallingIdentity();
10237
10238 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10239 try {
10240 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10241 switch (thermalMitigationAction) {
10242 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10243 thermalMitigationResult =
10244 handleDataThrottlingRequest(subId,
10245 thermalMitigationRequest.getDataThrottlingRequest());
10246 break;
10247 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10248 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10249 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10250 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10251 }
10252
10253 // Ensure that radio is on. If not able to power on due to phone being
10254 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010255 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010256 thermalMitigationResult =
10257 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10258 break;
10259 }
10260
10261 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10262 false);
10263 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10264 break;
10265 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10266 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10267 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10268 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10269 }
10270
10271 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10272 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010273 Phone phone = getPhone(subId);
10274 if (phone == null) {
10275 thermalMitigationResult =
10276 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10277 break;
10278 }
10279
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010280 TelephonyConnectionService service =
10281 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010282 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010283 Log.e(LOG_TAG, "An emergency call is pending");
10284 thermalMitigationResult =
10285 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10286 break;
10287 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010288 thermalMitigationResult =
10289 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10290 break;
10291 }
10292 } else {
10293 thermalMitigationResult =
10294 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10295 break;
10296 }
10297
10298 // Turn radio off. If not able to power off due to phone being unavailable,
10299 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010300 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010301 thermalMitigationResult =
10302 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10303 break;
10304 }
10305 thermalMitigationResult =
10306 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10307 break;
10308 default:
10309 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10310 + "not exist. Requested action: " + thermalMitigationAction);
10311 }
10312 } catch (IllegalArgumentException e) {
10313 throw e;
10314 } catch (Exception e) {
10315 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10316 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10317 } finally {
10318 Binder.restoreCallingIdentity(identity);
10319 }
10320
10321 if (DBG) {
10322 log("thermalMitigationRequest returning with thermalMitigationResult: "
10323 + thermalMitigationResult);
10324 }
10325
10326 return thermalMitigationResult;
10327 }
Hui Wang641e81c2020-10-12 12:14:23 -070010328
10329 /**
10330 * Set the GbaService Package Name that Telephony will bind to.
10331 *
10332 * @param subId The sim that the GbaService is associated with.
10333 * @param packageName The name of the package to be replaced with.
10334 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10335 */
10336 @Override
10337 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10338 enforceModifyPermission();
10339
10340 final long identity = Binder.clearCallingIdentity();
10341 try {
10342 return getGbaManager(subId).overrideServicePackage(packageName);
10343 } finally {
10344 Binder.restoreCallingIdentity(identity);
10345 }
10346 }
10347
10348 /**
10349 * Return the package name of the currently bound GbaService.
10350 *
10351 * @param subId The sim that the GbaService is associated with.
10352 * @return the package name of the GbaService configuration, null if GBA is not supported.
10353 */
10354 @Override
10355 public String getBoundGbaService(int subId) {
10356 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10357
10358 final long identity = Binder.clearCallingIdentity();
10359 try {
10360 return getGbaManager(subId).getServicePackage();
10361 } finally {
10362 Binder.restoreCallingIdentity(identity);
10363 }
10364 }
10365
10366 /**
10367 * Set the release time for telephony to unbind GbaService.
10368 *
10369 * @param subId The sim that the GbaService is associated with.
10370 * @param interval The release time to unbind GbaService by millisecond.
10371 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10372 */
10373 @Override
10374 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10375 enforceModifyPermission();
10376
10377 final long identity = Binder.clearCallingIdentity();
10378 try {
10379 return getGbaManager(subId).overrideReleaseTime(interval);
10380 } finally {
10381 Binder.restoreCallingIdentity(identity);
10382 }
10383 }
10384
10385 /**
10386 * Return the release time for telephony to unbind GbaService.
10387 *
10388 * @param subId The sim that the GbaService is associated with.
10389 * @return The release time to unbind GbaService by millisecond.
10390 */
10391 @Override
10392 public int getGbaReleaseTime(int subId) {
10393 enforceReadPrivilegedPermission("getGbaReleaseTime");
10394
10395 final long identity = Binder.clearCallingIdentity();
10396 try {
10397 return getGbaManager(subId).getReleaseTime();
10398 } finally {
10399 Binder.restoreCallingIdentity(identity);
10400 }
10401 }
10402
10403 private GbaManager getGbaManager(int subId) {
10404 GbaManager instance = GbaManager.getInstance(subId);
10405 if (instance == null) {
10406 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10407 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10408 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10409 }
10410 return instance;
10411 }
Hui Wang761a6682020-10-31 05:12:53 +000010412
10413 /**
10414 * indicate whether the device and the carrier can support
10415 * RCS VoLTE single registration.
10416 */
10417 @Override
10418 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010419 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10420 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10421 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10422 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010423
10424 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10425 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10426 }
10427
10428 final long identity = Binder.clearCallingIdentity();
10429 try {
10430 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10431 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010432 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10433 if (isCapable != null) {
10434 return isCapable;
10435 }
Hui Wang761a6682020-10-31 05:12:53 +000010436 }
Hui Wang67af90e2021-06-04 16:57:15 -070010437 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10438 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010439 } finally {
10440 Binder.restoreCallingIdentity(identity);
10441 }
10442 }
10443
10444 /**
10445 * Register RCS provisioning callback.
10446 */
10447 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010448 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010449 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010450 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010451 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010452 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10453 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010454
10455 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10456 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10457 }
10458 if (!isImsAvailableOnDevice()) {
10459 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10460 "IMS not available on device.");
10461 }
10462
10463 final long identity = Binder.clearCallingIdentity();
10464 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010465 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010466 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010467 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10468 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010469 }
Hui Wang761a6682020-10-31 05:12:53 +000010470 } finally {
10471 Binder.restoreCallingIdentity(identity);
10472 }
10473 }
10474
10475 /**
10476 * Unregister RCS provisioning callback.
10477 */
10478 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010479 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010480 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010481 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010482 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010483 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10484 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010485
10486 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10487 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10488 }
10489 if (!isImsAvailableOnDevice()) {
10490 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10491 "IMS not available on device.");
10492 }
10493
10494 final long identity = Binder.clearCallingIdentity();
10495 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010496 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010497 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010498 } finally {
10499 Binder.restoreCallingIdentity(identity);
10500 }
10501 }
10502
10503 /**
10504 * trigger RCS reconfiguration.
10505 */
10506 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010507 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10508 "triggerRcsReconfiguration",
10509 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010510
10511 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10512 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10513 }
10514 if (!isImsAvailableOnDevice()) {
10515 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10516 "IMS not available on device.");
10517 }
10518
10519 final long identity = Binder.clearCallingIdentity();
10520 try {
10521 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10522 } finally {
10523 Binder.restoreCallingIdentity(identity);
10524 }
10525 }
10526
10527 /**
10528 * Provide the client configuration parameters of the RCS application.
10529 */
10530 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010531 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10532 "setRcsClientConfiguration",
10533 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010534
10535 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10536 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10537 }
10538 if (!isImsAvailableOnDevice()) {
10539 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10540 "IMS not available on device.");
10541 }
10542
10543 final long identity = Binder.clearCallingIdentity();
10544
10545 try {
10546 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10547 if (configBinder == null) {
10548 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010549 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10550 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010551 } else {
10552 configBinder.setRcsClientConfiguration(rcc);
10553 }
joonhunshin3e154242021-09-17 06:33:39 +000010554
10555 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10556 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010557 } catch (RemoteException e) {
10558 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010559 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10560 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010561 } finally {
10562 Binder.restoreCallingIdentity(identity);
10563 }
10564 }
10565
10566 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010567 * Enables or disables the test mode for RCS VoLTE single registration.
10568 */
10569 @Override
10570 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10571 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10572 "setRcsSingleRegistrationTestModeEnabled");
10573
10574 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10575 }
10576
10577 /**
10578 * Gets the test mode for RCS VoLTE single registration.
10579 */
10580 @Override
10581 public boolean getRcsSingleRegistrationTestModeEnabled() {
10582 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10583 "getRcsSingleRegistrationTestModeEnabled");
10584
10585 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10586 }
10587
10588 /**
Hui Wang761a6682020-10-31 05:12:53 +000010589 * Overrides the config of RCS VoLTE single registration enabled for the device.
10590 */
10591 @Override
10592 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10593 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10594 "setDeviceSingleRegistrationEnabledOverride");
10595 enforceModifyPermission();
10596
10597 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10598 : Boolean.parseBoolean(enabledStr);
10599 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010600 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010601 }
10602
10603 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010604 * Sends a device to device communication message. Only usable via shell.
10605 * @param message message to send.
10606 * @param value message value.
10607 */
10608 @Override
10609 public void sendDeviceToDeviceMessage(int message, int value) {
10610 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010611 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010612 enforceModifyPermission();
10613
10614 final long identity = Binder.clearCallingIdentity();
10615 try {
10616 TelephonyConnectionService service =
10617 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10618 if (service == null) {
10619 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10620 return;
10621 }
10622 service.sendTestDeviceToDeviceMessage(message, value);
10623 } finally {
10624 Binder.restoreCallingIdentity(identity);
10625 }
10626 }
10627
Tyler Gunnbabbda02021-02-10 11:05:02 -080010628 /**
10629 * Sets the specified device to device transport active.
10630 * @param transport The transport to set active.
10631 */
10632 @Override
10633 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10634 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10635 "setActiveDeviceToDeviceTransport");
10636 enforceModifyPermission();
10637
10638 final long identity = Binder.clearCallingIdentity();
10639 try {
10640 TelephonyConnectionService service =
10641 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10642 if (service == null) {
10643 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10644 return;
10645 }
10646 service.setActiveDeviceToDeviceTransport(transport);
10647 } finally {
10648 Binder.restoreCallingIdentity(identity);
10649 }
10650 }
Tyler Gunn92479152021-01-20 16:30:10 -080010651
Tyler Gunnd4339262021-05-03 14:46:49 -070010652 @Override
10653 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10654 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10655 "setDeviceToDeviceForceEnabled");
10656
10657 final long identity = Binder.clearCallingIdentity();
10658 try {
10659 Arrays.stream(PhoneFactory.getPhones()).forEach(
10660 p -> {
10661 Phone thePhone = p.getImsPhone();
10662 if (thePhone != null && thePhone instanceof ImsPhone) {
10663 ImsPhone imsPhone = (ImsPhone) thePhone;
10664 CallTracker tracker = imsPhone.getCallTracker();
10665 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10666 ImsPhoneCallTracker imsPhoneCallTracker =
10667 (ImsPhoneCallTracker) tracker;
10668 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10669 }
10670 }
10671 }
10672 );
10673 } finally {
10674 Binder.restoreCallingIdentity(identity);
10675 }
10676 }
10677
Tyler Gunn92479152021-01-20 16:30:10 -080010678 /**
Hui Wang761a6682020-10-31 05:12:53 +000010679 * Gets the config of RCS VoLTE single registration enabled for the device.
10680 */
10681 @Override
10682 public boolean getDeviceSingleRegistrationEnabled() {
10683 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10684 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10685 }
10686
10687 /**
10688 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10689 */
10690 @Override
10691 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10692 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10693 "setCarrierSingleRegistrationEnabledOverride");
10694 enforceModifyPermission();
10695
10696 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10697 : Boolean.parseBoolean(enabledStr);
10698 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10699 subId, enabled);
10700 }
10701
10702 /**
10703 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10704 */
10705 @Override
10706 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10707 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10708 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10709 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010710
10711 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010712 * Overrides the ims feature validation result
10713 */
10714 @Override
10715 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10716 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10717 "setImsFeatureValidationOverride");
10718
10719 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10720 : Boolean.parseBoolean(enabledStr);
10721 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10722 subId, enabled);
10723 }
10724
10725 /**
10726 * Gets the ims feature validation override value
10727 */
10728 @Override
10729 public boolean getImsFeatureValidationOverride(int subId) {
10730 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10731 "getImsFeatureValidationOverride");
10732 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10733 }
10734
10735 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010736 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10737 * their mobile plan.
10738 */
10739 @Override
10740 public String getMobileProvisioningUrl() {
10741 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10742 final long identity = Binder.clearCallingIdentity();
10743 try {
10744 return getDefaultPhone().getMobileProvisioningUrl();
10745 } finally {
10746 Binder.restoreCallingIdentity(identity);
10747 }
10748 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010749
James.cf Linbcdf8b32021-01-14 16:44:13 +080010750 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010751 * Get the EAB contact from the EAB database.
10752 */
10753 @Override
10754 public String getContactFromEab(String contact) {
10755 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10756 enforceModifyPermission();
10757 final long identity = Binder.clearCallingIdentity();
10758 try {
10759 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10760 } finally {
10761 Binder.restoreCallingIdentity(identity);
10762 }
10763 }
10764
10765 /**
Calvin Pana1434322021-07-01 19:27:01 +080010766 * Get the EAB capability from the EAB database.
10767 */
10768 @Override
10769 public String getCapabilityFromEab(String contact) {
10770 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10771 enforceModifyPermission();
10772 final long identity = Binder.clearCallingIdentity();
10773 try {
10774 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10775 } finally {
10776 Binder.restoreCallingIdentity(identity);
10777 }
10778 }
10779
10780 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010781 * Remove the EAB contacts from the EAB database.
10782 */
10783 @Override
10784 public int removeContactFromEab(int subId, String contacts) {
10785 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10786 enforceModifyPermission();
10787 final long identity = Binder.clearCallingIdentity();
10788 try {
10789 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10790 } finally {
10791 Binder.restoreCallingIdentity(identity);
10792 }
10793 }
10794
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010795 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010796 public boolean getDeviceUceEnabled() {
10797 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10798 final long identity = Binder.clearCallingIdentity();
10799 try {
10800 return mApp.getDeviceUceEnabled();
10801 } finally {
10802 Binder.restoreCallingIdentity(identity);
10803 }
10804 }
10805
10806 @Override
10807 public void setDeviceUceEnabled(boolean isEnabled) {
10808 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10809 final long identity = Binder.clearCallingIdentity();
10810 try {
10811 mApp.setDeviceUceEnabled(isEnabled);
10812 } finally {
10813 Binder.restoreCallingIdentity(identity);
10814 }
10815 }
10816
Brad Ebinger14d467f2021-02-12 06:18:28 +000010817 /**
10818 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10819 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10820 */
10821 // Used for SHELL command only right now.
10822 @Override
10823 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10824 List<String> featureTags) {
10825 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10826 "addUceRegistrationOverrideShell");
10827 final long identity = Binder.clearCallingIdentity();
10828 try {
10829 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10830 new ArraySet<>(featureTags));
10831 } catch (ImsException e) {
10832 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10833 } finally {
10834 Binder.restoreCallingIdentity(identity);
10835 }
10836 }
10837
10838 /**
10839 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10840 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10841 */
10842 // Used for SHELL command only right now.
10843 @Override
10844 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10845 List<String> featureTags) {
10846 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10847 "removeUceRegistrationOverrideShell");
10848 final long identity = Binder.clearCallingIdentity();
10849 try {
10850 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10851 new ArraySet<>(featureTags));
10852 } catch (ImsException e) {
10853 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10854 } finally {
10855 Binder.restoreCallingIdentity(identity);
10856 }
10857 }
10858
10859 /**
10860 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10861 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10862 */
10863 // Used for SHELL command only right now.
10864 @Override
10865 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10866 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10867 "clearUceRegistrationOverrideShell");
10868 final long identity = Binder.clearCallingIdentity();
10869 try {
10870 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10871 } catch (ImsException e) {
10872 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10873 } finally {
10874 Binder.restoreCallingIdentity(identity);
10875 }
10876 }
10877
10878 /**
10879 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10880 */
10881 // Used for SHELL command only right now.
10882 @Override
10883 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10884 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10885 "getLatestRcsContactUceCapabilityShell");
10886 final long identity = Binder.clearCallingIdentity();
10887 try {
10888 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10889 } catch (ImsException e) {
10890 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10891 } finally {
10892 Binder.restoreCallingIdentity(identity);
10893 }
10894 }
10895
10896 /**
10897 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10898 * device does not have an active PUBLISH.
10899 */
10900 // Used for SHELL command only right now.
10901 @Override
10902 public String getLastUcePidfXmlShell(int subId) {
10903 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10904 final long identity = Binder.clearCallingIdentity();
10905 try {
10906 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10907 } catch (ImsException e) {
10908 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10909 } finally {
10910 Binder.restoreCallingIdentity(identity);
10911 }
10912 }
10913
James.cf Line8713a42021-04-29 16:04:26 +080010914 /**
10915 * Remove UCE requests cannot be sent to the network status.
10916 */
10917 // Used for SHELL command only right now.
10918 @Override
10919 public boolean removeUceRequestDisallowedStatus(int subId) {
10920 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10921 final long identity = Binder.clearCallingIdentity();
10922 try {
10923 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10924 } catch (ImsException e) {
10925 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10926 } finally {
10927 Binder.restoreCallingIdentity(identity);
10928 }
10929 }
10930
James.cf Lin18bb9002021-05-25 01:37:38 +080010931 /**
10932 * Remove UCE requests cannot be sent to the network status.
10933 */
10934 // Used for SHELL command only.
10935 @Override
10936 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10937 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10938 final long identity = Binder.clearCallingIdentity();
10939 try {
10940 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10941 } catch (ImsException e) {
10942 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10943 } finally {
10944 Binder.restoreCallingIdentity(identity);
10945 }
10946 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010947
James.cf Lin4b784aa2021-01-31 03:25:15 +080010948 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010949 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10950 String callingPackage) {
10951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10952 mApp, subId, "setSignalStrengthUpdateRequest");
10953
10954 final int callingUid = Binder.getCallingUid();
10955 // Verify that tha callingPackage belongs to the calling UID
10956 mApp.getSystemService(AppOpsManager.class)
10957 .checkPackage(callingUid, callingPackage);
10958
Rambo Wang3607f502021-02-01 21:51:40 -080010959 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010960
10961 final long identity = Binder.clearCallingIdentity();
10962 try {
10963 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10964 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10965
10966 if (result instanceof IllegalStateException) {
10967 throw (IllegalStateException) result;
10968 }
10969 } finally {
10970 Binder.restoreCallingIdentity(identity);
10971 }
10972 }
10973
10974 @Override
10975 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10976 String callingPackage) {
10977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10978 mApp, subId, "clearSignalStrengthUpdateRequest");
10979
10980 final int callingUid = Binder.getCallingUid();
10981 // Verify that tha callingPackage belongs to the calling UID
10982 mApp.getSystemService(AppOpsManager.class)
10983 .checkPackage(callingUid, callingPackage);
10984
10985 final long identity = Binder.clearCallingIdentity();
10986 try {
10987 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10988 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10989
10990 if (result instanceof IllegalStateException) {
10991 throw (IllegalStateException) result;
10992 }
10993 } finally {
10994 Binder.restoreCallingIdentity(identity);
10995 }
10996 }
10997
Rambo Wang3607f502021-02-01 21:51:40 -080010998 private static void validateSignalStrengthUpdateRequest(Context context,
10999 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011000 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11001 // phone/system process do not have further restriction on request
11002 return;
11003 }
11004
11005 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011006 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011007 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011008 context.enforceCallingOrSelfPermission(
11009 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11010 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011011 }
11012
11013 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11014 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11015 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11016 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11017 || info.isEnabled()) {
11018 throw new IllegalArgumentException(
11019 "Only system can set hide fields in SignalThresholdInfo");
11020 }
11021
11022 // Thresholds length for each RAN need in range. This has been validated in
11023 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11024 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11025 final int[] thresholds = info.getThresholds();
11026 Objects.requireNonNull(thresholds);
11027 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11028 || thresholds.length
11029 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11030 throw new IllegalArgumentException(
11031 "thresholds length is out of range: " + thresholds.length);
11032 }
11033 }
11034 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011035
11036 /**
11037 * Gets the current phone capability.
11038 *
11039 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11040 * @return the PhoneCapability which describes the data connection capability of modem.
11041 * It's used to evaluate possible phone config change, for example from single
11042 * SIM device to multi-SIM device.
11043 */
11044 @Override
11045 public PhoneCapability getPhoneCapability() {
11046 enforceReadPrivilegedPermission("getPhoneCapability");
11047 final long identity = Binder.clearCallingIdentity();
11048 try {
11049 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11050 } finally {
11051 Binder.restoreCallingIdentity(identity);
11052 }
11053 }
Michele Berionne5e411512020-11-13 02:36:59 +000011054
11055 /**
11056 * Prepare TelephonyManager for an unattended reboot. The reboot is
11057 * required to be done shortly after the API is invoked.
11058 */
11059 @Override
11060 @TelephonyManager.PrepareUnattendedRebootResult
11061 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011062 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011063 enforceRebootPermission();
11064
11065 final long identity = Binder.clearCallingIdentity();
11066 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011067 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011068 } finally {
11069 Binder.restoreCallingIdentity(identity);
11070 }
11071 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011072
11073 /**
11074 * Request to get the current slicing configuration including URSP rules and
11075 * NSSAIs (configured, allowed and rejected).
11076 *
11077 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11078 */
11079 @Override
11080 public void getSlicingConfig(ResultReceiver callback) {
11081 enforceReadPrivilegedPermission("getSlicingConfig");
11082
11083 final long identity = Binder.clearCallingIdentity();
11084 try {
11085 Phone phone = getDefaultPhone();
11086 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11087 } finally {
11088 Binder.restoreCallingIdentity(identity);
11089 }
11090 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011091
11092 /**
11093 * Register an IMS connection state callback
11094 */
11095 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011096 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11097 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011098 if (feature == ImsFeature.FEATURE_MMTEL) {
11099 // ImsMmTelManager
11100 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11101 TelephonyPermissions
11102 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11103 mApp, subId, "registerImsStateCallback");
11104 } else if (feature == ImsFeature.FEATURE_RCS) {
11105 // ImsRcsManager or SipDelegateManager
11106 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11107 Binder.getCallingUid(), "registerImsStateCallback",
11108 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11109 Manifest.permission.READ_PRECISE_PHONE_STATE,
11110 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11111 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11112 }
11113
11114 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11115 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11116 "IMS not available on device.");
11117 }
11118
11119 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11120 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11121 }
11122
11123 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11124 if (controller == null) {
11125 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11126 "IMS not available on device.");
11127 }
11128
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011129 if (callingPackage == null) {
11130 callingPackage = getCurrentPackageName();
11131 }
11132
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011133 final long token = Binder.clearCallingIdentity();
11134 try {
11135 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011136 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011137 } catch (ImsException e) {
11138 throw new ServiceSpecificException(e.getCode());
11139 } finally {
11140 Binder.restoreCallingIdentity(token);
11141 }
11142 }
11143
11144 /**
11145 * Unregister an IMS connection state callback
11146 */
11147 @Override
11148 public void unregisterImsStateCallback(IImsStateCallback cb) {
11149 final long token = Binder.clearCallingIdentity();
11150 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11151 if (controller == null) {
11152 return;
11153 }
11154 try {
11155 controller.unregisterImsStateCallback(cb);
11156 } finally {
11157 Binder.restoreCallingIdentity(token);
11158 }
11159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011160}