blob: abbdbdba9a87d6bf8788d8d77c7b15752a679037 [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;
Rambo Wanga1782702021-11-10 20:15:19 -0800166import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700167import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700168import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700169import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700171import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800172import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700173import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700174import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700175import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700176import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800177import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800178import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700179import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700180import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700181import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800182import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800183import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800184import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700185import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700187import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800188import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700189import com.android.internal.telephony.imsphone.ImsPhone;
190import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000191import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800192import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700193import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700194import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800195import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800197import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700198import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000201import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800202import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000203import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800204import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700205import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700206import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800207import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800208import com.android.phone.callcomposer.CallComposerPictureManager;
209import com.android.phone.callcomposer.CallComposerPictureTransfer;
210import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700211import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700212import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800213import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700214import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700215import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800216import com.android.services.telephony.TelecomAccountRegistry;
217import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800218import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800219
Hall Liu82694d52020-12-11 18:22:04 -0800220import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700221import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.io.IOException;
223import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700224import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800226import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000227import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800228import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800229import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800230import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100231import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800232import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700233import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800234import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800235import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800236import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800237import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800238import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239
240/**
241 * Implementation of the ITelephony interface.
242 */
Santos Cordon117fee72014-05-16 17:56:12 -0700243public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244 private static final String LOG_TAG = "PhoneInterfaceManager";
245 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
246 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800247 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248
249 // Message codes used with mMainThreadHandler
250 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700251 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
252 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700253 private static final int CMD_OPEN_CHANNEL = 9;
254 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
255 private static final int CMD_CLOSE_CHANNEL = 11;
256 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800257 private static final int CMD_NV_READ_ITEM = 13;
258 private static final int EVENT_NV_READ_ITEM_DONE = 14;
259 private static final int CMD_NV_WRITE_ITEM = 15;
260 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
261 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
262 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700263 private static final int CMD_RESET_MODEM_CONFIG = 19;
264 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800265 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
266 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800267 private static final int CMD_SEND_ENVELOPE = 25;
268 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000269 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
270 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700271 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
272 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
273 private static final int CMD_EXCHANGE_SIM_IO = 31;
274 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800275 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
276 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700277 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
278 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700279 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
280 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700281 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
282 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
283 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
284 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700285 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
286 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
287 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
288 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700289 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800290 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
291 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000292 private static final int CMD_SWITCH_SLOTS = 50;
293 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700294 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
295 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
296 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
297 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
298 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
299 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
300 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
301 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700302 private static final int CMD_GET_ALL_CELL_INFO = 60;
303 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
304 private static final int CMD_GET_CELL_LOCATION = 62;
305 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700306 private static final int CMD_MODEM_REBOOT = 64;
307 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700308 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
309 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800310 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
311 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700312 private static final int CMD_GET_MODEM_STATUS = 70;
313 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700314 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
315 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700316 private static final int CMD_ERASE_MODEM_CONFIG = 74;
317 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800318 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
319 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
320 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
321 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800322 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
323 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800324 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800325 private static final int CMD_GET_CALL_FORWARDING = 83;
326 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
327 private static final int CMD_SET_CALL_FORWARDING = 85;
328 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
329 private static final int CMD_GET_CALL_WAITING = 87;
330 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
331 private static final int CMD_SET_CALL_WAITING = 89;
332 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700333 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
334 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
335 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
336 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700337 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
338 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800339 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
340 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800341 private static final int CMD_SET_DATA_THROTTLING = 99;
342 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800343 private static final int CMD_SET_SIM_POWER = 101;
344 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800345 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
346 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
347 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
348 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800349 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
350 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000351 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800352 private static final int CMD_GET_SLICING_CONFIG = 110;
353 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800354 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700355 private static final int CMD_ENABLE_VONR = 113;
356 private static final int EVENT_ENABLE_VONR_DONE = 114;
357 private static final int CMD_IS_VONR_ENABLED = 115;
358 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800360 // Parameters of select command.
361 private static final int SELECT_COMMAND = 0xA4;
362 private static final int SELECT_P1 = 0x04;
363 private static final int SELECT_P2 = 0;
364 private static final int SELECT_P3 = 0x10;
365
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 /** The singleton instance. */
367 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800368 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
Wink Saville3ab207e2014-11-20 13:07:20 -0800370 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800371 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800372 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700373 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700375 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800377 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700379 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800380 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381
Peter Wangdafb9ac2020-01-15 14:13:38 -0800382 /** User Activity */
383 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800384 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
385
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700386 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
387
Derek Tan97ebb422014-09-05 16:55:38 -0700388 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
389 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800390 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800391 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700392
Michelecea4cf22018-12-21 15:00:11 -0800393 // String to store multi SIM allowed
394 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
395
Derek Tan740e1672017-06-27 14:56:27 -0700396 // The AID of ISD-R.
397 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
398
yinxub1bed742017-04-17 11:45:04 -0700399 private NetworkScanRequestTracker mNetworkScanRequestTracker;
400
David Kelly5e06a7f2018-03-12 14:10:59 +0000401 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
402 private static final int MANUFACTURER_CODE_LENGTH = 8;
403
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800404 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800405 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800406
Derek Tan89e89d42014-07-08 17:00:10 -0700407 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700408 * Experiment flag to enable erase modem config on reset network, default value is false
409 */
410 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
411 "reset_network_erase_modem_config_enabled";
412
Rambo Wang0f050d82021-02-12 11:43:36 -0800413 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjsb6c87872021-09-27 15:34:44 +0000414 /**
415 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
416 * one ICCID active at the same time.
417 * Apps should use below API signatures if targeting SDK is T and beyond.
418 *
419 * @hide
420 */
421 @ChangeId
422 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
423 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800424
Naina Nallurid63128d2019-09-17 14:10:30 -0700425 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700426 * A request object to use for transmitting data to an ICC.
427 */
428 private static final class IccAPDUArgument {
429 public int channel, cla, command, p1, p2, p3;
430 public String data;
431
432 public IccAPDUArgument(int channel, int cla, int command,
433 int p1, int p2, int p3, String data) {
434 this.channel = channel;
435 this.cla = cla;
436 this.command = command;
437 this.p1 = p1;
438 this.p2 = p2;
439 this.p3 = p3;
440 this.data = data;
441 }
442 }
443
444 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700445 * A request object to use for transmitting data to an ICC.
446 */
447 private static final class ManualNetworkSelectionArgument {
448 public OperatorInfo operatorInfo;
449 public boolean persistSelection;
450
451 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
452 this.operatorInfo = operatorInfo;
453 this.persistSelection = persistSelection;
454 }
455 }
456
457 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
459 * request after sending. The main thread will notify the request when it is complete.
460 */
461 private static final class MainThreadRequest {
462 /** The argument to use for the request */
463 public Object argument;
464 /** The result of the request that is run on the main thread */
465 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800466 // The subscriber id that this request applies to. Defaults to
467 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
468 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469
Nathan Harold92bed182018-10-12 18:16:49 -0700470 // In cases where subId is unavailable, the caller needs to specify the phone.
471 public Phone phone;
472
vagdeviaf9a5b92018-08-15 16:01:53 -0700473 public WorkSource workSource;
474
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 public MainThreadRequest(Object argument) {
476 this.argument = argument;
477 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800478
Nathan Harold92bed182018-10-12 18:16:49 -0700479 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
480 this.argument = argument;
481 if (phone != null) {
482 this.phone = phone;
483 }
484 this.workSource = workSource;
485 }
486
vagdeviaf9a5b92018-08-15 16:01:53 -0700487 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800488 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800489 if (subId != null) {
490 this.subId = subId;
491 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700492 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 }
495
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800496 private static final class IncomingThirdPartyCallArgs {
497 public final ComponentName component;
498 public final String callId;
499 public final String callerDisplayName;
500
501 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
502 String callerDisplayName) {
503 this.component = component;
504 this.callId = callId;
505 this.callerDisplayName = callerDisplayName;
506 }
507 }
508
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 /**
510 * A handler that processes messages on the main thread in the phone process. Since many
511 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
512 * inbound binder threads to the main thread in the phone process. The Binder thread
513 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
514 * on, which will be notified when the operation completes and will contain the result of the
515 * request.
516 *
517 * <p>If a MainThreadRequest object is provided in the msg.obj field,
518 * note that request.result must be set to something non-null for the calling thread to
519 * unblock.
520 */
521 private final class MainThreadHandler extends Handler {
522 @Override
523 public void handleMessage(Message msg) {
524 MainThreadRequest request;
525 Message onCompleted;
526 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000527 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800529 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530
531 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 case CMD_HANDLE_USSD_REQUEST: {
533 request = (MainThreadRequest) msg.obj;
534 final Phone phone = getPhoneFromRequest(request);
535 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
536 String ussdRequest = ussdObject.first;
537 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700538
Pengquan Menga1bb6272018-09-06 09:59:22 -0700539 if (!isUssdApiAllowed(request.subId)) {
540 // Carrier does not support use of this API, return failure.
541 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
542 UssdResponse response = new UssdResponse(ussdRequest, null);
543 Bundle returnData = new Bundle();
544 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
545 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700546
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 request.result = true;
548 notifyRequester(request);
549 return;
550 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700551
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 try {
553 request.result = phone != null
554 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
555 } catch (CallStateException cse) {
556 request.result = false;
557 }
558 // Wake up the requesting thread
559 notifyRequester(request);
560 break;
pkanwar32d516d2016-10-14 19:37:38 -0700561 }
562
Yorke Lee716f67e2015-06-17 15:39:16 -0700563 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700564 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700565 final Phone phone = getPhoneFromRequest(request);
566 request.result = phone != null ?
567 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
568 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700573
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000577 uiccPort = getUiccPortFromRequest(request);
578 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 loge("iccTransmitApduLogicalChannel: No UICC");
580 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
584 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000585 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 iccArgument.channel, iccArgument.cla, iccArgument.command,
587 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 break;
591
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 ar = (AsyncResult) msg.obj;
594 request = (MainThreadRequest) ar.userObj;
595 if (ar.exception == null && ar.result != null) {
596 request.result = ar.result;
597 } else {
598 request.result = new IccIoResult(0x6F, 0, (byte[])null);
599 if (ar.result == null) {
600 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800601 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800603 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 } else {
605 loge("iccTransmitApduLogicalChannel: Unknown exception");
606 }
607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
612 request = (MainThreadRequest) msg.obj;
613 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000614 uiccPort = getUiccPortFromRequest(request);
615 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 loge("iccTransmitApduBasicChannel: No UICC");
617 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 } else {
620 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
621 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000622 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
624 iccArgument.p3, iccArgument.data, onCompleted);
625 }
626 break;
627
628 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
629 ar = (AsyncResult) msg.obj;
630 request = (MainThreadRequest) ar.userObj;
631 if (ar.exception == null && ar.result != null) {
632 request.result = ar.result;
633 } else {
634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
635 if (ar.result == null) {
636 loge("iccTransmitApduBasicChannel: Empty response");
637 } else if (ar.exception instanceof CommandException) {
638 loge("iccTransmitApduBasicChannel: CommandException: " +
639 ar.exception);
640 } else {
641 loge("iccTransmitApduBasicChannel: Unknown exception");
642 }
643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 break;
646
647 case CMD_EXCHANGE_SIM_IO:
648 request = (MainThreadRequest) msg.obj;
649 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000650 uiccPort = getUiccPortFromRequest(request);
651 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 loge("iccExchangeSimIO: No UICC");
653 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
657 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000658 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
660 iccArgument.data, onCompleted);
661 }
662 break;
663
664 case EVENT_EXCHANGE_SIM_IO_DONE:
665 ar = (AsyncResult) msg.obj;
666 request = (MainThreadRequest) ar.userObj;
667 if (ar.exception == null && ar.result != null) {
668 request.result = ar.result;
669 } else {
670 request.result = new IccIoResult(0x6f, 0, (byte[])null);
671 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700672 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 break;
674
Derek Tan4d5e5c12014-02-04 11:54:58 -0800675 case CMD_SEND_ENVELOPE:
676 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000677 uiccPort = getUiccPortFromRequest(request);
678 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 loge("sendEnvelopeWithStatus: No UICC");
680 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 } else {
683 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000684 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700685 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800686 break;
687
688 case EVENT_SEND_ENVELOPE_DONE:
689 ar = (AsyncResult) msg.obj;
690 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700691 if (ar.exception == null && ar.result != null) {
692 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800693 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700694 request.result = new IccIoResult(0x6F, 0, (byte[])null);
695 if (ar.result == null) {
696 loge("sendEnvelopeWithStatus: Empty response");
697 } else if (ar.exception instanceof CommandException) {
698 loge("sendEnvelopeWithStatus: CommandException: " +
699 ar.exception);
700 } else {
701 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
702 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700704 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 break;
706
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 case CMD_OPEN_CHANNEL:
708 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000709 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800710 IccLogicalChannelRequest openChannelRequest =
711 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000712 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700713 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800714 request.result = new IccOpenLogicalChannelResponse(-1,
715 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700717 } else {
718 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800719 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
720 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700721 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 break;
723
724 case EVENT_OPEN_CHANNEL_DONE:
725 ar = (AsyncResult) msg.obj;
726 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700727 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700728 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700729 int[] result = (int[]) ar.result;
730 int channelId = result[0];
731 byte[] selectResponse = null;
732 if (result.length > 1) {
733 selectResponse = new byte[result.length - 1];
734 for (int i = 1; i < result.length; ++i) {
735 selectResponse[i - 1] = (byte) result[i];
736 }
737 }
738 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700739 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 if (ar.result == null) {
742 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700744 if (ar.exception != null) {
745 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
746 }
747
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700748 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700749 if (ar.exception instanceof CommandException) {
750 CommandException.Error error =
751 ((CommandException) (ar.exception)).getCommandError();
752 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700753 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700754 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700755 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700756 }
757 }
758 openChannelResp = new IccOpenLogicalChannelResponse(
759 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700761 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700762 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 break;
764
765 case CMD_CLOSE_CHANNEL:
766 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000767 uiccPort = getUiccPortFromRequest(request);
768 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700769 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900770 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700771 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700772 } else {
773 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000774 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700775 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700776 break;
777
778 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800779 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
780 break;
781
782 case CMD_NV_READ_ITEM:
783 request = (MainThreadRequest) msg.obj;
784 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800785 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
786 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800787 break;
788
789 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 ar = (AsyncResult) msg.obj;
791 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800792 if (ar.exception == null && ar.result != null) {
793 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700794 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800795 request.result = "";
796 if (ar.result == null) {
797 loge("nvReadItem: Empty response");
798 } else if (ar.exception instanceof CommandException) {
799 loge("nvReadItem: CommandException: " +
800 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700801 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800802 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 }
804 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700805 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700806 break;
807
Jake Hambye994d462014-02-03 13:10:13 -0800808 case CMD_NV_WRITE_ITEM:
809 request = (MainThreadRequest) msg.obj;
810 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
811 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800812 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700813 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800814 break;
815
816 case EVENT_NV_WRITE_ITEM_DONE:
817 handleNullReturnEvent(msg, "nvWriteItem");
818 break;
819
820 case CMD_NV_WRITE_CDMA_PRL:
821 request = (MainThreadRequest) msg.obj;
822 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800823 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800824 break;
825
826 case EVENT_NV_WRITE_CDMA_PRL_DONE:
827 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
828 break;
829
chen xu6dac5ab2018-10-26 17:39:23 -0700830 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800831 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700832 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800833 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800834 break;
835
chen xu6dac5ab2018-10-26 17:39:23 -0700836 case EVENT_RESET_MODEM_CONFIG_DONE:
837 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800838 break;
839
Sooraj Sasindran37444802020-08-11 10:40:43 -0700840 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
841 request = (MainThreadRequest) msg.obj;
842 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
843 request);
844 Phone phone = getPhoneFromRequest(request);
845 if (phone != null) {
846 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
847 } else {
848 loge("isNRDualConnectivityEnabled: No phone object");
849 request.result = false;
850 notifyRequester(request);
851 }
852 break;
853 }
854
855 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
856 ar = (AsyncResult) msg.obj;
857 request = (MainThreadRequest) ar.userObj;
858 if (ar.exception == null && ar.result != null) {
859 request.result = ar.result;
860 } else {
861 // request.result must be set to something non-null
862 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700863 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700864 request.result = ar.result;
865 } else {
866 request.result = false;
867 }
868 if (ar.result == null) {
869 loge("isNRDualConnectivityEnabled: Empty response");
870 } else if (ar.exception instanceof CommandException) {
871 loge("isNRDualConnectivityEnabled: CommandException: "
872 + ar.exception);
873 } else {
874 loge("isNRDualConnectivityEnabled: Unknown exception");
875 }
876 }
877 notifyRequester(request);
878 break;
879
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700880 case CMD_IS_VONR_ENABLED: {
881 request = (MainThreadRequest) msg.obj;
882 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
883 request);
884 Phone phone = getPhoneFromRequest(request);
885 if (phone != null) {
886 phone.isVoNrEnabled(onCompleted, request.workSource);
887 } else {
888 loge("isVoNrEnabled: No phone object");
889 request.result = false;
890 notifyRequester(request);
891 }
892 break;
893 }
894
895 case EVENT_IS_VONR_ENABLED_DONE:
896 ar = (AsyncResult) msg.obj;
897 request = (MainThreadRequest) ar.userObj;
898 if (ar.exception == null && ar.result != null) {
899 request.result = ar.result;
900 } else {
901 // request.result must be set to something non-null
902 // for the calling thread to unblock
903 if (ar.result != null) {
904 request.result = ar.result;
905 } else {
906 request.result = false;
907 }
908 if (ar.result == null) {
909 loge("isVoNrEnabled: Empty response");
910 } else if (ar.exception instanceof CommandException) {
911 loge("isVoNrEnabled: CommandException: "
912 + ar.exception);
913 } else {
914 loge("isVoNrEnabled: Unknown exception");
915 }
916 }
917 notifyRequester(request);
918 break;
919
Sooraj Sasindran37444802020-08-11 10:40:43 -0700920 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
921 request = (MainThreadRequest) msg.obj;
922 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
923 Phone phone = getPhoneFromRequest(request);
924 if (phone != null) {
925 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
926 request.workSource);
927 } else {
928 loge("enableNrDualConnectivity: No phone object");
929 request.result =
930 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
931 notifyRequester(request);
932 }
933 break;
934 }
935
936 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
937 ar = (AsyncResult) msg.obj;
938 request = (MainThreadRequest) ar.userObj;
939 if (ar.exception == null) {
940 request.result =
941 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
942 } else {
943 request.result =
944 TelephonyManager
945 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
946 if (ar.exception instanceof CommandException) {
947 CommandException.Error error =
948 ((CommandException) (ar.exception)).getCommandError();
949 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
950 request.result =
951 TelephonyManager
952 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000953 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
954 request.result =
955 TelephonyManager
956 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700957 }
958 loge("enableNrDualConnectivity" + ": CommandException: "
959 + ar.exception);
960 } else {
961 loge("enableNrDualConnectivity" + ": Unknown exception");
962 }
963 }
964 notifyRequester(request);
965 break;
966 }
967
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700968 case CMD_ENABLE_VONR: {
969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
971 Phone phone = getPhoneFromRequest(request);
972 if (phone != null) {
973 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
974 request.workSource);
975 } else {
976 loge("setVoNrEnabled: No phone object");
977 request.result =
978 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
979 notifyRequester(request);
980 }
981 break;
982 }
983
984 case EVENT_ENABLE_VONR_DONE: {
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception == null) {
988 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
989 } else {
990 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
991 if (ar.exception instanceof CommandException) {
992 CommandException.Error error =
993 ((CommandException) (ar.exception)).getCommandError();
994 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
995 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
996 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
997 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
998 } else {
999 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1000 }
1001 loge("setVoNrEnabled" + ": CommandException: "
1002 + ar.exception);
1003 } else {
1004 loge("setVoNrEnabled" + ": Unknown exception");
1005 }
1006 }
1007 notifyRequester(request);
1008 break;
1009 }
1010
SongFerngWang3ef3e072020-12-21 16:41:52 +08001011 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001012 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001013 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1014 request);
1015 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001016 break;
1017
SongFerngWang3ef3e072020-12-21 16:41:52 +08001018 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001019 ar = (AsyncResult) msg.obj;
1020 request = (MainThreadRequest) ar.userObj;
1021 if (ar.exception == null && ar.result != null) {
1022 request.result = ar.result; // Integer
1023 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301024 // request.result must be set to something non-null
1025 // for the calling thread to unblock
1026 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001027 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001028 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001029 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001030 loge("getAllowedNetworkTypesBitmask: CommandException: "
1031 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001032 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001033 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001034 }
1035 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001036 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001037 break;
1038
SongFerngWang3ef3e072020-12-21 16:41:52 +08001039 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001040 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001041 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1042 request);
1043 Pair<Integer, Long> reasonWithNetworkTypes =
1044 (Pair<Integer, Long>) request.argument;
1045 getPhoneFromRequest(request).setAllowedNetworkTypes(
1046 reasonWithNetworkTypes.first,
1047 reasonWithNetworkTypes.second,
1048 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001049 break;
1050
SongFerngWang3ef3e072020-12-21 16:41:52 +08001051 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1052 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001053 break;
1054
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001055 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1056 request = (MainThreadRequest)msg.obj;
1057 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001058 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001059 break;
1060
1061 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1062 ar = (AsyncResult)msg.obj;
1063 request = (MainThreadRequest)ar.userObj;
1064 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001065 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001066 break;
1067
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001068 case CMD_SET_VOICEMAIL_NUMBER:
1069 request = (MainThreadRequest) msg.obj;
1070 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1071 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001072 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1073 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001074 break;
1075
1076 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1077 handleNullReturnEvent(msg, "setVoicemailNumber");
1078 break;
1079
Stuart Scott54788802015-03-30 13:18:01 -07001080 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1081 request = (MainThreadRequest) msg.obj;
1082 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1083 request);
1084 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1085 break;
1086
1087 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1088 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1089 break;
1090
Shishir Agrawal302c8692015-06-19 13:49:39 -07001091 case CMD_PERFORM_NETWORK_SCAN:
1092 request = (MainThreadRequest) msg.obj;
1093 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1094 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1095 break;
1096
Hall Liu27d24262020-09-18 19:04:59 -07001097 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001098 request = (MainThreadRequest) msg.obj;
1099 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001100 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1101 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1102 request.argument;
1103 int callForwardingReason = args.first;
1104 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001105 break;
Hall Liu27d24262020-09-18 19:04:59 -07001106 }
1107 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001108 ar = (AsyncResult) msg.obj;
1109 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001110 TelephonyManager.CallForwardingInfoCallback callback =
1111 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1112 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001113 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001114 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001115 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1116 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1117 // Service Class is a bit mask per 3gpp 27.007. Search for
1118 // any service for voice call.
1119 if ((callForwardInfo.serviceClass
1120 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001121 callForwardingInfo = new CallForwardingInfo(
1122 callForwardInfo.status
1123 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001124 callForwardInfo.reason,
1125 callForwardInfo.number,
1126 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001127 break;
1128 }
1129 }
1130 // Didn't find a call forward info for voice call.
1131 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001132 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1133 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001134 }
Hall Liu27d24262020-09-18 19:04:59 -07001135 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001136 } else {
1137 if (ar.result == null) {
1138 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1139 }
1140 if (ar.exception != null) {
1141 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1142 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001143 int errorCode = TelephonyManager
1144 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001145 if (ar.exception instanceof CommandException) {
1146 CommandException.Error error =
1147 ((CommandException) (ar.exception)).getCommandError();
1148 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001149 errorCode = TelephonyManager
1150 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001151 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001152 errorCode = TelephonyManager
1153 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001154 }
1155 }
Hall Liu27d24262020-09-18 19:04:59 -07001156 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001157 }
Shuo Qian4a594052020-01-23 11:59:30 -08001158 break;
Hall Liu27d24262020-09-18 19:04:59 -07001159 }
Shuo Qian4a594052020-01-23 11:59:30 -08001160
Hall Liu27d24262020-09-18 19:04:59 -07001161 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001162 request = (MainThreadRequest) msg.obj;
1163 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001164 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001165 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001166 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1167 request.argument).first;
1168 request.phone.setCallForwardingOption(
1169 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001170 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001171 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001172 callForwardingInfoToSet.getReason(),
1173 callForwardingInfoToSet.getNumber(),
1174 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1175 break;
Hall Liu27d24262020-09-18 19:04:59 -07001176 }
Shuo Qian4a594052020-01-23 11:59:30 -08001177
Hall Liu27d24262020-09-18 19:04:59 -07001178 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001179 ar = (AsyncResult) msg.obj;
1180 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001181 Consumer<Integer> callback =
1182 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1183 request.argument).second;
1184 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001185 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001186 int errorCode = TelephonyManager.CallForwardingInfoCallback
1187 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001188 if (ar.exception instanceof CommandException) {
1189 CommandException.Error error =
1190 ((CommandException) (ar.exception)).getCommandError();
1191 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001192 errorCode = TelephonyManager.CallForwardingInfoCallback
1193 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001194 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001195 errorCode = TelephonyManager.CallForwardingInfoCallback
1196 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001197 }
1198 }
1199 callback.accept(errorCode);
1200 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001201 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001202 }
Shuo Qian4a594052020-01-23 11:59:30 -08001203 break;
Hall Liu27d24262020-09-18 19:04:59 -07001204 }
Shuo Qian4a594052020-01-23 11:59:30 -08001205
Hall Liu27d24262020-09-18 19:04:59 -07001206 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001207 request = (MainThreadRequest) msg.obj;
1208 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1209 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1210 break;
Hall Liu27d24262020-09-18 19:04:59 -07001211 }
Shuo Qian4a594052020-01-23 11:59:30 -08001212
Hall Liu27d24262020-09-18 19:04:59 -07001213 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001214 ar = (AsyncResult) msg.obj;
1215 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001216 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001217 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1218 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001219 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001220 // Service Class is a bit mask per 3gpp 27.007.
1221 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001222 if (callForwardResults.length > 1
1223 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001224 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001225 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001226 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1227 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001228 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001229 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001230 }
1231 } else {
1232 if (ar.result == null) {
1233 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1234 }
1235 if (ar.exception != null) {
1236 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1237 }
1238 if (ar.exception instanceof CommandException) {
1239 CommandException.Error error =
1240 ((CommandException) (ar.exception)).getCommandError();
1241 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1242 callForwardingStatus =
1243 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1244 }
1245 }
1246 }
Hall Liu27d24262020-09-18 19:04:59 -07001247 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001248 break;
Hall Liu27d24262020-09-18 19:04:59 -07001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250
Hall Liu27d24262020-09-18 19:04:59 -07001251 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001252 request = (MainThreadRequest) msg.obj;
1253 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001254 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1255 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001256 break;
Hall Liu27d24262020-09-18 19:04:59 -07001257 }
Shuo Qian4a594052020-01-23 11:59:30 -08001258
Hall Liu27d24262020-09-18 19:04:59 -07001259 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001260 ar = (AsyncResult) msg.obj;
1261 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001262 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1263 Consumer<Integer> callback =
1264 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1265 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001266 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001267 if (ar.exception instanceof CommandException) {
1268 CommandException.Error error =
1269 ((CommandException) (ar.exception)).getCommandError();
1270 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1271 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1272 } else {
1273 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1274 }
1275 } else {
1276 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1277 }
1278 } else {
1279 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1280 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001281 }
Shuo Qian4a594052020-01-23 11:59:30 -08001282 break;
Hall Liu27d24262020-09-18 19:04:59 -07001283 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001284 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1285 ar = (AsyncResult) msg.obj;
1286 request = (MainThreadRequest) ar.userObj;
1287 CellNetworkScanResult cellScanResult;
1288 if (ar.exception == null && ar.result != null) {
1289 cellScanResult = new CellNetworkScanResult(
1290 CellNetworkScanResult.STATUS_SUCCESS,
1291 (List<OperatorInfo>) ar.result);
1292 } else {
1293 if (ar.result == null) {
1294 loge("getCellNetworkScanResults: Empty response");
1295 }
1296 if (ar.exception != null) {
1297 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1298 }
1299 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1300 if (ar.exception instanceof CommandException) {
1301 CommandException.Error error =
1302 ((CommandException) (ar.exception)).getCommandError();
1303 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1304 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1305 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1306 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1307 }
1308 }
1309 cellScanResult = new CellNetworkScanResult(errorCode, null);
1310 }
1311 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001312 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001313 break;
1314
1315 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1316 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001317 ManualNetworkSelectionArgument selArg =
1318 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001319 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1320 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001321 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1322 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001323 break;
1324
1325 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001326 ar = (AsyncResult) msg.obj;
1327 request = (MainThreadRequest) ar.userObj;
1328 if (ar.exception == null) {
1329 request.result = true;
1330 } else {
1331 request.result = false;
1332 loge("setNetworkSelectionModeManual " + ar.exception);
1333 }
1334 notifyRequester(request);
1335 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001336 break;
1337
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001338 case CMD_GET_MODEM_ACTIVITY_INFO:
1339 request = (MainThreadRequest) msg.obj;
1340 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001341 if (defaultPhone != null) {
1342 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001343 } else {
1344 ResultReceiver result = (ResultReceiver) request.argument;
1345 Bundle bundle = new Bundle();
1346 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001347 new ModemActivityInfo(0, 0, 0,
1348 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001349 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001350 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001351 break;
1352
Hall Liud0f208c2020-10-14 16:54:44 -07001353 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001354 ar = (AsyncResult) msg.obj;
1355 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001356 ResultReceiver result = (ResultReceiver) request.argument;
1357
Hall Liud0f208c2020-10-14 16:54:44 -07001358 ModemActivityInfo ret = null;
1359 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001360 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001361 // Update the last modem activity info and the result of the request.
1362 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1363 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001364 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001365 int[] txTimeMs = info.getTransmitTimeMillis();
1366 int[] lastModemTxTimeMs = mLastModemActivityInfo
1367 .getTransmitTimeMillis();
1368 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1369 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1370 }
Hall Liu49656c02020-10-09 19:00:11 -07001371 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001372 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1373 + mLastModemActivityInfo.getSleepTimeMillis());
1374 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1375 + mLastModemActivityInfo.getIdleTimeMillis());
1376 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1377 mLastModemActivityInfo.setReceiveTimeMillis(
1378 info.getReceiveTimeMillis()
1379 + mLastModemActivityInfo.getReceiveTimeMillis());
1380 }
Hall Liu49656c02020-10-09 19:00:11 -07001381 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001382 mLastModemActivityInfo.getSleepTimeMillis(),
1383 mLastModemActivityInfo.getIdleTimeMillis(),
1384 mLastModemActivityInfo.getTransmitTimeMillis(),
1385 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001386 } else {
1387 if (ar.result == null) {
1388 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001389 error = TelephonyManager.ModemActivityInfoException
1390 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001391 } else if (ar.exception instanceof CommandException) {
1392 loge("queryModemActivityInfo: CommandException: " +
1393 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001394 error = TelephonyManager.ModemActivityInfoException
1395 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001396 } else {
1397 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001398 error = TelephonyManager.ModemActivityInfoException
1399 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001400 }
1401 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001402 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001403 if (ret != null) {
1404 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1405 } else {
1406 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1407 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001408 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001409 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001410 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001411 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001412
Meng Wang1a7c35a2016-05-05 20:56:15 -07001413 case CMD_SET_ALLOWED_CARRIERS:
1414 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001415 CarrierRestrictionRules argument =
1416 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001417 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001418 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001419 break;
1420
1421 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1422 ar = (AsyncResult) msg.obj;
1423 request = (MainThreadRequest) ar.userObj;
1424 if (ar.exception == null && ar.result != null) {
1425 request.result = ar.result;
1426 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001427 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1428 if (ar.exception instanceof CommandException) {
1429 loge("setAllowedCarriers: CommandException: " + ar.exception);
1430 CommandException.Error error =
1431 ((CommandException) (ar.exception)).getCommandError();
1432 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1433 request.result =
1434 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1435 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001436 } else {
1437 loge("setAllowedCarriers: Unknown exception");
1438 }
1439 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001440 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001441 break;
1442
1443 case CMD_GET_ALLOWED_CARRIERS:
1444 request = (MainThreadRequest) msg.obj;
1445 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001446 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001447 break;
1448
1449 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
1452 if (ar.exception == null && ar.result != null) {
1453 request.result = ar.result;
1454 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001455 request.result = new IllegalStateException(
1456 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001457 if (ar.result == null) {
1458 loge("getAllowedCarriers: Empty response");
1459 } else if (ar.exception instanceof CommandException) {
1460 loge("getAllowedCarriers: CommandException: " +
1461 ar.exception);
1462 } else {
1463 loge("getAllowedCarriers: Unknown exception");
1464 }
1465 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001466 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001467 break;
1468
Nathan Haroldb3014052017-01-25 15:57:32 -08001469 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1470 ar = (AsyncResult) msg.obj;
1471 request = (MainThreadRequest) ar.userObj;
1472 if (ar.exception == null && ar.result != null) {
1473 request.result = ar.result;
1474 } else {
1475 request.result = new IllegalArgumentException(
1476 "Failed to retrieve Forbidden Plmns");
1477 if (ar.result == null) {
1478 loge("getForbiddenPlmns: Empty response");
1479 } else {
1480 loge("getForbiddenPlmns: Unknown exception");
1481 }
1482 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001483 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001484 break;
1485
1486 case CMD_GET_FORBIDDEN_PLMNS:
1487 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001488 uiccPort = getUiccPortFromRequest(request);
1489 if (uiccPort == null) {
1490 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001491 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001492 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001493 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001494 break;
1495 }
1496 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001497 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001498 if (uiccApp == null) {
1499 loge("getForbiddenPlmns() no app with specified type -- "
1500 + appType);
1501 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001502 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001503 break;
1504 } else {
1505 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1506 + " specified type -- " + appType);
1507 }
1508 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1509 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1510 onCompleted);
1511 break;
1512
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001513 case CMD_SWITCH_SLOTS:
1514 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001515 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001516 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001517 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001518 break;
1519
1520 case EVENT_SWITCH_SLOTS_DONE:
1521 ar = (AsyncResult) msg.obj;
1522 request = (MainThreadRequest) ar.userObj;
1523 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001524 notifyRequester(request);
1525 break;
1526 case CMD_GET_NETWORK_SELECTION_MODE:
1527 request = (MainThreadRequest) msg.obj;
1528 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1529 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1530 break;
1531
1532 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1533 ar = (AsyncResult) msg.obj;
1534 request = (MainThreadRequest) ar.userObj;
1535 if (ar.exception != null) {
1536 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1537 } else {
1538 int mode = ((int[]) ar.result)[0];
1539 if (mode == 0) {
1540 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1541 } else {
1542 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1543 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001544 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001545 notifyRequester(request);
1546 break;
1547 case CMD_GET_CDMA_ROAMING_MODE:
1548 request = (MainThreadRequest) msg.obj;
1549 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1550 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1551 break;
1552 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1553 ar = (AsyncResult) msg.obj;
1554 request = (MainThreadRequest) ar.userObj;
1555 if (ar.exception != null) {
1556 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1557 } else {
1558 request.result = ((int[]) ar.result)[0];
1559 }
1560 notifyRequester(request);
1561 break;
1562 case CMD_SET_CDMA_ROAMING_MODE:
1563 request = (MainThreadRequest) msg.obj;
1564 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1565 int mode = (int) request.argument;
1566 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1567 break;
1568 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1569 ar = (AsyncResult) msg.obj;
1570 request = (MainThreadRequest) ar.userObj;
1571 request.result = ar.exception == null;
1572 notifyRequester(request);
1573 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001574 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1575 request = (MainThreadRequest) msg.obj;
1576 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1577 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1578 break;
1579 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1580 ar = (AsyncResult) msg.obj;
1581 request = (MainThreadRequest) ar.userObj;
1582 if (ar.exception != null) {
1583 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1584 } else {
1585 request.result = ((int[]) ar.result)[0];
1586 }
1587 notifyRequester(request);
1588 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001589 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1590 request = (MainThreadRequest) msg.obj;
1591 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1592 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001593 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1594 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001595 break;
1596 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1597 ar = (AsyncResult) msg.obj;
1598 request = (MainThreadRequest) ar.userObj;
1599 request.result = ar.exception == null;
1600 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001601 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001602 case CMD_GET_ALL_CELL_INFO:
1603 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001604 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001605 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001606 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001607 case EVENT_GET_ALL_CELL_INFO_DONE:
1608 ar = (AsyncResult) msg.obj;
1609 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001610 // If a timeout occurs, the response will be null
1611 request.result = (ar.exception == null && ar.result != null)
1612 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001613 synchronized (request) {
1614 request.notifyAll();
1615 }
1616 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001617 case CMD_REQUEST_CELL_INFO_UPDATE:
1618 request = (MainThreadRequest) msg.obj;
1619 request.phone.requestCellInfoUpdate(request.workSource,
1620 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1621 break;
1622 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1623 ar = (AsyncResult) msg.obj;
1624 request = (MainThreadRequest) ar.userObj;
1625 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1626 try {
1627 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001628 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001629 cb.onError(
1630 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1631 ar.exception.getClass().getName(),
1632 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001633 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001634 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001635 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001636 } else {
1637 // use the result as returned
1638 cb.onCellInfo((List<CellInfo>) ar.result);
1639 }
1640 } catch (RemoteException re) {
1641 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1642 }
1643 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001644 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001645 request = (MainThreadRequest) msg.obj;
1646 WorkSource ws = (WorkSource) request.argument;
1647 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001648 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001649 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001650 }
1651 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001652 ar = (AsyncResult) msg.obj;
1653 request = (MainThreadRequest) ar.userObj;
1654 if (ar.exception == null) {
1655 request.result = ar.result;
1656 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001657 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001659 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001660 }
1661
1662 synchronized (request) {
1663 request.notifyAll();
1664 }
1665 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001666 }
chen xu6dac5ab2018-10-26 17:39:23 -07001667 case CMD_MODEM_REBOOT:
1668 request = (MainThreadRequest) msg.obj;
1669 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001670 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001671 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001672 case EVENT_CMD_MODEM_REBOOT_DONE:
1673 handleNullReturnEvent(msg, "rebootModem");
1674 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001675 case CMD_REQUEST_ENABLE_MODEM:
1676 request = (MainThreadRequest) msg.obj;
1677 boolean enable = (boolean) request.argument;
1678 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001679 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001680 PhoneConfigurationManager.getInstance()
1681 .enablePhone(request.phone, enable, onCompleted);
1682 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001683 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001684 ar = (AsyncResult) msg.obj;
1685 request = (MainThreadRequest) ar.userObj;
1686 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001687 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001688 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001689 if ((boolean) request.result) {
1690 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1691 updateModemStateMetrics();
1692 } else {
1693 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1694 + ar.exception);
1695 }
1696 notifyRequester(request);
1697 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001698 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001699 case CMD_GET_MODEM_STATUS:
1700 request = (MainThreadRequest) msg.obj;
1701 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1702 PhoneConfigurationManager.getInstance()
1703 .getPhoneStatusFromModem(request.phone, onCompleted);
1704 break;
1705 case EVENT_GET_MODEM_STATUS_DONE:
1706 ar = (AsyncResult) msg.obj;
1707 request = (MainThreadRequest) ar.userObj;
1708 int id = request.phone.getPhoneId();
1709 if (ar.exception == null && ar.result != null) {
1710 request.result = ar.result;
1711 //update the cache as modem status has changed
1712 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1713 (boolean) request.result);
1714 } else {
1715 // Return true if modem status cannot be retrieved. For most cases,
1716 // modem status is on. And for older version modems, GET_MODEM_STATUS
1717 // and disable modem are not supported. Modem is always on.
1718 // TODO: this should be fixed in R to support a third
1719 // status UNKNOWN b/131631629
1720 request.result = true;
1721 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1722 + ar.exception);
1723 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001724 notifyRequester(request);
1725 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001726 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1727 request = (MainThreadRequest) msg.obj;
1728 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1729 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1730 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1731 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1732 break;
1733 }
1734 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1735 ar = (AsyncResult) msg.obj;
1736 request = (MainThreadRequest) ar.userObj;
1737 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1738 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1739 args.second.accept(ar.exception == null);
1740 notifyRequester(request);
1741 break;
1742 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001743 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1744 request = (MainThreadRequest) msg.obj;
1745 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1746 Phone phone = getPhoneFromRequest(request);
1747 if (phone != null) {
1748 phone.getSystemSelectionChannels(onCompleted);
1749 } else {
1750 loge("getSystemSelectionChannels: No phone object");
1751 request.result = new ArrayList<RadioAccessSpecifier>();
1752 notifyRequester(request);
1753 }
1754 break;
1755 }
1756 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1757 ar = (AsyncResult) msg.obj;
1758 request = (MainThreadRequest) ar.userObj;
1759 if (ar.exception == null && ar.result != null) {
1760 request.result = ar.result;
1761 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001762 request.result = new IllegalStateException(
1763 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001764 if (ar.result == null) {
1765 loge("getSystemSelectionChannels: Empty response");
1766 } else {
1767 loge("getSystemSelectionChannels: Unknown exception");
1768 }
1769 }
1770 notifyRequester(request);
1771 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001772 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1773 ar = (AsyncResult) msg.obj;
1774 request = (MainThreadRequest) ar.userObj;
1775 if (ar.exception == null && ar.result != null) {
1776 request.result = ar.result;
1777 } else {
1778 request.result = -1;
1779 loge("Failed to set Forbidden Plmns");
1780 if (ar.result == null) {
1781 loge("setForbidenPlmns: Empty response");
1782 } else if (ar.exception != null) {
1783 loge("setForbiddenPlmns: Exception: " + ar.exception);
1784 request.result = -1;
1785 } else {
1786 loge("setForbiddenPlmns: Unknown exception");
1787 }
1788 }
1789 notifyRequester(request);
1790 break;
1791 case CMD_SET_FORBIDDEN_PLMNS:
1792 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001793 uiccPort = getUiccPortFromRequest(request);
1794 if (uiccPort == null) {
1795 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001796 request.result = -1;
1797 notifyRequester(request);
1798 break;
1799 }
1800 Pair<Integer, List<String>> setFplmnsArgs =
1801 (Pair<Integer, List<String>>) request.argument;
1802 appType = setFplmnsArgs.first;
1803 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001804 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001805 if (uiccApp == null) {
1806 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1807 request.result = -1;
1808 loge("Failed to get UICC App");
1809 notifyRequester(request);
1810 } else {
1811 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1812 ((SIMRecords) uiccApp.getIccRecords())
1813 .setForbiddenPlmns(onCompleted, fplmns);
1814 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001815 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001816 case CMD_ERASE_MODEM_CONFIG:
1817 request = (MainThreadRequest) msg.obj;
1818 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1819 defaultPhone.eraseModemConfig(onCompleted);
1820 break;
1821 case EVENT_ERASE_MODEM_CONFIG_DONE:
1822 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001823 break;
zoey chene02881a2019-12-30 16:11:23 +08001824
Kai Shif70f46f2021-03-03 13:59:46 -08001825 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1826 request = (MainThreadRequest) msg.obj;
1827 request.result = defaultPhone.eraseDataInSharedPreferences();
1828 notifyRequester(request);
1829 break;
1830
zoey chene02881a2019-12-30 16:11:23 +08001831 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1832 request = (MainThreadRequest) msg.obj;
1833 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1834 Pair<String, String> changed = (Pair<String, String>) request.argument;
1835 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1836 changed.first, changed.second, onCompleted);
1837 break;
1838 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1839 ar = (AsyncResult) msg.obj;
1840 request = (MainThreadRequest) ar.userObj;
1841 if (ar.exception == null) {
1842 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001843 // If the operation is successful, update the PIN storage
1844 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1845 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001846 UiccController.getInstance().getPinStorage()
1847 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001848 } else {
1849 request.result = msg.arg1;
1850 }
1851 notifyRequester(request);
1852 break;
1853
Michele Berionne5e411512020-11-13 02:36:59 +00001854 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001855 request = (MainThreadRequest) msg.obj;
1856 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1857 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1858 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1859 enabled.first, enabled.second, onCompleted);
1860 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001861 }
zoey chene02881a2019-12-30 16:11:23 +08001862 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1863 ar = (AsyncResult) msg.obj;
1864 request = (MainThreadRequest) ar.userObj;
1865 if (ar.exception == null) {
1866 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001867 // If the operation is successful, update the PIN storage
1868 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1869 int phoneId = getPhoneFromRequest(request).getPhoneId();
1870 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001871 UiccController.getInstance().getPinStorage()
1872 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001873 } else {
1874 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1875 }
zoey chene02881a2019-12-30 16:11:23 +08001876 } else {
1877 request.result = msg.arg1;
1878 }
Michele Berionne5e411512020-11-13 02:36:59 +00001879
1880
zoey chene02881a2019-12-30 16:11:23 +08001881 notifyRequester(request);
1882 break;
1883
Peter Wangdafb9ac2020-01-15 14:13:38 -08001884 case MSG_NOTIFY_USER_ACTIVITY:
1885 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001886 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001887 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1888 getDefaultPhone().getContext().sendBroadcastAsUser(
1889 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1890 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001891
1892 case CMD_SET_DATA_THROTTLING: {
1893 request = (MainThreadRequest) msg.obj;
1894 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1895 DataThrottlingRequest dataThrottlingRequest =
1896 (DataThrottlingRequest) request.argument;
1897 Phone phone = getPhoneFromRequest(request);
1898 if (phone != null) {
1899 phone.setDataThrottling(onCompleted,
1900 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1901 dataThrottlingRequest.getCompletionDurationMillis());
1902 } else {
1903 loge("setDataThrottling: No phone object");
1904 request.result =
1905 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1906 notifyRequester(request);
1907 }
1908
1909 break;
1910 }
1911 case EVENT_SET_DATA_THROTTLING_DONE:
1912 ar = (AsyncResult) msg.obj;
1913 request = (MainThreadRequest) ar.userObj;
1914
1915 if (ar.exception == null) {
1916 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1917 } else if (ar.exception instanceof CommandException) {
1918 loge("setDataThrottling: CommandException: " + ar.exception);
1919 CommandException.Error error =
1920 ((CommandException) (ar.exception)).getCommandError();
1921
1922 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1923 request.result = TelephonyManager
1924 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1925 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1926 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001927 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1928 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001929 } else {
1930 request.result =
1931 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1932 }
1933 } else {
1934 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1935 }
1936 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1937 notifyRequester(request);
1938 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001939
1940 case CMD_SET_SIM_POWER: {
1941 request = (MainThreadRequest) msg.obj;
1942 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1943 request = (MainThreadRequest) msg.obj;
1944 int stateToSet =
1945 ((Pair<Integer, IIntegerConsumer>)
1946 request.argument).first;
1947 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1948 break;
1949 }
1950 case EVENT_SET_SIM_POWER_DONE: {
1951 ar = (AsyncResult) msg.obj;
1952 request = (MainThreadRequest) ar.userObj;
1953 IIntegerConsumer callback =
1954 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1955 if (ar.exception != null) {
1956 loge("setSimPower exception: " + ar.exception);
1957 int errorCode = TelephonyManager.CallForwardingInfoCallback
1958 .RESULT_ERROR_UNKNOWN;
1959 if (ar.exception instanceof CommandException) {
1960 CommandException.Error error =
1961 ((CommandException) (ar.exception)).getCommandError();
1962 if (error == CommandException.Error.SIM_ERR) {
1963 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1964 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1965 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1966 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1967 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1968 } else {
1969 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1970 }
1971 }
1972 try {
1973 callback.accept(errorCode);
1974 } catch (RemoteException e) {
1975 // Ignore if the remote process is no longer available to call back.
1976 Log.w(LOG_TAG, "setSimPower: callback not available.");
1977 }
1978 } else {
1979 try {
1980 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1981 } catch (RemoteException e) {
1982 // Ignore if the remote process is no longer available to call back.
1983 Log.w(LOG_TAG, "setSimPower: callback not available.");
1984 }
1985 }
1986 break;
1987 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001988 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1989 request = (MainThreadRequest) msg.obj;
1990
1991 final Phone phone = getPhoneFromRequest(request);
1992 if (phone == null || phone.getServiceStateTracker() == null) {
1993 request.result = new IllegalStateException("Phone or SST is null");
1994 notifyRequester(request);
1995 break;
1996 }
1997
1998 Pair<Integer, SignalStrengthUpdateRequest> pair =
1999 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2000 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2001 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002002 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002003 request.subId, pair.first /*callingUid*/,
2004 pair.second /*request*/, onCompleted);
2005 break;
2006 }
2007 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2008 ar = (AsyncResult) msg.obj;
2009 request = (MainThreadRequest) ar.userObj;
2010 // request.result will be the exception of ar if present, true otherwise.
2011 // Be cautious not to leave result null which will wait() forever
2012 request.result = ar.exception != null ? ar.exception : true;
2013 notifyRequester(request);
2014 break;
2015 }
2016 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2017 request = (MainThreadRequest) msg.obj;
2018
2019 Phone phone = getPhoneFromRequest(request);
2020 if (phone == null || phone.getServiceStateTracker() == null) {
2021 request.result = new IllegalStateException("Phone or SST is null");
2022 notifyRequester(request);
2023 break;
2024 }
2025
2026 Pair<Integer, SignalStrengthUpdateRequest> pair =
2027 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2028 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2029 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002030 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002031 request.subId, pair.first /*callingUid*/,
2032 pair.second /*request*/, onCompleted);
2033 break;
2034 }
2035 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2036 ar = (AsyncResult) msg.obj;
2037 request = (MainThreadRequest) ar.userObj;
2038 request.result = ar.exception != null ? ar.exception : true;
2039 notifyRequester(request);
2040 break;
2041 }
Jordan Liu109698e2020-11-24 14:50:34 -08002042
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002043 case CMD_GET_SLICING_CONFIG: {
2044 request = (MainThreadRequest) msg.obj;
2045 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2046 request.phone.getSlicingConfig(onCompleted);
2047 break;
2048 }
2049 case EVENT_GET_SLICING_CONFIG_DONE: {
2050 ar = (AsyncResult) msg.obj;
2051 request = (MainThreadRequest) ar.userObj;
2052 ResultReceiver result = (ResultReceiver) request.argument;
2053
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002054 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002055 Bundle bundle = new Bundle();
2056 int resultCode = 0;
2057 if (ar.exception != null) {
2058 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2059 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002060 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002061 } else if (ar.result == null) {
2062 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002063 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002064 } else {
2065 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002066 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2067 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002068 }
2069
2070 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002071 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002072 }
2073 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2074 result.send(resultCode, bundle);
2075 notifyRequester(request);
2076 break;
2077 }
2078
Michele Berionne5e411512020-11-13 02:36:59 +00002079 case CMD_PREPARE_UNATTENDED_REBOOT:
2080 request = (MainThreadRequest) msg.obj;
2081 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002082 UiccController.getInstance().getPinStorage()
2083 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002084 notifyRequester(request);
2085 break;
2086
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 default:
2088 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2089 break;
2090 }
2091 }
Jake Hambye994d462014-02-03 13:10:13 -08002092
Pengquan Menga1bb6272018-09-06 09:59:22 -07002093 private void notifyRequester(MainThreadRequest request) {
2094 synchronized (request) {
2095 request.notifyAll();
2096 }
2097 }
2098
Jake Hambye994d462014-02-03 13:10:13 -08002099 private void handleNullReturnEvent(Message msg, String command) {
2100 AsyncResult ar = (AsyncResult) msg.obj;
2101 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2102 if (ar.exception == null) {
2103 request.result = true;
2104 } else {
2105 request.result = false;
2106 if (ar.exception instanceof CommandException) {
2107 loge(command + ": CommandException: " + ar.exception);
2108 } else {
2109 loge(command + ": Unknown exception");
2110 }
2111 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002112 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 }
2115
2116 /**
2117 * Posts the specified command to be executed on the main thread,
2118 * waits for the request to complete, and returns the result.
2119 * @see #sendRequestAsync
2120 */
2121 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002122 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2123 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002124 }
2125
2126 /**
2127 * Posts the specified command to be executed on the main thread,
2128 * waits for the request to complete, and returns the result.
2129 * @see #sendRequestAsync
2130 */
2131 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2132 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002133 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002134 }
2135
2136 /**
2137 * Posts the specified command to be executed on the main thread,
2138 * waits for the request to complete, and returns the result.
2139 * @see #sendRequestAsync
2140 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002141 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002142 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2143 }
2144
2145 /**
2146 * Posts the specified command to be executed on the main thread,
2147 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2148 * if not timeout or null otherwise.
2149 * @see #sendRequestAsync
2150 */
2151 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2152 long timeoutInMs) {
2153 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002154 }
2155
2156 /**
2157 * Posts the specified command to be executed on the main thread,
2158 * waits for the request to complete, and returns the result.
2159 * @see #sendRequestAsync
2160 */
Nathan Harold92bed182018-10-12 18:16:49 -07002161 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002162 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002163 }
2164
2165 /**
2166 * Posts the specified command to be executed on the main thread,
2167 * waits for the request to complete, and returns the result.
2168 * @see #sendRequestAsync
2169 */
2170 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002171 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2172 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002173 }
2174
2175 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002176 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2177 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2178 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002179 * @see #sendRequestAsync
2180 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002181 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2182 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2184 throw new RuntimeException("This method will deadlock if called from the main thread.");
2185 }
2186
Nathan Harold92bed182018-10-12 18:16:49 -07002187 MainThreadRequest request = null;
2188 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2189 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2190 } else if (phone != null) {
2191 request = new MainThreadRequest(argument, phone, workSource);
2192 } else {
2193 request = new MainThreadRequest(argument, subId, workSource);
2194 }
2195
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 Message msg = mMainThreadHandler.obtainMessage(command, request);
2197 msg.sendToTarget();
2198
Rambo Wang0f050d82021-02-12 11:43:36 -08002199
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002201 if (timeoutInMs >= 0) {
2202 // Wait for at least timeoutInMs before returning null request result
2203 long now = SystemClock.elapsedRealtime();
2204 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002205 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002206 try {
2207 request.wait(deadline - now);
2208 } catch (InterruptedException e) {
2209 // Do nothing, go back and check if request is completed or timeout
2210 } finally {
2211 now = SystemClock.elapsedRealtime();
2212 }
2213 }
2214 } else {
2215 // Wait for the request to complete
2216 while (request.result == null) {
2217 try {
2218 request.wait();
2219 } catch (InterruptedException e) {
2220 // Do nothing, go back and wait until the request is complete
2221 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 }
2223 }
2224 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002225 if (request.result == null) {
2226 Log.wtf(LOG_TAG,
2227 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 return request.result;
2230 }
2231
2232 /**
2233 * Asynchronous ("fire and forget") version of sendRequest():
2234 * Posts the specified command to be executed on the main thread, and
2235 * returns immediately.
2236 * @see #sendRequest
2237 */
2238 private void sendRequestAsync(int command) {
2239 mMainThreadHandler.sendEmptyMessage(command);
2240 }
2241
2242 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002243 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002244 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002245 */
2246 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002247 sendRequestAsync(command, argument, null, null);
2248 }
2249
2250 /**
2251 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2252 * @see {@link #sendRequest(int,Object)}
2253 */
2254 private void sendRequestAsync(
2255 int command, Object argument, Phone phone, WorkSource workSource) {
2256 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002257 Message msg = mMainThreadHandler.obtainMessage(command, request);
2258 msg.sendToTarget();
2259 }
2260
2261 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 * Initialize the singleton PhoneInterfaceManager instance.
2263 * This is only done once, at startup, from PhoneApp.onCreate().
2264 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002265 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 synchronized (PhoneInterfaceManager.class) {
2267 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002268 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 } else {
2270 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2271 }
2272 return sInstance;
2273 }
2274 }
2275
2276 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002277 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002280 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002281 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002283 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002285 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002286 mTelephonySharedPreferences =
2287 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002288 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002289 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002290 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002291 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002292
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 publish();
2294 }
2295
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002296 private Phone getDefaultPhone() {
2297 Phone thePhone = getPhone(getDefaultSubscription());
2298 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2299 }
2300
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 private void publish() {
2302 if (DBG) log("publish: " + this);
2303
Peter Wangc035ce42020-01-08 21:00:22 -08002304 TelephonyFrameworkInitializer
2305 .getTelephonyServiceManager()
2306 .getTelephonyServiceRegisterer()
2307 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 }
2309
Stuart Scott584921c2015-01-15 17:10:34 -08002310 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002311 if (request.phone != null) {
2312 return request.phone;
2313 } else {
2314 return getPhoneFromSubId(request.subId);
2315 }
2316 }
2317
2318 private Phone getPhoneFromSubId(int subId) {
2319 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2320 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002321 }
2322
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002323 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002324 Phone phone = getPhoneFromRequest(request);
2325 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002326 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002327 }
2328
Wink Saville36469e72014-06-11 15:17:00 -07002329 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002330 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002331 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333
Kai Shif70f46f2021-03-03 13:59:46 -08002334 private void sendEraseModemConfig(@NonNull Phone phone) {
2335 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2336 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2337 }
2338
2339 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2340 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2341 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002342 }
2343
Peter Wang44b186e2020-01-13 23:33:09 -08002344 private boolean isImsAvailableOnDevice() {
2345 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2346 if (pm == null) {
2347 // For some reason package manger is not available.. This will fail internally anyway,
2348 // so do not throw error and allow.
2349 return true;
2350 }
2351 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2352 }
2353
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002355 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002356 }
2357
Wink Savilleb564aae2014-10-23 10:18:09 -07002358 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 if (DBG) log("dial: " + number);
2360 // No permission check needed here: This is just a wrapper around the
2361 // ACTION_DIAL intent, which is available to any app since it puts up
2362 // the UI before it does anything.
2363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002364 final long identity = Binder.clearCallingIdentity();
2365 try {
2366 String url = createTelUrl(number);
2367 if (url == null) {
2368 return;
2369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371 // PENDING: should we just silently fail if phone is offhook or ringing?
2372 PhoneConstants.State state = mCM.getState(subId);
2373 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2374 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2375 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2376 mApp.startActivity(intent);
2377 }
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 }
2381 }
2382
2383 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002384 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002385 }
2386
Wink Savilleb564aae2014-10-23 10:18:09 -07002387 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 if (DBG) log("call: " + number);
2389
2390 // This is just a wrapper around the ACTION_CALL intent, but we still
2391 // need to do a permission check since we're calling startActivity()
2392 // from the context of the phone app.
2393 enforceCallPermission();
2394
Jordan Liu1617b712019-07-10 15:06:26 -07002395 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 != AppOpsManager.MODE_ALLOWED) {
2397 return;
2398 }
2399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002400 final long identity = Binder.clearCallingIdentity();
2401 try {
2402 String url = createTelUrl(number);
2403 if (url == null) {
2404 return;
2405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002407 boolean isValid = false;
2408 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2409 if (slist != null) {
2410 for (SubscriptionInfo subInfoRecord : slist) {
2411 if (subInfoRecord.getSubscriptionId() == subId) {
2412 isValid = true;
2413 break;
2414 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002415 }
Wink Saville08874612014-08-31 19:19:58 -07002416 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417 if (!isValid) {
2418 return;
2419 }
Wink Saville08874612014-08-31 19:19:58 -07002420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002421 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2422 intent.putExtra(SUBSCRIPTION_KEY, subId);
2423 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2424 mApp.startActivity(intent);
2425 } finally {
2426 Binder.restoreCallingIdentity(identity);
2427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 }
2429
Wink Savilleb564aae2014-10-23 10:18:09 -07002430 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002431 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002432 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2433 }
2434
Wink Savilleb564aae2014-10-23 10:18:09 -07002435 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002436 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002437 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2438 }
2439
Wink Savilleb564aae2014-10-23 10:18:09 -07002440 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442
2443 final long identity = Binder.clearCallingIdentity();
2444 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002445 Phone phone = getPhone(subId);
2446 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002447 checkSimPin.start();
2448 return checkSimPin.unlockSim(null, pin);
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
2451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 }
2453
Wink Savilleb564aae2014-10-23 10:18:09 -07002454 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456
2457 final long identity = Binder.clearCallingIdentity();
2458 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002459 Phone phone = getPhone(subId);
2460 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002461 checkSimPuk.start();
2462 return checkSimPuk.unlockSim(puk, pin);
2463 } finally {
2464 Binder.restoreCallingIdentity(identity);
2465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 }
2467
2468 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002469 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 * a synchronous one.
2471 */
2472 private static class UnlockSim extends Thread {
2473
2474 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002475 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476
2477 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002478 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2479 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480
2481 // For replies from SimCard interface
2482 private Handler mHandler;
2483
2484 // For async handler to identify request type
2485 private static final int SUPPLY_PIN_COMPLETE = 100;
2486
Michele Berionne5e411512020-11-13 02:36:59 +00002487 UnlockSim(int phoneId, IccCard simCard) {
2488 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 mSimCard = simCard;
2490 }
2491
2492 @Override
2493 public void run() {
2494 Looper.prepare();
2495 synchronized (UnlockSim.this) {
2496 mHandler = new Handler() {
2497 @Override
2498 public void handleMessage(Message msg) {
2499 AsyncResult ar = (AsyncResult) msg.obj;
2500 switch (msg.what) {
2501 case SUPPLY_PIN_COMPLETE:
2502 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2503 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002504 mRetryCount = msg.arg1;
2505 if (ar.exception != null) {
2506 if (ar.exception instanceof CommandException &&
2507 ((CommandException)(ar.exception)).getCommandError()
2508 == CommandException.Error.PASSWORD_INCORRECT) {
2509 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002510 } //When UiccCardApp dispose,handle message and return exception
2511 else if (ar.exception instanceof CommandException &&
2512 ((CommandException) (ar.exception)).getCommandError()
2513 == CommandException.Error.ABORTED) {
2514 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002515 } else {
2516 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2517 }
2518 } else {
2519 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 mDone = true;
2522 UnlockSim.this.notifyAll();
2523 }
2524 break;
2525 }
2526 }
2527 };
2528 UnlockSim.this.notifyAll();
2529 }
2530 Looper.loop();
2531 }
2532
2533 /*
2534 * Use PIN or PUK to unlock SIM card
2535 *
2536 * If PUK is null, unlock SIM card with PIN
2537 *
2538 * If PUK is not null, unlock SIM card with PUK and set PIN code
2539 */
Wink Saville9de0f752013-10-22 19:04:03 -07002540 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541
2542 while (mHandler == null) {
2543 try {
2544 wait();
2545 } catch (InterruptedException e) {
2546 Thread.currentThread().interrupt();
2547 }
2548 }
2549 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2550
2551 if (puk == null) {
2552 mSimCard.supplyPin(pin, callback);
2553 } else {
2554 mSimCard.supplyPuk(puk, pin, callback);
2555 }
2556
2557 while (!mDone) {
2558 try {
2559 Log.d(LOG_TAG, "wait for done");
2560 wait();
2561 } catch (InterruptedException e) {
2562 // Restore the interrupted status
2563 Thread.currentThread().interrupt();
2564 }
2565 }
2566 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002567 int[] resultArray = new int[2];
2568 resultArray[0] = mResult;
2569 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002570
2571 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002572 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002573 }
2574
Wink Saville9de0f752013-10-22 19:04:03 -07002575 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 }
2577 }
2578
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002579 /**
2580 * This method has been removed due to privacy and stability concerns.
2581 */
2582 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002584 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2585 return;
Wink Saville36469e72014-06-11 15:17:00 -07002586 }
2587
Nathan Harold1f889d82020-06-04 17:05:26 -07002588 @Override
2589 public void updateServiceLocationWithPackageName(String callingPackage) {
2590 mApp.getSystemService(AppOpsManager.class)
2591 .checkPackage(Binder.getCallingUid(), callingPackage);
2592
Nathan Haroldf096d982020-11-18 17:18:06 -08002593 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002594 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2595 // Callers targeting S have no business invoking this method.
2596 return;
2597 }
2598
2599 LocationAccessPolicy.LocationPermissionResult locationResult =
2600 LocationAccessPolicy.checkLocationPermission(mApp,
2601 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2602 .setCallingPackage(callingPackage)
2603 .setCallingFeatureId(null)
2604 .setCallingPid(Binder.getCallingPid())
2605 .setCallingUid(Binder.getCallingUid())
2606 .setMethod("updateServiceLocation")
2607 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2608 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2609 .build());
2610 // Apps that lack location permission have no business calling this method;
2611 // however, because no permission was declared in the public API, denials must
2612 // all be "soft".
2613 switch (locationResult) {
2614 case DENIED_HARD: /* fall through */
2615 case DENIED_SOFT:
2616 return;
2617 }
2618
2619 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620 final long identity = Binder.clearCallingIdentity();
2621 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002622 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002624 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 }
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629 }
2630
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002631 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002632 @Override
2633 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002634 return isRadioOnWithFeature(callingPackage, null);
2635 }
2636
2637
2638 @Override
2639 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2640 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2641 callingFeatureId);
2642 }
2643
2644 @Deprecated
2645 @Override
2646 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2647 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002648 }
2649
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002650 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002651 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2652 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002653 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002654 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002655 return false;
2656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657
2658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 return isRadioOnForSubscriber(subId);
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002664 }
2665
2666 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 final Phone phone = getPhone(subId);
2670 if (phone != null) {
2671 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2672 } else {
2673 return false;
2674 }
2675 } finally {
2676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
2679
2680 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002681 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 }
Wink Saville36469e72014-06-11 15:17:00 -07002683
Wink Savilleb564aae2014-10-23 10:18:09 -07002684 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686
2687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 final Phone phone = getPhone(subId);
2690 if (phone != null) {
2691 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2692 }
2693 } finally {
2694 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002695 }
Wink Saville36469e72014-06-11 15:17:00 -07002696 }
2697
2698 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002699 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002700 }
2701
Wink Savilleb564aae2014-10-23 10:18:09 -07002702 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704
2705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 final Phone phone = getPhone(subId);
2708 if (phone == null) {
2709 return false;
2710 }
2711 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2712 toggleRadioOnOffForSubscriber(subId);
2713 }
2714 return true;
2715 } finally {
2716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 }
Wink Saville36469e72014-06-11 15:17:00 -07002719
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002720 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002721 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002722 /*
2723 * If any of the Radios are available, it will need to be
2724 * shutdown. So return true if any Radio is available.
2725 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 final long identity = Binder.clearCallingIdentity();
2727 try {
2728 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2729 Phone phone = PhoneFactory.getPhone(i);
2730 if (phone != null && phone.isRadioAvailable()) return true;
2731 }
2732 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2733 return false;
2734 } finally {
2735 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002736 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002737 }
2738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002740 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741 enforceModifyPermission();
2742
2743 final long identity = Binder.clearCallingIdentity();
2744 try {
2745 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2746 logv("Shutting down Phone " + i);
2747 shutdownRadioUsingPhoneId(i);
2748 }
2749 } finally {
2750 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002751 }
2752 }
2753
2754 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002755 Phone phone = PhoneFactory.getPhone(phoneId);
2756 if (phone != null && phone.isRadioAvailable()) {
2757 phone.shutdownRadio();
2758 }
2759 }
2760
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763
2764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2767 if (defaultPhone != null) {
2768 defaultPhone.setRadioPower(turnOn);
2769 return true;
2770 } else {
2771 loge("There's no default phone.");
2772 return false;
2773 }
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002776 }
Wink Saville36469e72014-06-11 15:17:00 -07002777 }
2778
Wink Savilleb564aae2014-10-23 10:18:09 -07002779 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 final Phone phone = getPhone(subId);
2785 if (phone != null) {
2786 phone.setRadioPower(turnOn);
2787 return true;
2788 } else {
2789 return false;
2790 }
2791 } finally {
2792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 }
2795
Wink Saville36469e72014-06-11 15:17:00 -07002796 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002797 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 public boolean enableDataConnectivity() {
2799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800
2801 final long identity = Binder.clearCallingIdentity();
2802 try {
2803 int subId = mSubscriptionController.getDefaultDataSubId();
2804 final Phone phone = getPhone(subId);
2805 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002806 phone.getDataEnabledSettings().setDataEnabled(
2807 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808 return true;
2809 } else {
2810 return false;
2811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 }
2816
Wink Saville36469e72014-06-11 15:17:00 -07002817 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002818 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 public boolean disableDataConnectivity() {
2820 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821
2822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 int subId = mSubscriptionController.getDefaultDataSubId();
2825 final Phone phone = getPhone(subId);
2826 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002827 phone.getDataEnabledSettings().setDataEnabled(
2828 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829 return true;
2830 } else {
2831 return false;
2832 }
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002835 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002836 }
2837
Sanket Padawe356d7632015-06-22 14:03:32 -07002838 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002839 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840 final long identity = Binder.clearCallingIdentity();
2841 try {
2842 final Phone phone = getPhone(subId);
2843 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002844 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 } else {
2846 return false;
2847 }
2848 } finally {
2849 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002850 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 }
2852
2853 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002854 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002855 }
2856
pkanwarae03a6b2016-11-06 20:37:09 -08002857 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 enforceCallPermission();
2859
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2863 return;
2864 }
2865 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2866 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
2869 }
pkanwar32d516d2016-10-14 19:37:38 -07002870 };
2871
Wink Savilleb564aae2014-10-23 10:18:09 -07002872 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874
2875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2878 return false;
2879 }
2880 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 }
2885
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002886 /**
2887 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2888 * tag on getCallState Binder call.
2889 */
2890 @Deprecated
2891 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002893 if (CompatChanges.isChangeEnabled(
2894 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2895 Binder.getCallingUid())) {
2896 // Do not allow this API to be called on API version 31+, it should only be
2897 // called on old apps using this Binder call directly.
2898 throw new SecurityException("This method can only be used for applications "
2899 + "targeting API version 30 or less.");
2900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 final long identity = Binder.clearCallingIdentity();
2902 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002903 Phone phone = getPhone(getDefaultSubscription());
2904 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2905 PhoneConstantConversions.convertCallState(phone.getState());
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
2908 }
2909 }
2910
2911 @Override
2912 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2913 if (CompatChanges.isChangeEnabled(
2914 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2915 Binder.getCallingUid())) {
2916 // Check READ_PHONE_STATE for API version 31+
2917 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2918 featureId, "getCallStateForSubscription")) {
2919 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2920 + "targeting API level 31+.");
2921 }
2922 }
2923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2927 PhoneConstantConversions.convertCallState(phone.getState());
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
2930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
2932
Sanket Padawe356d7632015-06-22 14:03:32 -07002933 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002934 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002935 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2936 }
2937
2938 @Override
2939 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940 final long identity = Binder.clearCallingIdentity();
2941 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002942 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08002944 if (phone.isUsingNewDataStack()) {
2945 return phone.getDataNetworkController().getInternetDataNetworkState();
2946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002947 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2948 } else {
2949 return PhoneConstantConversions.convertDataState(
2950 PhoneConstants.DataState.DISCONNECTED);
2951 }
2952 } finally {
2953 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002955 }
2956
Sanket Padawe356d7632015-06-22 14:03:32 -07002957 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002958 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002959 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2960 }
2961
2962 @Override
2963 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964 final long identity = Binder.clearCallingIdentity();
2965 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002966 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002967 if (phone != null) {
2968 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2969 } else {
2970 return TelephonyManager.DATA_ACTIVITY_NONE;
2971 }
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 }
2976
2977 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002978 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002979 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002980 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002981
2982 LocationAccessPolicy.LocationPermissionResult locationResult =
2983 LocationAccessPolicy.checkLocationPermission(mApp,
2984 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2985 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002986 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002987 .setCallingPid(Binder.getCallingPid())
2988 .setCallingUid(Binder.getCallingUid())
2989 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002990 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002991 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2992 .build());
2993 switch (locationResult) {
2994 case DENIED_HARD:
2995 throw new SecurityException("Not allowed to access cell location");
2996 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002997 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2998 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002999 }
3000
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003001 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003005 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003006 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007 } finally {
3008 Binder.restoreCallingIdentity(identity);
3009 }
Svetoslav64fad262015-04-14 14:35:21 -07003010 }
3011
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003012 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003013 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003014 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3015 // registered cell info, so return a NULL country instead.
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003018 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3019 // Get default phone in this case.
3020 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3021 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003022 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003024 if (phone == null) return "";
3025 ServiceStateTracker sst = phone.getServiceStateTracker();
3026 if (sst == null) return "";
3027 LocaleTracker lt = sst.getLocaleTracker();
3028 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003029 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003033 }
3034
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003035 /**
3036 * This method was removed due to potential issues caused by performing partial
3037 * updates of service state, and lack of a credible use case.
3038 *
3039 * This has the ability to break the telephony implementation by disabling notification of
3040 * changes in device connectivity. DO NOT USE THIS!
3041 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003042 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003043 public void enableLocationUpdates() {
3044 mApp.enforceCallingOrSelfPermission(
3045 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003046 }
3047
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003048 /**
3049 * This method was removed due to potential issues caused by performing partial
3050 * updates of service state, and lack of a credible use case.
3051 *
3052 * This has the ability to break the telephony implementation by disabling notification of
3053 * changes in device connectivity. DO NOT USE THIS!
3054 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003055 @Override
3056 public void disableLocationUpdates() {
3057 mApp.enforceCallingOrSelfPermission(
3058 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 }
3060
3061 @Override
3062 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003063 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3064 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003065 try {
3066 mApp.getSystemService(AppOpsManager.class)
3067 .checkPackage(Binder.getCallingUid(), callingPackage);
3068 } catch (SecurityException e) {
3069 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3070 throw e;
3071 }
3072
Nathan Haroldf096d982020-11-18 17:18:06 -08003073 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003074 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3075 throw new SecurityException(
3076 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3077 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003078
Jordan Liu1617b712019-07-10 15:06:26 -07003079 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3081 return null;
3082 }
Svetoslav64fad262015-04-14 14:35:21 -07003083
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003084 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003085
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003086 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003087 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003088
Nathan Haroldf180aac2018-06-01 18:43:55 -07003089 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3090 for (CellInfo ci : info) {
3091 if (ci instanceof CellInfoGsm) {
3092 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3093 } else if (ci instanceof CellInfoWcdma) {
3094 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003097 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 }
3099
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003100 private List<CellInfo> getCachedCellInfo() {
3101 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3102 for (Phone phone : PhoneFactory.getPhones()) {
3103 List<CellInfo> info = phone.getAllCellInfo();
3104 if (info != null) cellInfos.addAll(info);
3105 }
3106 return cellInfos;
3107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108
3109 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003110 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003111 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003112 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003113
3114 LocationAccessPolicy.LocationPermissionResult locationResult =
3115 LocationAccessPolicy.checkLocationPermission(mApp,
3116 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3117 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003118 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003119 .setCallingPid(Binder.getCallingPid())
3120 .setCallingUid(Binder.getCallingUid())
3121 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003122 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003123 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3124 .build());
3125 switch (locationResult) {
3126 case DENIED_HARD:
3127 throw new SecurityException("Not allowed to access cell info");
3128 case DENIED_SOFT:
3129 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003130 }
3131
Nathan Haroldf096d982020-11-18 17:18:06 -08003132 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003133 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3134 return getCachedCellInfo();
3135 }
3136
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003137 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003138 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003139 final long identity = Binder.clearCallingIdentity();
3140 try {
3141 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3142 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003143 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003144 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145 if (info != null) cellInfos.addAll(info);
3146 }
3147 return cellInfos;
3148 } finally {
3149 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150 }
3151 }
3152
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003153 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003154 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3155 String callingFeatureId) {
3156 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3157 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003158 }
3159
3160 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003161 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3162 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003163 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003164 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003165 }
3166
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003167 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3168 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003169 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003170 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003171
3172 LocationAccessPolicy.LocationPermissionResult locationResult =
3173 LocationAccessPolicy.checkLocationPermission(mApp,
3174 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3175 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003176 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003177 .setCallingPid(Binder.getCallingPid())
3178 .setCallingUid(Binder.getCallingUid())
3179 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003180 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3181 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003182 .build());
3183 switch (locationResult) {
3184 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003185 if (TelephonyPermissions
3186 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003187 // Safetynet logging for b/154934934
3188 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3189 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003190 throw new SecurityException("Not allowed to access cell info");
3191 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003192 if (TelephonyPermissions
3193 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003194 // Safetynet logging for b/154934934
3195 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3196 }
Nathan Harold5320c422019-05-09 10:26:08 -07003197 try {
3198 cb.onCellInfo(new ArrayList<CellInfo>());
3199 } catch (RemoteException re) {
3200 // Drop without consequences
3201 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003202 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003203 }
3204
Nathan Harolda939a962019-05-09 10:13:47 -07003205
3206 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003207 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3208
3209 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3210 }
3211
3212 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003213 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003214 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003215 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216
3217 final long identity = Binder.clearCallingIdentity();
3218 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003219 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003223 }
3224
Shishir Agrawala9f32182016-04-12 12:00:16 -07003225 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003226 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003227 Phone phone = PhoneFactory.getPhone(slotIndex);
3228 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003229 return null;
3230 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003231 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003232 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003233 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003234 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003235 return null;
3236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003237
3238 final long identity = Binder.clearCallingIdentity();
3239 try {
3240 return phone.getImei();
3241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003244 }
3245
3246 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003247 public String getTypeAllocationCodeForSlot(int slotIndex) {
3248 Phone phone = PhoneFactory.getPhone(slotIndex);
3249 String tac = null;
3250 if (phone != null) {
3251 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003252 try {
3253 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3254 } catch (IndexOutOfBoundsException e) {
3255 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3256 return null;
3257 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003258 }
3259 return tac;
3260 }
3261
3262 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003263 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003264 try {
3265 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3266 } catch (SecurityException se) {
3267 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3268 throw new SecurityException("Package " + callingPackage + " does not belong to "
3269 + Binder.getCallingUid());
3270 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003271 Phone phone = PhoneFactory.getPhone(slotIndex);
3272 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003273 return null;
3274 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003275
Jeff Davidson913390f2018-02-23 17:11:49 -08003276 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003277 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003278 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003279 return null;
3280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281
3282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 return phone.getMeid();
3285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
Jack Yu2af8d712017-03-15 17:14:14 -07003288 }
3289
3290 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003291 public String getManufacturerCodeForSlot(int slotIndex) {
3292 Phone phone = PhoneFactory.getPhone(slotIndex);
3293 String manufacturerCode = null;
3294 if (phone != null) {
3295 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003296 try {
3297 manufacturerCode =
3298 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3299 } catch (IndexOutOfBoundsException e) {
3300 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3301 return null;
3302 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003303 }
3304 return manufacturerCode;
3305 }
3306
3307 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003308 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3309 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003310 Phone phone = PhoneFactory.getPhone(slotIndex);
3311 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003312 return null;
3313 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003314 int subId = phone.getSubId();
3315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003316 mApp, subId, callingPackage, callingFeatureId,
3317 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003318 return null;
3319 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003320
3321 final long identity = Binder.clearCallingIdentity();
3322 try {
3323 return phone.getDeviceSvn();
3324 } finally {
3325 Binder.restoreCallingIdentity(identity);
3326 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003327 }
3328
fionaxu43304da2017-11-27 22:51:16 -08003329 @Override
3330 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331 final long identity = Binder.clearCallingIdentity();
3332 try {
3333 final Phone phone = getPhone(subId);
3334 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
fionaxu43304da2017-11-27 22:51:16 -08003338 }
3339
3340 @Override
3341 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 final Phone phone = getPhone(subId);
3345 return phone == null ? null : phone.getCarrierName();
3346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
fionaxu43304da2017-11-27 22:51:16 -08003349 }
3350
calvinpanffe225e2018-11-01 19:43:06 +08003351 @Override
chen xu0026ca62019-03-06 15:28:50 -08003352 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003353 final long identity = Binder.clearCallingIdentity();
3354 try {
3355 final Phone phone = getPhone(subId);
3356 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003357 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003358 } finally {
3359 Binder.restoreCallingIdentity(identity);
3360 }
3361 }
3362
3363 @Override
chen xu0026ca62019-03-06 15:28:50 -08003364 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003365 final long identity = Binder.clearCallingIdentity();
3366 try {
3367 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003368 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
3372 }
3373
chen xu651eec72018-11-11 19:03:44 -08003374 @Override
chen xu864e11c2018-12-06 22:10:03 -08003375 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3376 if (!isSubscriptionMccMnc) {
3377 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3378 }
chen xu651eec72018-11-11 19:03:44 -08003379 final Phone phone = PhoneFactory.getPhone(slotIndex);
3380 if (phone == null) {
3381 return TelephonyManager.UNKNOWN_CARRIER_ID;
3382 }
3383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
3389 }
3390
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003391 //
3392 // Internal helper methods.
3393 //
3394
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003395 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003396 * Make sure the caller is the calling package itself
3397 *
3398 * @throws SecurityException if the caller is not the calling package
3399 */
3400 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3401 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003402 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3403 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003404 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003405 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003406 } catch (PackageManager.NameNotFoundException e) {
3407 // packageUid is -1
3408 }
3409 if (packageUid != callingUid) {
3410 throw new SecurityException(message + ": Package " + callingPackage
3411 + " does not belong to " + callingUid);
3412 }
3413 }
3414
3415 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003416 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3417 *
3418 * @throws SecurityException if the caller does not have the required permission
3419 */
3420 private void enforceModifyPermission() {
3421 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3422 }
3423
Shuo Qian3b6ee772019-11-13 17:43:31 -08003424 private void enforceActiveEmergencySessionPermission() {
3425 mApp.enforceCallingOrSelfPermission(
3426 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3427 }
3428
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003429 /**
3430 * Make sure the caller has the CALL_PHONE permission.
3431 *
3432 * @throws SecurityException if the caller does not have the required permission
3433 */
3434 private void enforceCallPermission() {
3435 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3436 }
3437
paulhu5a773602019-08-23 19:17:33 +08003438 private void enforceSettingsPermission() {
3439 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003440 }
3441
Michele Berionne5e411512020-11-13 02:36:59 +00003442 private void enforceRebootPermission() {
3443 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3444 }
3445
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003446 private String createTelUrl(String number) {
3447 if (TextUtils.isEmpty(number)) {
3448 return null;
3449 }
3450
Jake Hambye994d462014-02-03 13:10:13 -08003451 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 }
3453
Ihab Awadf9e92732013-12-05 18:02:52 -08003454 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3456 }
3457
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003458 private static void logv(String msg) {
3459 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3460 }
3461
Ihab Awadf9e92732013-12-05 18:02:52 -08003462 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3464 }
3465
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003466 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003467 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003468 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003469 }
3470
Sanket Padawe356d7632015-06-22 14:03:32 -07003471 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003472 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 final Phone phone = PhoneFactory.getPhone(slotIndex);
3476 if (phone == null) {
3477 return PhoneConstants.PHONE_TYPE_NONE;
3478 } else {
3479 return phone.getPhoneType();
3480 }
3481 } finally {
3482 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003484 }
3485
3486 /**
3487 * Returns the CDMA ERI icon index to display
3488 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003489 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003490 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3491 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3492 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003493 }
3494
Sanket Padawe356d7632015-06-22 14:03:32 -07003495 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003496 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3497 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003499 mApp, subId, callingPackage, callingFeatureId,
3500 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003501 return -1;
3502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003503
3504 final long identity = Binder.clearCallingIdentity();
3505 try {
3506 final Phone phone = getPhone(subId);
3507 if (phone != null) {
3508 return phone.getCdmaEriIconIndex();
3509 } else {
3510 return -1;
3511 }
3512 } finally {
3513 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003515 }
3516
3517 /**
3518 * Returns the CDMA ERI icon mode,
3519 * 0 - ON
3520 * 1 - FLASHING
3521 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003522 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003523 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3524 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3525 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003526 }
3527
Sanket Padawe356d7632015-06-22 14:03:32 -07003528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003529 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3530 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003532 mApp, subId, callingPackage, callingFeatureId,
3533 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003534 return -1;
3535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536
3537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 final Phone phone = getPhone(subId);
3540 if (phone != null) {
3541 return phone.getCdmaEriIconMode();
3542 } else {
3543 return -1;
3544 }
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003548 }
3549
3550 /**
3551 * Returns the CDMA ERI text,
3552 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003553 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003554 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3555 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3556 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003557 }
3558
Sanket Padawe356d7632015-06-22 14:03:32 -07003559 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003560 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3561 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003562 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003563 mApp, subId, callingPackage, callingFeatureId,
3564 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003565 return null;
3566 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003567
3568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 final Phone phone = getPhone(subId);
3571 if (phone != null) {
3572 return phone.getCdmaEriText();
3573 } else {
3574 return null;
3575 }
3576 } finally {
3577 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003579 }
3580
3581 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003582 * Returns the CDMA MDN.
3583 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003584 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003585 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3587 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003588
3589 final long identity = Binder.clearCallingIdentity();
3590 try {
3591 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003592 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003593 return phone.getLine1Number();
3594 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003595 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596 return null;
3597 }
3598 } finally {
3599 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003600 }
3601 }
3602
3603 /**
3604 * Returns the CDMA MIN.
3605 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003606 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003607 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3609 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003610
3611 final long identity = Binder.clearCallingIdentity();
3612 try {
3613 final Phone phone = getPhone(subId);
3614 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3615 return phone.getCdmaMin();
3616 } else {
3617 return null;
3618 }
3619 } finally {
3620 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003621 }
3622 }
3623
Hall Liud892bec2018-11-30 14:51:45 -08003624 @Override
3625 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3626 INumberVerificationCallback callback, String callingPackage) {
3627 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3628 != PERMISSION_GRANTED) {
3629 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3630 }
3631 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3632
3633 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3634 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003635 throw new SecurityException("Calling package must be configured in the device config: "
3636 + "calling package: " + callingPackage
3637 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003638 }
3639
3640 if (range == null) {
3641 throw new NullPointerException("Range must be non-null");
3642 }
3643
3644 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003645 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003646
3647 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3648 }
3649
Junda Liuca05d5d2014-08-14 22:36:34 -07003650 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003651 * Returns true if CDMA provisioning needs to run.
3652 */
3653 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 final long identity = Binder.clearCallingIdentity();
3655 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003656 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003660 }
3661
3662 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003663 * Sets the voice mail number of a given subId.
3664 */
3665 @Override
3666 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003667 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3668 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669
3670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3673 new Pair<String, String>(alphaTag, number), new Integer(subId));
3674 return success;
3675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003678 }
3679
Ta-wei Yen87c49842016-05-13 21:19:52 -07003680 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003681 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3682 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003683 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3684 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003685 if (!TextUtils.equals(callingPackage, systemDialer)) {
3686 throw new SecurityException("caller must be system dialer");
3687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003688
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3692 if (phoneAccountHandle == null) {
3693 return null;
3694 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003695 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003696 } finally {
3697 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003698 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003699 }
3700
3701 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003702 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3703 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003704 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003706 mApp, subId, callingPackage, callingFeatureId,
3707 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003708 return null;
3709 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003711 final long identity = Binder.clearCallingIdentity();
3712 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003713 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003717 }
3718
3719 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003720 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3721 VisualVoicemailSmsFilterSettings settings) {
3722 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723
3724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003727 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728 } finally {
3729 Binder.restoreCallingIdentity(identity);
3730 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003731 }
3732
3733 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003734 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3735 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736
3737 final long identity = Binder.clearCallingIdentity();
3738 try {
3739 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003740 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741 } finally {
3742 Binder.restoreCallingIdentity(identity);
3743 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003744 }
3745
3746 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003747 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3748 String callingPackage, int subId) {
3749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750
3751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003754 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755 } finally {
3756 Binder.restoreCallingIdentity(identity);
3757 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003758 }
3759
3760 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003761 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003762 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003763
3764 final long identity = Binder.clearCallingIdentity();
3765 try {
3766 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003767 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768 } finally {
3769 Binder.restoreCallingIdentity(identity);
3770 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003771 }
3772
3773 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003774 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3775 String callingAttributionTag, int subId, String number, int port, String text,
3776 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003777 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003778 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003779 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003780 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003781 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3782 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003783 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003784
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003785 /**
fionaxu0152e512016-11-14 13:36:14 -08003786 * Sets the voice activation state of a given subId.
3787 */
3788 @Override
3789 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3791 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792
3793 final long identity = Binder.clearCallingIdentity();
3794 try {
3795 final Phone phone = getPhone(subId);
3796 if (phone != null) {
3797 phone.setVoiceActivationState(activationState);
3798 } else {
3799 loge("setVoiceActivationState fails with invalid subId: " + subId);
3800 }
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003803 }
3804 }
3805
3806 /**
3807 * Sets the data activation state of a given subId.
3808 */
3809 @Override
3810 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3812 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813
3814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 final Phone phone = getPhone(subId);
3817 if (phone != null) {
3818 phone.setDataActivationState(activationState);
3819 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003820 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821 }
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003824 }
3825 }
3826
3827 /**
3828 * Returns the voice activation state of a given subId.
3829 */
3830 @Override
3831 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003832 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833
fionaxu0152e512016-11-14 13:36:14 -08003834 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003835 final long identity = Binder.clearCallingIdentity();
3836 try {
3837 if (phone != null) {
3838 return phone.getVoiceActivationState();
3839 } else {
3840 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3841 }
3842 } finally {
3843 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003844 }
3845 }
3846
3847 /**
3848 * Returns the data activation state of a given subId.
3849 */
3850 @Override
3851 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853
fionaxu0152e512016-11-14 13:36:14 -08003854 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003855 final long identity = Binder.clearCallingIdentity();
3856 try {
3857 if (phone != null) {
3858 return phone.getDataActivationState();
3859 } else {
3860 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3861 }
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003864 }
3865 }
3866
3867 /**
Wink Saville36469e72014-06-11 15:17:00 -07003868 * Returns the unread count of voicemails for a subId
3869 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003870 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003871 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3872 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003873 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003874 mApp, subId, callingPackage, callingFeatureId,
3875 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003876 return 0;
3877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003878 final long identity = Binder.clearCallingIdentity();
3879 try {
3880 final Phone phone = getPhone(subId);
3881 if (phone != null) {
3882 return phone.getVoiceMessageCount();
3883 } else {
3884 return 0;
3885 }
3886 } finally {
3887 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003889 }
3890
3891 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003892 * returns true, if the device is in a state where both voice and data
3893 * are supported simultaneously. This can change based on location or network condition.
3894 */
3895 @Override
3896 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 final Phone phone = getPhone(subId);
3900 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3901 } finally {
3902 Binder.restoreCallingIdentity(identity);
3903 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003904 }
3905
3906 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003907 * Send the dialer code if called from the current default dialer or the caller has
3908 * carrier privilege.
3909 * @param inputCode The dialer code to send
3910 */
3911 @Override
3912 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003913 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003914 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003915 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3916 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003917 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003918 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003919 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003920 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003921
3922 final long identity = Binder.clearCallingIdentity();
3923 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003924 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003925 } finally {
3926 Binder.restoreCallingIdentity(identity);
3927 }
fionaxu235cc5e2017-03-06 22:25:57 -08003928 }
3929
Pengquan Menga1bb6272018-09-06 09:59:22 -07003930 @Override
3931 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003932 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003933 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003934 mApp, subId, "getNetworkSelectionMode");
3935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 if (!isActiveSubscription(subId)) {
3938 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3939 }
3940 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3941 } finally {
3942 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003943 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003944 }
3945
Brad Ebinger35c841c2018-10-01 10:40:55 -07003946 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003947 public boolean isInEmergencySmsMode() {
3948 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 for (Phone phone : PhoneFactory.getPhones()) {
3952 if (phone.isInEmergencySmsMode()) {
3953 return true;
3954 }
3955 }
3956 } finally {
3957 Binder.restoreCallingIdentity(identity);
3958 }
3959 return false;
3960 }
3961
shilu366312e2019-12-17 09:28:10 -08003962 /**
3963 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3964 * @param subId The subscription to use to check the configuration.
3965 * @param c The callback that will be used to send the result.
3966 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003967 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003968 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3969 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003970 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003971 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003972
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003973 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3974 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3975 "IMS not available on device.");
3976 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 final long token = Binder.clearCallingIdentity();
3978 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003979 int slotId = getSlotIndexOrException(subId);
3980 verifyImsMmTelConfiguredOrThrow(slotId);
3981 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003982 } catch (ImsException e) {
3983 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003984 } finally {
3985 Binder.restoreCallingIdentity(token);
3986 }
3987 }
3988
shilu366312e2019-12-17 09:28:10 -08003989 /**
3990 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3991 * @param subId The subscription to use to check the configuration.
3992 * @param c The callback that will be used to send the result.
3993 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003994 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003995 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003996 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003997 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003998 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3999 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4000 }
Meng Wangafbc5852019-09-19 17:37:13 -07004001 final long token = Binder.clearCallingIdentity();
4002 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004003 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4004 .removeRegistrationCallbackForSubscription(c, subId);
4005 } catch (ImsException e) {
4006 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4007 + "is inactive, ignoring unregister.");
4008 // If the subscription is no longer active, just return, since the callback
4009 // will already have been removed internally.
4010 } finally {
4011 Binder.restoreCallingIdentity(token);
4012 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004013 }
4014
Brad Ebingera34a6c22019-10-22 17:36:18 -07004015 /**
4016 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4017 */
4018 @Override
4019 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4020 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4021 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4022 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4023 "IMS not available on device.");
4024 }
4025 final long token = Binder.clearCallingIdentity();
4026 try {
4027 Phone phone = getPhone(subId);
4028 if (phone == null) {
4029 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4030 + subId + "'");
4031 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4032 }
4033 phone.getImsRegistrationState(regState -> {
4034 try {
4035 consumer.accept((regState == null)
4036 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4037 } catch (RemoteException e) {
4038 // Ignore if the remote process is no longer available to call back.
4039 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4040 }
4041 });
4042 } finally {
4043 Binder.restoreCallingIdentity(token);
4044 }
4045 }
4046
4047 /**
4048 * Get the transport type for the IMS service registration state.
4049 */
4050 @Override
4051 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004052 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004053 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004054 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4055 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4056 "IMS not available on device.");
4057 }
4058 final long token = Binder.clearCallingIdentity();
4059 try {
4060 Phone phone = getPhone(subId);
4061 if (phone == null) {
4062 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4063 + subId + "'");
4064 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4065 }
4066 phone.getImsRegistrationTech(regTech -> {
4067 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4068 int regTechConverted = (regTech == null)
4069 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4070 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4071 regTechConverted);
4072 try {
4073 consumer.accept(regTechConverted);
4074 } catch (RemoteException e) {
4075 // Ignore if the remote process is no longer available to call back.
4076 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4077 }
4078 });
4079 } finally {
4080 Binder.restoreCallingIdentity(token);
4081 }
4082 }
4083
shilu366312e2019-12-17 09:28:10 -08004084 /**
4085 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4086 * @param subId The subscription to use to check the configuration.
4087 * @param c The callback that will be used to send the result.
4088 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004090 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4091 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004092 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004093 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004094 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4095 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4096 "IMS not available on device.");
4097 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 final long token = Binder.clearCallingIdentity();
4099 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004100 int slotId = getSlotIndexOrException(subId);
4101 verifyImsMmTelConfiguredOrThrow(slotId);
4102 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004103 } catch (ImsException e) {
4104 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004105 } finally {
4106 Binder.restoreCallingIdentity(token);
4107 }
4108 }
4109
shilu366312e2019-12-17 09:28:10 -08004110 /**
4111 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4112 * @param subId The subscription to use to check the configuration.
4113 * @param c The callback that will be used to send the result.
4114 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004116 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004117 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004118 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004119 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4120 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4121 }
Meng Wangafbc5852019-09-19 17:37:13 -07004122
4123 final long token = Binder.clearCallingIdentity();
4124 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004125 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004126 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004127 } catch (ImsException e) {
4128 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4129 + "is inactive, ignoring unregister.");
4130 // If the subscription is no longer active, just return, since the callback
4131 // will already have been removed internally.
4132 } finally {
4133 Binder.restoreCallingIdentity(token);
4134 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004135 }
4136
4137 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004138 public boolean isCapable(int subId, int capability, int regTech) {
4139 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004140 final long token = Binder.clearCallingIdentity();
4141 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004142 int slotId = getSlotIndexOrException(subId);
4143 verifyImsMmTelConfiguredOrThrow(slotId);
4144 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004145 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4147 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004148 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004149 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4150 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 } finally {
4152 Binder.restoreCallingIdentity(token);
4153 }
4154 }
4155
4156 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004157 public boolean isAvailable(int subId, int capability, int regTech) {
4158 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 final long token = Binder.clearCallingIdentity();
4160 try {
4161 Phone phone = getPhone(subId);
4162 if (phone == null) return false;
4163 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004164 } catch (com.android.ims.ImsException e) {
4165 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4166 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004167 } finally {
4168 Binder.restoreCallingIdentity(token);
4169 }
4170 }
4171
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004172 /**
4173 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4174 * subscription.
4175 * @param subId The subscription to use to check the configuration.
4176 * @param callback The callback that will be used to send the result.
4177 * @param capability The MmTelFeature capability that will be used to send the result.
4178 * @param transportType The transport type of the MmTelFeature capability.
4179 */
4180 @Override
4181 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4182 int transportType) {
4183 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4184 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4185 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4186 "IMS not available on device.");
4187 }
4188 final long token = Binder.clearCallingIdentity();
4189 try {
4190 int slotId = getSlotIndex(subId);
4191 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4192 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4193 + subId + "'");
4194 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4195 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004196 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004197 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4198 transportType, aBoolean -> {
4199 try {
4200 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4201 } catch (RemoteException e) {
4202 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4203 + "running. Ignore");
4204 }
4205 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004206 } catch (ImsException e) {
4207 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004208 } finally {
4209 Binder.restoreCallingIdentity(token);
4210 }
4211 }
4212
shilu366312e2019-12-17 09:28:10 -08004213 /**
4214 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4215 * @param subId The subscription to use to check the configuration.
4216 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 @Override
4218 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004219 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004220 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004221
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 final long token = Binder.clearCallingIdentity();
4223 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004224 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004225 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004226 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004227 } catch (ImsException e) {
4228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 } finally {
4230 Binder.restoreCallingIdentity(token);
4231 }
4232 }
4233
4234 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004235 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004237 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004238 final long identity = Binder.clearCallingIdentity();
4239 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004240 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004241 // This setting doesn't require an active ImsService connection, so do not verify. The
4242 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004243 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004244 } catch (ImsException e) {
4245 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004246 } finally {
4247 Binder.restoreCallingIdentity(identity);
4248 }
4249 }
4250
shilu366312e2019-12-17 09:28:10 -08004251 /**
4252 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4253 * @param subId The subscription to use to check the configuration.
4254 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004256 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004257 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004258 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 final long identity = Binder.clearCallingIdentity();
4260 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004261 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004262 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004263 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004264 } catch (ImsException e) {
4265 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004266 } finally {
4267 Binder.restoreCallingIdentity(identity);
4268 }
4269 }
4270
4271 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004272 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004274 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 final long identity = Binder.clearCallingIdentity();
4276 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004277 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004278 // This setting doesn't require an active ImsService connection, so do not verify. The
4279 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004280 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004281 } catch (ImsException e) {
4282 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
4286 }
4287
shilu366312e2019-12-17 09:28:10 -08004288 /**
4289 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4290 * @param subId The subscription to use to check the configuration.
4291 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004292 @Override
4293 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004294 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004295 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 final long identity = Binder.clearCallingIdentity();
4297 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004299 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004300 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004301 } catch (ImsException e) {
4302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004303 } finally {
4304 Binder.restoreCallingIdentity(identity);
4305 }
4306 }
4307
4308 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004309 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004311 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004312 final long identity = Binder.clearCallingIdentity();
4313 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004314 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004315 // This setting doesn't require an active ImsService connection, so do not verify. The
4316 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004317 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004318 } catch (ImsException e) {
4319 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
4323 }
4324
shilu366312e2019-12-17 09:28:10 -08004325 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004326 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4327 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4328 * @param subId The subscription to use to check the configuration.
4329 */
4330 @Override
4331 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004332 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004333 mApp, subId, "isCrossSimCallingEnabledByUser");
4334 final long identity = Binder.clearCallingIdentity();
4335 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004336 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004337 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004338 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004339 } catch (ImsException e) {
4340 throw new ServiceSpecificException(e.getCode());
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
4344 }
4345
4346 /**
4347 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4348 * Requires MODIFY_PHONE_STATE permission.
4349 * @param subId The subscription to use to check the configuration.
4350 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4351 * false otherwise
4352 */
4353 @Override
4354 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4356 "setCrossSimCallingEnabled");
4357 final long identity = Binder.clearCallingIdentity();
4358 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004359 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004360 // This setting doesn't require an active ImsService connection, so do not verify. The
4361 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004362 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004363 } catch (ImsException e) {
4364 throw new ServiceSpecificException(e.getCode());
4365 } finally {
4366 Binder.restoreCallingIdentity(identity);
4367 }
4368 }
4369
4370 /**
shilu366312e2019-12-17 09:28:10 -08004371 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4372 * @param subId The subscription to use to check the configuration.
4373 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004375
Brad Ebinger35c841c2018-10-01 10:40:55 -07004376 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004377 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004378 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 final long identity = Binder.clearCallingIdentity();
4380 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004381 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004382 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004383 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004384 } catch (ImsException e) {
4385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 } finally {
4387 Binder.restoreCallingIdentity(identity);
4388 }
4389 }
4390
4391 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004392 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004394 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004395 final long identity = Binder.clearCallingIdentity();
4396 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004397 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004398 // This setting doesn't require an active ImsService connection, so do not verify. The
4399 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004400 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004401 } catch (ImsException e) {
4402 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004403 } finally {
4404 Binder.restoreCallingIdentity(identity);
4405 }
4406 }
4407
4408 @Override
4409 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4411 "setVoWiFiNonPersistent");
4412 final long identity = Binder.clearCallingIdentity();
4413 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004414 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004415 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004416 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004417 } catch (ImsException e) {
4418 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
4422 }
4423
shilu366312e2019-12-17 09:28:10 -08004424 /**
4425 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4426 * @param subId The subscription to use to check the configuration.
4427 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004428 @Override
4429 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004430 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004431 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004432 final long identity = Binder.clearCallingIdentity();
4433 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004434 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004435 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004436 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004437 } catch (ImsException e) {
4438 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004439 } finally {
4440 Binder.restoreCallingIdentity(identity);
4441 }
4442 }
4443
4444 @Override
4445 public void setVoWiFiModeSetting(int subId, int mode) {
4446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4447 "setVoWiFiModeSetting");
4448 final long identity = Binder.clearCallingIdentity();
4449 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004450 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004451 // This setting doesn't require an active ImsService connection, so do not verify. The
4452 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004453 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004454 } catch (ImsException e) {
4455 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
4459 }
4460
4461 @Override
4462 public int getVoWiFiRoamingModeSetting(int subId) {
4463 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4464 final long identity = Binder.clearCallingIdentity();
4465 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004466 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004467 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004468 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004469 } catch (ImsException e) {
4470 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
4474 }
4475
4476 @Override
4477 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4479 "setVoWiFiRoamingModeSetting");
4480 final long identity = Binder.clearCallingIdentity();
4481 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004482 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004483 // This setting doesn't require an active ImsService connection, so do not verify. The
4484 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004485 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004486 } catch (ImsException e) {
4487 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004488 } finally {
4489 Binder.restoreCallingIdentity(identity);
4490 }
4491 }
4492
4493 @Override
4494 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4496 "setRttCapabilityEnabled");
4497 final long identity = Binder.clearCallingIdentity();
4498 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004499 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004500 // This setting doesn't require an active ImsService connection, so do not verify. The
4501 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004502 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004503 } catch (ImsException e) {
4504 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004505 } finally {
4506 Binder.restoreCallingIdentity(identity);
4507 }
4508 }
4509
shilu366312e2019-12-17 09:28:10 -08004510 /**
4511 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4512 * @param subId The subscription to use to check the configuration.
4513 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004514 @Override
4515 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004516 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004517 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004518 final long identity = Binder.clearCallingIdentity();
4519 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004520 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004521 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004522 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004523 } catch (ImsException e) {
4524 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004525 } finally {
4526 Binder.restoreCallingIdentity(identity);
4527 }
4528 }
4529
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004530 @Override
4531 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4532 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4533 final long identity = Binder.clearCallingIdentity();
4534 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004535 if (!isImsAvailableOnDevice()) {
4536 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4537 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004538 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004539 int slotId = getSlotIndexOrException(subId);
4540 verifyImsMmTelConfiguredOrThrow(slotId);
4541 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004542 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004543 } catch (ImsException e) {
4544 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004545 } finally {
4546 Binder.restoreCallingIdentity(identity);
4547 }
4548 }
4549
4550 @Override
4551 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4552 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4553 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004554 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4555 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4556 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004557 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004558 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004559 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004560 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004561 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4562 + "is inactive, ignoring unregister.");
4563 // If the subscription is no longer active, just return, since the callback will already
4564 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
4568 }
4569
allenwtsu99c623b2020-01-03 18:24:23 +08004570
4571 private void checkModifyPhoneStatePermission(int subId, String message) {
4572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4573 message);
4574 }
4575
4576 private boolean isImsProvisioningRequired(int subId, int capability,
4577 boolean isMmtelCapability) {
4578 Phone phone = getPhone(subId);
4579 if (phone == null) {
4580 loge("phone instance null for subid " + subId);
4581 return false;
4582 }
4583 if (isMmtelCapability) {
4584 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4585 return false;
4586 }
4587 } else {
4588 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4589 return false;
4590 }
4591 }
4592 return true;
4593 }
4594
4595 @Override
4596 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4597 boolean isProvisioned) {
4598 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4599
4600 final long identity = Binder.clearCallingIdentity();
4601 try {
4602 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4603 if (!isImsProvisioningRequired(subId, capability, false)) {
4604 return;
4605 }
4606
4607 // this capability requires provisioning, route to the correct API.
4608 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4609 switch (capability) {
4610 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4611 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4612 ims.setEabProvisioned(isProvisioned);
4613 break;
4614 default: {
4615 throw new IllegalArgumentException("Tried to set provisioning for "
4616 + "rcs capability '" + capability + "', which does not require "
4617 + "provisioning.");
4618 }
4619 }
4620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
4623
4624 }
4625
4626
4627 @Override
4628 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4629 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4630 final long identity = Binder.clearCallingIdentity();
4631 try {
4632 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4633 if (!isImsProvisioningRequired(subId, capability, false)) {
4634 return true;
4635 }
4636
4637 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4638 switch (capability) {
4639 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4640 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4641 return ims.isEabProvisionedOnDevice();
4642
4643 default: {
4644 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4645 + "capability '" + capability + "', which does not require "
4646 + "provisioning.");
4647 }
4648 }
4649
4650 } finally {
4651 Binder.restoreCallingIdentity(identity);
4652 }
4653 }
4654
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004655 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004656 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4657 boolean isProvisioned) {
4658 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004659 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4660 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4661 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004662 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4663 }
allenwtsu99c623b2020-01-03 18:24:23 +08004664 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004665 final long identity = Binder.clearCallingIdentity();
4666 try {
4667 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004668 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004669 return;
4670 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004671 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4672 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4673 loge("setImsProvisioningStatusForCapability: called for technology that does "
4674 + "not support provisioning - " + tech);
4675 return;
4676 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004677
4678 // this capability requires provisioning, route to the correct API.
4679 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4680 switch (capability) {
4681 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4682 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4683 ims.setVolteProvisioned(isProvisioned);
4684 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4685 ims.setWfcProvisioned(isProvisioned);
4686 }
4687 break;
4688 }
4689 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4690 // There is currently no difference in VT provisioning type.
4691 ims.setVtProvisioned(isProvisioned);
4692 break;
4693 }
4694 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4695 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4696 // change the capability of the feature instead if needed.
4697 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4698 == isProvisioned) {
4699 // No change in provisioning.
4700 return;
4701 }
4702 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4703 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004704 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004705 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004706 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4707 + ", Exception" + e.getMessage());
4708 }
4709 break;
4710 }
4711 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004712 throw new IllegalArgumentException("Tried to set provisioning for "
4713 + "MmTel capability '" + capability + "', which does not require "
4714 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004715 }
4716 }
4717
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
4721 }
4722
4723 @Override
4724 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4725 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004726 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4727 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4728 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004729 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4730 }
4731 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4732 final long identity = Binder.clearCallingIdentity();
4733 try {
4734 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004735 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004736 return true;
4737 }
4738
Brad Ebinger0d79c572021-04-17 15:20:49 -07004739 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4740 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4741 loge("getImsProvisioningStatusForCapability: called for technology that does "
4742 + "not support provisioning - " + tech);
4743 return true;
4744 }
4745
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004746 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4747 switch (capability) {
4748 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4749 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4750 return ims.isVolteProvisionedOnDevice();
4751 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4752 return ims.isWfcProvisionedOnDevice();
4753 }
4754 // This should never happen, since we are checking tech above to make sure it
4755 // is either LTE or IWLAN.
4756 throw new IllegalArgumentException("Invalid radio technology for voice "
4757 + "capability.");
4758 }
4759 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4760 // There is currently no difference in VT provisioning type.
4761 return ims.isVtProvisionedOnDevice();
4762 }
4763 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4764 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4765 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4766 }
4767 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004768 throw new IllegalArgumentException(
4769 "Tried to get provisioning for MmTel capability '" + capability
4770 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004771 }
4772 }
4773
4774 } finally {
4775 Binder.restoreCallingIdentity(identity);
4776 }
4777 }
4778
4779 @Override
4780 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4781 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4782 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4783 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4784 }
4785 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4786 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4787 return (provisionedBits & capability) > 0;
4788 }
4789
4790 @Override
4791 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4792 boolean isProvisioned) {
4793 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4794 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4795 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4796 }
4797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4798 "setProvisioningStatusForCapability");
4799 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4800 // If the current provisioning status for capability already matches isProvisioned,
4801 // do nothing.
4802 if (((provisionedBits & capability) > 0) == isProvisioned) {
4803 return;
4804 }
4805 if (isProvisioned) {
4806 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4807 } else {
4808 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4809 }
4810 }
4811
4812 /**
4813 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4814 * technology. The bitfield should mirror the bitfield defined by
4815 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4816 */
4817 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4818 String key = getMmTelProvisioningKey(subId, tech);
4819 // Default is no capabilities are provisioned.
4820 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4821 }
4822
4823 /**
4824 * Sets the MmTel capability provisioning bitfield (defined by
4825 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4826 * technology specified.
4827 *
4828 * Note: This is a synchronous command and should not be called on UI thread.
4829 */
4830 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4831 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4832 String key = getMmTelProvisioningKey(subId, tech);
4833 editor.putInt(key, newField);
4834 editor.commit();
4835 }
4836
4837 private static String getMmTelProvisioningKey(int subId, int tech) {
4838 // resulting key is provision_ims_mmtel_{subId}_{tech}
4839 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4840 }
4841
4842 /**
4843 * Query CarrierConfig to see if the specified capability requires provisioning for the
4844 * carrier associated with the subscription id.
4845 */
4846 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4847 int capability) {
4848 CarrierConfigManager configManager = new CarrierConfigManager(context);
4849 PersistableBundle c = configManager.getConfigForSubId(subId);
4850 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004851 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004852 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4853 false);
4854 boolean requireVoiceVtProvisioning = c.getBoolean(
4855 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4856
4857 // First check to make sure that the capability requires provisioning.
4858 switch (capability) {
4859 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4860 // intentional fallthrough
4861 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4862 if (requireVoiceVtProvisioning) {
4863 // Voice and Video requires provisioning
4864 return true;
4865 }
4866 break;
4867 }
4868 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4869 if (requireUtProvisioning) {
4870 // UT requires provisioning
4871 return true;
4872 }
4873 break;
4874 }
4875 }
4876 return false;
4877 }
4878
allenwtsu99c623b2020-01-03 18:24:23 +08004879 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4880 int capability) {
4881 CarrierConfigManager configManager = new CarrierConfigManager(context);
4882 PersistableBundle c = configManager.getConfigForSubId(subId);
4883
4884 boolean requireRcsProvisioning = c.getBoolean(
4885 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4886
4887 // First check to make sure that the capability requires provisioning.
4888 switch (capability) {
4889 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4890 // intentional fallthrough
4891 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4892 if (requireRcsProvisioning) {
4893 // OPTION or PRESENCE requires provisioning
4894 return true;
4895 }
4896 break;
4897 }
4898 }
4899 return false;
4900 }
4901
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004902 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004903 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004904 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4905 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4906 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004907 enforceReadPrivilegedPermission("getImsProvisioningInt");
4908 final long identity = Binder.clearCallingIdentity();
4909 try {
4910 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004911 int slotId = getSlotIndex(subId);
4912 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4913 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4914 + subId + "' for key:" + key);
4915 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4916 }
calvinpanb5a34062021-02-08 19:59:36 +08004917 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004918 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004919 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4920 + subId + "' for key:" + key);
4921 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004922 } finally {
4923 Binder.restoreCallingIdentity(identity);
4924 }
4925 }
4926
4927 @Override
4928 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004929 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4930 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4931 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004932 enforceReadPrivilegedPermission("getImsProvisioningString");
4933 final long identity = Binder.clearCallingIdentity();
4934 try {
4935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004936 int slotId = getSlotIndex(subId);
4937 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4938 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4939 + subId + "' for key:" + key);
4940 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4941 }
calvinpanb5a34062021-02-08 19:59:36 +08004942 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004943 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004944 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4945 + subId + "' for key:" + key);
4946 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004947 } finally {
4948 Binder.restoreCallingIdentity(identity);
4949 }
4950 }
4951
4952 @Override
4953 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004954 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4955 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4956 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4958 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004959 final long identity = Binder.clearCallingIdentity();
4960 try {
4961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004962 int slotId = getSlotIndex(subId);
4963 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4964 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4965 + subId + "' for key:" + key);
4966 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4967 }
calvinpanb5a34062021-02-08 19:59:36 +08004968 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4969 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004970 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004971 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004973 } finally {
4974 Binder.restoreCallingIdentity(identity);
4975 }
4976 }
4977
4978 @Override
4979 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004980 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4981 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4982 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4984 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004985 final long identity = Binder.clearCallingIdentity();
4986 try {
4987 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004988 int slotId = getSlotIndex(subId);
4989 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4990 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4991 + subId + "' for key:" + key);
4992 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4993 }
calvinpanb5a34062021-02-08 19:59:36 +08004994 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4995 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004996 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004997 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004998 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004999 } finally {
5000 Binder.restoreCallingIdentity(identity);
5001 }
5002 }
5003
Brad Ebinger919631e2021-06-02 17:46:35 -07005004 /**
5005 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5006 * for the given slot ID or no ImsResolver instance has been created.
5007 * @param slotId The slot ID that the IMS service is created for.
5008 * @throws ImsException If there is no ImsService configured for this slot.
5009 */
5010 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5011 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5012 ImsFeature.FEATURE_MMTEL)) {
5013 throw new ImsException("This subscription does not support MMTEL over IMS",
5014 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5015 }
5016 }
5017
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005018 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005019 int slotId = SubscriptionManager.getSlotIndex(subId);
5020 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005021 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5022 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005023 }
5024 return slotId;
5025 }
5026
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005027 private int getSlotIndex(int subId) {
5028 int slotId = SubscriptionManager.getSlotIndex(subId);
5029 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5030 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5031 }
5032 return slotId;
5033 }
5034
Wink Saville36469e72014-06-11 15:17:00 -07005035 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005036 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005037 */
5038 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005039 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5040 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005041 try {
5042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5043 } catch (SecurityException se) {
5044 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5045 throw new SecurityException("Package " + callingPackage + " does not belong to "
5046 + Binder.getCallingUid());
5047 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005048 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005049 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005050 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005051 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005052 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005053 mApp, subId, callingPackage, callingFeatureId,
5054 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005055 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5056 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005057
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058 final long identity = Binder.clearCallingIdentity();
5059 try {
5060 final Phone phone = getPhone(subId);
5061 if (phone != null) {
5062 return phone.getServiceState().getDataNetworkType();
5063 } else {
5064 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5065 }
5066 } finally {
5067 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005068 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005069 }
5070
5071 /**
5072 * Returns the data network type
5073 */
5074 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005075 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005076 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5077 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005078 }
5079
5080 /**
5081 * Returns the data network type for a subId
5082 */
5083 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005084 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5085 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005086 String functionName = "getDataNetworkTypeForSubscriber";
5087 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5088 mApp, functionName)) {
5089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5090 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5091 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5092 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005093 }
5094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
5097 final Phone phone = getPhone(subId);
5098 if (phone != null) {
5099 return phone.getServiceState().getDataNetworkType();
5100 } else {
5101 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5102 }
5103 } finally {
5104 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005106 }
5107
5108 /**
Wink Saville36469e72014-06-11 15:17:00 -07005109 * Returns the Voice network type for a subId
5110 */
5111 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005112 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5113 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005114 String functionName = "getVoiceNetworkTypeForSubscriber";
5115 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5116 mApp, functionName)) {
5117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5118 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5119 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5120 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005121 }
5122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123 final long identity = Binder.clearCallingIdentity();
5124 try {
5125 final Phone phone = getPhone(subId);
5126 if (phone != null) {
5127 return phone.getServiceState().getVoiceNetworkType();
5128 } else {
5129 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5130 }
5131 } finally {
5132 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005134 }
5135
5136 /**
5137 * @return true if a ICC card is present
5138 */
5139 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005140 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005141 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5142 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005143 }
5144
5145 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005146 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005147 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005148 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005149 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150 final long identity = Binder.clearCallingIdentity();
5151 try {
5152 final Phone phone = PhoneFactory.getPhone(slotIndex);
5153 if (phone != null) {
5154 return phone.getIccCard().hasIccCard();
5155 } else {
5156 return false;
5157 }
5158 } finally {
5159 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005160 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005161 }
5162
5163 /**
5164 * Return if the current radio is LTE on CDMA. This
5165 * is a tri-state return value as for a period of time
5166 * the mode may be unknown.
5167 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005168 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005169 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005170 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005171 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005172 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005173 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5174 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5175 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005176 }
5177
Sanket Padawe356d7632015-06-22 14:03:32 -07005178 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005179 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5180 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005181 try {
5182 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5183 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005184 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5185 }
5186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 final Phone phone = getPhone(subId);
5190 if (phone == null) {
5191 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5192 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005193 return TelephonyProperties.lte_on_cdma_device()
5194 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 }
5196 } finally {
5197 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005198 }
Wink Saville36469e72014-06-11 15:17:00 -07005199 }
5200
Wink Saville36469e72014-06-11 15:17:00 -07005201 /**
5202 * {@hide}
5203 * Returns Default subId, 0 in the case of single standby.
5204 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005205 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005206 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005207 }
5208
Shishir Agrawala9f32182016-04-12 12:00:16 -07005209 private int getSlotForDefaultSubscription() {
5210 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5211 }
5212
Wink Savilleb564aae2014-10-23 10:18:09 -07005213 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005214 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005215 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005216
Pengquan Menge92a50d2018-09-21 15:54:48 -07005217 private boolean isActiveSubscription(int subId) {
5218 return mSubscriptionController.isActiveSubId(subId);
5219 }
5220
Ihab Awadf2177b72013-11-25 13:33:23 -08005221 /**
5222 * @see android.telephony.TelephonyManager.WifiCallingChoices
5223 */
5224 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 final long identity = Binder.clearCallingIdentity();
5226 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005227 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5229 getWhenToMakeWifiCallsDefaultPreference());
5230 } finally {
5231 Binder.restoreCallingIdentity(identity);
5232 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005233 }
5234
5235 /**
5236 * @see android.telephony.TelephonyManager.WifiCallingChoices
5237 */
5238 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 final long identity = Binder.clearCallingIdentity();
5240 try {
5241 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005242 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005247 }
5248
Sailesh Nepald1e68152013-12-12 19:08:02 -08005249 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005250 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005251 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005252 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005253
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005254 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5255 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5256 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005257 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005258 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5259 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005260 }
5261 return PhoneFactory.getPhone(phoneId);
5262 }
5263
Shishir Agrawal566b7612013-10-28 14:41:00 -07005264 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005265 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005266 @NonNull IccLogicalChannelRequest request) {
5267 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5268 /*message=*/ "iccOpenLogicalChannel");
5269
5270 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5271 // Verify that the callingPackage in the request belongs to the calling UID
5272 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5273
5274 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005275 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005276
Rambo Wanga1782702021-11-10 20:15:19 -08005277 private Phone getPhoneFromValidIccLogicalChannelRequest(
5278 @NonNull IccLogicalChannelRequest request, String message) {
5279 Phone phone;
5280 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5282 mApp, request.subId, message);
5283 phone = getPhoneFromSubId(request.subId);
5284 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5285 enforceModifyPermission();
5286 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5287 } else {
5288 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005289 }
Rambo Wanga1782702021-11-10 20:15:19 -08005290 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005291 }
5292
5293 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005294 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295 final long identity = Binder.clearCallingIdentity();
5296 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005297 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005299 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5300 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005301 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5302 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005303 loge("The calling package is not allowed to access ISD-R.");
5304 throw new SecurityException(
5305 "The calling package is not allowed to access ISD-R.");
5306 }
Derek Tan740e1672017-06-27 14:56:27 -07005307 }
Derek Tan740e1672017-06-27 14:56:27 -07005308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005310 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5311 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312 return response;
5313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005316 }
5317
5318 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005319 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5320 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5321 /*message=*/"iccCloseLogicalChannel");
5322
5323 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5324
5325 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005326 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005327
Rambo Wanga1782702021-11-10 20:15:19 -08005328 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5329 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330 final long identity = Binder.clearCallingIdentity();
5331 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005332 if (request.channel < 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 return false;
5334 }
Rambo Wanga1782702021-11-10 20:15:19 -08005335 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005336 null /* workSource */);
Rambo Wanga1782702021-11-10 20:15:19 -08005337 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 return success;
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005341 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005342 }
5343
5344 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005345 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005346 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5348 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005349 if (DBG) {
5350 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5351 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5352 + p3 + " data=" + data);
5353 }
5354 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5355 command, p1, p2, p3, data);
5356 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005357
Jordan Liu4c733742019-02-28 12:03:40 -08005358 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005359 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5360 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005361 enforceModifyPermission();
5362 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005363 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5364 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5365 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005366 }
5367 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005368 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5369 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005370 }
5371
5372 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5373 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 final long identity = Binder.clearCallingIdentity();
5375 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005376 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 return "";
5378 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005381 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5382 null /* workSource */);
5383 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 // Append the returned status code to the end of the response payload.
5386 String s = Integer.toHexString(
5387 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5388 if (response.payload != null) {
5389 s = IccUtils.bytesToHexString(response.payload) + s;
5390 }
5391 return s;
5392 } finally {
5393 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005394 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005395 }
Jake Hambye994d462014-02-03 13:10:13 -08005396
Evan Charltonc66da362014-05-16 14:06:40 -07005397 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005398 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5399 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5401 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005403 if (DBG) {
5404 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5405 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5406 }
5407 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5408 cla, command, p1, p2, p3, data);
5409 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005410
Jordan Liu4c733742019-02-28 12:03:40 -08005411 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005412 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5413 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005414 enforceModifyPermission();
5415 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5416 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005417 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5418 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5419 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005420 }
5421
5422 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005423 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5424 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005425 }
5426
5427 // open APDU basic channel assuming the caller has sufficient permissions
5428 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5429 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
5432 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5433 && TextUtils.equals(ISDR_AID, data)) {
5434 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005435 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5436 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 if (bestComponent == null
5438 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5439 loge("The calling package is not allowed to select ISD-R.");
5440 throw new SecurityException(
5441 "The calling package is not allowed to select ISD-R.");
5442 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005443 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005446 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5447 null /* workSource */);
5448 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 // Append the returned status code to the end of the response payload.
5451 String s = Integer.toHexString(
5452 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5453 if (response.payload != null) {
5454 s = IccUtils.bytesToHexString(response.payload) + s;
5455 }
5456 return s;
5457 } finally {
5458 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005459 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005460 }
5461
5462 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005463 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005464 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5466 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 final long identity = Binder.clearCallingIdentity();
5469 try {
5470 if (DBG) {
5471 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5472 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5473 }
5474
5475 IccIoResult response =
5476 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5477 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5478 subId);
5479
5480 if (DBG) {
5481 log("Exchange SIM_IO [R]" + response);
5482 }
5483
5484 byte[] result = null;
5485 int length = 2;
5486 if (response.payload != null) {
5487 length = 2 + response.payload.length;
5488 result = new byte[length];
5489 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5490 } else {
5491 result = new byte[length];
5492 }
5493
5494 result[length - 1] = (byte) response.sw2;
5495 result[length - 2] = (byte) response.sw1;
5496 return result;
5497 } finally {
5498 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005499 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005500 }
5501
Nathan Haroldb3014052017-01-25 15:57:32 -08005502 /**
5503 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5504 * on a particular subscription
5505 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005506 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5507 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005509 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005510 return null;
5511 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512
5513 final long identity = Binder.clearCallingIdentity();
5514 try {
5515 if (appType != TelephonyManager.APPTYPE_USIM
5516 && appType != TelephonyManager.APPTYPE_SIM) {
5517 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5518 return null;
5519 }
5520 Object response = sendRequest(
5521 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5522 if (response instanceof String[]) {
5523 return (String[]) response;
5524 }
yincheng zhao2737e882019-09-06 17:06:54 -07005525 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005527 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 } finally {
5529 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005530 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005531 }
5532
yincheng zhao2737e882019-09-06 17:06:54 -07005533 /**
5534 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5535 * subscription.
5536 *
5537 * @param subId the id of the subscription.
5538 * @param appType the uicc app type, must be USIM or SIM.
5539 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5540 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005541 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005542 * @return number of fplmns that is successfully written to the SIM.
5543 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005544 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5545 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5547 mApp, subId, "setForbiddenPlmns");
5548
yincheng zhao2737e882019-09-06 17:06:54 -07005549 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5550 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5551 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5552 }
5553 if (fplmns == null) {
5554 throw new IllegalArgumentException("Fplmn List provided is null");
5555 }
5556 for (String fplmn : fplmns) {
5557 if (!CellIdentity.isValidPlmn(fplmn)) {
5558 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5559 }
5560 }
5561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 Object response = sendRequest(
5564 CMD_SET_FORBIDDEN_PLMNS,
5565 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5566 subId);
5567 return (int) response;
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
5571 }
5572
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005573 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005574 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5576 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5581 if (response.payload == null) {
5582 return "";
5583 }
Evan Charltonc66da362014-05-16 14:06:40 -07005584
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585 // Append the returned status code to the end of the response payload.
5586 String s = Integer.toHexString(
5587 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5588 s = IccUtils.bytesToHexString(response.payload) + s;
5589 return s;
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
5592 }
Evan Charltonc66da362014-05-16 14:06:40 -07005593 }
5594
Jake Hambye994d462014-02-03 13:10:13 -08005595 /**
5596 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5597 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5598 *
5599 * @param itemID the ID of the item to read
5600 * @return the NV item as a String, or null on error.
5601 */
5602 @Override
5603 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005604 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5606 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607
5608 final long identity = Binder.clearCallingIdentity();
5609 try {
5610 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005611 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5613 return value;
5614 } finally {
5615 Binder.restoreCallingIdentity(identity);
5616 }
Jake Hambye994d462014-02-03 13:10:13 -08005617 }
5618
5619 /**
5620 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5621 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5622 *
5623 * @param itemID the ID of the item to read
5624 * @param itemValue the value to write, as a String
5625 * @return true on success; false on any failure
5626 */
5627 @Override
5628 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005629 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5631 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632
5633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5636 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005637 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5639 return success;
5640 } finally {
5641 Binder.restoreCallingIdentity(identity);
5642 }
Jake Hambye994d462014-02-03 13:10:13 -08005643 }
5644
5645 /**
5646 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5647 * Used for device configuration by some CDMA operators.
5648 *
5649 * @param preferredRoamingList byte array containing the new PRL
5650 * @return true on success; false on any failure
5651 */
5652 @Override
5653 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5655 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656
5657 final long identity = Binder.clearCallingIdentity();
5658 try {
5659 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5660 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5661 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5662 return success;
5663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Jake Hambye994d462014-02-03 13:10:13 -08005666 }
5667
5668 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005669 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005670 * Used for device configuration by some CDMA operators.
5671 *
chen xu6dac5ab2018-10-26 17:39:23 -07005672 * @param slotIndex - device slot.
5673 *
Jake Hambye994d462014-02-03 13:10:13 -08005674 * @return true on success; false on any failure
5675 */
5676 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005677 public boolean resetModemConfig(int slotIndex) {
5678 Phone phone = PhoneFactory.getPhone(slotIndex);
5679 if (phone != null) {
5680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5681 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682
chen xu6dac5ab2018-10-26 17:39:23 -07005683 final long identity = Binder.clearCallingIdentity();
5684 try {
5685 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5686 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5687 return success;
5688 } finally {
5689 Binder.restoreCallingIdentity(identity);
5690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005691 }
chen xu6dac5ab2018-10-26 17:39:23 -07005692 return false;
5693 }
5694
5695 /**
5696 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5697 *
5698 * @param slotIndex - device slot.
5699 *
5700 * @return true on success; false on any failure
5701 */
5702 @Override
5703 public boolean rebootModem(int slotIndex) {
5704 Phone phone = PhoneFactory.getPhone(slotIndex);
5705 if (phone != null) {
5706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5707 mApp, phone.getSubId(), "rebootModem");
5708
5709 final long identity = Binder.clearCallingIdentity();
5710 try {
5711 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5712 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5713 return success;
5714 } finally {
5715 Binder.restoreCallingIdentity(identity);
5716 }
5717 }
5718 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005719 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005720
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005721 public String[] getPcscfAddress(String apnType, String callingPackage,
5722 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005723 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5725 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005726 return new String[0];
5727 }
5728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729 final long identity = Binder.clearCallingIdentity();
5730 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005731 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 } finally {
5733 Binder.restoreCallingIdentity(identity);
5734 }
Wink Saville36469e72014-06-11 15:17:00 -07005735 }
5736
Brad Ebinger51f743a2017-01-23 13:50:20 -08005737 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005738 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5739 * {@link #disableIms(int)}.
5740 * @param slotIndex device slot.
5741 */
5742 public void resetIms(int slotIndex) {
5743 enforceModifyPermission();
5744
5745 final long identity = Binder.clearCallingIdentity();
5746 try {
5747 if (mImsResolver == null) {
5748 // may happen if the does not support IMS.
5749 return;
5750 }
5751 mImsResolver.disableIms(slotIndex);
5752 mImsResolver.enableIms(slotIndex);
5753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
5756 }
5757
5758 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005759 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5760 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005761 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005762 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764
5765 final long identity = Binder.clearCallingIdentity();
5766 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005767 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005768 // may happen if the device does not support IMS.
5769 return;
5770 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005771 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005775 }
5776
5777 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005778 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5779 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005780 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005781 public void disableIms(int slotId) {
5782 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783
5784 final long identity = Binder.clearCallingIdentity();
5785 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005786 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005787 // may happen if the device does not support IMS.
5788 return;
5789 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005790 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 } finally {
5792 Binder.restoreCallingIdentity(identity);
5793 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005794 }
5795
5796 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005797 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5798 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005799 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005800 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005801 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005802 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803
5804 final long identity = Binder.clearCallingIdentity();
5805 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005806 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005807 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5808 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005809 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005810 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005811 } finally {
5812 Binder.restoreCallingIdentity(identity);
5813 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005814 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005815 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005816 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5817 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005818 @Override
5819 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005820 enforceModifyPermission();
5821
5822 final long identity = Binder.clearCallingIdentity();
5823 try {
5824 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005825 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005826 } finally {
5827 Binder.restoreCallingIdentity(identity);
5828 }
5829 }
5830
5831 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005832 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005833 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005834 */
5835 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837
5838 final long identity = Binder.clearCallingIdentity();
5839 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005840 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005841 // may happen if the device does not support IMS.
5842 return null;
5843 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005844 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005848 }
5849
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005850 /**
5851 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005852 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005853 */
5854 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5855 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005859 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005860 // may happen if the device does not support IMS.
5861 return null;
5862 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005867 }
5868
Brad Ebinger884c07b2018-02-15 16:17:40 -08005869 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005870 * Sets the ImsService Package Name that Telephony will bind to.
5871 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005872 * @param slotIndex the slot ID that the ImsService should bind for.
5873 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005874 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005875 * @param featureTypes An integer array of feature types associated with a packageName.
5876 * @param packageName The name of the package that the current configuration will be replaced
5877 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005878 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005879 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005880 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5881 int[] featureTypes, String packageName) {
5882 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5883 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5885 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005886 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888 final long identity = Binder.clearCallingIdentity();
5889 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005890 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005891 // may happen if the device does not support IMS.
5892 return false;
5893 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005894 Map<Integer, String> featureConfig = new HashMap<>();
5895 for (int featureType : featureTypes) {
5896 featureConfig.put(featureType, packageName);
5897 }
5898 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5899 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005903 }
5904
5905 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005906 * Clears any carrier ImsService overrides for the slot index specified that were previously
5907 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5908 *
5909 * This should only be used for testing.
5910 *
5911 * @param slotIndex the slot ID that the ImsService should bind for.
5912 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5913 */
5914 @Override
5915 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5916 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5917 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5918 "clearCarrierImsServiceOverride");
5919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5920 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5921 "clearCarrierImsServiceOverride");
5922
5923 final long identity = Binder.clearCallingIdentity();
5924 try {
5925 if (mImsResolver == null) {
5926 // may happen if the device does not support IMS.
5927 return false;
5928 }
5929 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5930 } finally {
5931 Binder.restoreCallingIdentity(identity);
5932 }
5933 }
5934
5935 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005937 *
5938 * @param slotId The slot that the ImsService is associated with.
5939 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5940 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005941 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005942 * @return the package name of the ImsService configuration.
5943 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005944 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5945 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005946 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005947 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005948 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005949 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5950 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 final long identity = Binder.clearCallingIdentity();
5953 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005954 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005955 // may happen if the device does not support IMS.
5956 return "";
5957 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005958 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005959 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5960 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 } finally {
5962 Binder.restoreCallingIdentity(identity);
5963 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005964 }
5965
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005966 /**
5967 * Get the MmTelFeature state associated with the requested subscription id.
5968 * @param subId The subscription that the MmTelFeature is associated with.
5969 * @param callback A callback with an integer containing the
5970 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5971 */
5972 @Override
5973 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5974 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5975 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5976 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5977 "IMS not available on device.");
5978 }
5979 final long token = Binder.clearCallingIdentity();
5980 try {
5981 int slotId = getSlotIndex(subId);
5982 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5983 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5984 + subId + "'");
5985 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5986 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005987 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005988 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5989 try {
5990 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5991 } catch (RemoteException e) {
5992 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5993 + "Ignore");
5994 }
5995 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005996 } catch (ImsException e) {
5997 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005998 } finally {
5999 Binder.restoreCallingIdentity(token);
6000 }
6001 }
6002
Daniel Brightbb5840b2021-01-12 15:48:18 -08006003 /**
6004 * Sets the ims registration state on all valid {@link Phone}s.
6005 */
6006 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006007 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008
6009 final long identity = Binder.clearCallingIdentity();
6010 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006011 // NOTE: Before S, this method only set the default phone.
6012 for (final Phone phone : PhoneFactory.getPhones()) {
6013 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6014 phone.setImsRegistrationState(registered);
6015 }
6016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 } finally {
6018 Binder.restoreCallingIdentity(identity);
6019 }
Wink Saville36469e72014-06-11 15:17:00 -07006020 }
6021
6022 /**
Stuart Scott54788802015-03-30 13:18:01 -07006023 * Set the network selection mode to automatic.
6024 *
6025 */
6026 @Override
6027 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6029 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030
6031 final long identity = Binder.clearCallingIdentity();
6032 try {
shilufc958392020-01-20 11:36:01 -08006033 if (!isActiveSubscription(subId)) {
6034 return;
6035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006037 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6038 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 } finally {
6040 Binder.restoreCallingIdentity(identity);
6041 }
Stuart Scott54788802015-03-30 13:18:01 -07006042 }
6043
Jack Yud10cdd42020-09-28 20:28:01 -07006044 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006045 * Ask the radio to connect to the input network and change selection mode to manual.
6046 *
6047 * @param subId the id of the subscription.
6048 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6049 * the operator to attach to.
6050 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6051 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6052 * normal network selection next time.
6053 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006054 */
6055 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006056 public boolean setNetworkSelectionModeManual(
6057 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6059 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006060
6061 if (!isActiveSubscription(subId)) {
6062 return false;
6063 }
6064
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 final long identity = Binder.clearCallingIdentity();
6066 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006067 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006069 if (DBG) {
6070 log("setNetworkSelectionModeManual: subId: " + subId
6071 + " operator: " + operatorInfo);
6072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6074 } finally {
6075 Binder.restoreCallingIdentity(identity);
6076 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006077 }
shilu84f6e8b2019-12-19 13:58:01 -08006078 /**
6079 * Get the manual network selection
6080 *
6081 * @param subId the id of the subscription.
6082 *
6083 * @return the previously saved user selected PLMN
6084 */
6085 @Override
6086 public String getManualNetworkSelectionPlmn(int subId) {
6087 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006088 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006089 mApp, subId, "getManualNetworkSelectionPlmn");
6090
6091 final long identity = Binder.clearCallingIdentity();
6092 try {
6093 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006094 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006095 }
6096
6097 final Phone phone = getPhone(subId);
6098 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006099 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006100 }
6101 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6102 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6103 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6104 } finally {
6105 Binder.restoreCallingIdentity(identity);
6106 }
6107 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006108
6109 /**
6110 * Scans for available networks.
6111 */
6112 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006113 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6114 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6116 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006117 LocationAccessPolicy.LocationPermissionResult locationResult =
6118 LocationAccessPolicy.checkLocationPermission(mApp,
6119 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6120 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006121 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006122 .setCallingPid(Binder.getCallingPid())
6123 .setCallingUid(Binder.getCallingUid())
6124 .setMethod("getCellNetworkScanResults")
6125 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006126 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6127 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006128 .build());
6129 switch (locationResult) {
6130 case DENIED_HARD:
6131 throw new SecurityException("Not allowed to access scan results -- location");
6132 case DENIED_SOFT:
6133 return null;
6134 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135
Pengquan Menga1bb6272018-09-06 09:59:22 -07006136 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 try {
6138 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006139 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 } finally {
6142 Binder.restoreCallingIdentity(identity);
6143 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006144 }
6145
6146 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006147 * Get the call forwarding info, given the call forwarding reason.
6148 */
6149 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006150 public void getCallForwarding(int subId, int callForwardingReason,
6151 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006152 enforceReadPrivilegedPermission("getCallForwarding");
6153 long identity = Binder.clearCallingIdentity();
6154 try {
6155 if (DBG) {
6156 log("getCallForwarding: subId " + subId
6157 + " callForwardingReason" + callForwardingReason);
6158 }
Hall Liu27d24262020-09-18 19:04:59 -07006159
6160 Phone phone = getPhone(subId);
6161 if (phone == null) {
6162 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006163 callback.onError(
6164 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006165 } catch (RemoteException e) {
6166 // ignore
6167 }
6168 return;
6169 }
6170
6171 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6172 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6173 @Override
6174 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6175 try {
6176 callback.onCallForwardingInfoAvailable(info);
6177 } catch (RemoteException e) {
6178 // ignore
6179 }
6180 }
6181
6182 @Override
6183 public void onError(int error) {
6184 try {
6185 callback.onError(error);
6186 } catch (RemoteException e) {
6187 // ignore
6188 }
6189 }
6190 });
6191 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006192 } finally {
6193 Binder.restoreCallingIdentity(identity);
6194 }
6195 }
6196
6197 /**
6198 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6199 * reason, the number to forward, and the timeout before the forwarding is attempted.
6200 */
6201 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006202 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6203 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006204 enforceModifyPermission();
6205 long identity = Binder.clearCallingIdentity();
6206 try {
6207 if (DBG) {
6208 log("setCallForwarding: subId " + subId
6209 + " callForwardingInfo" + callForwardingInfo);
6210 }
Hall Liu27d24262020-09-18 19:04:59 -07006211
6212 Phone phone = getPhone(subId);
6213 if (phone == null) {
6214 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006215 callback.accept(
6216 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006217 } catch (RemoteException e) {
6218 // ignore
6219 }
6220 return;
6221 }
6222
6223 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6224 FunctionalUtils.ignoreRemoteException(callback::accept));
6225
6226 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006227 } finally {
6228 Binder.restoreCallingIdentity(identity);
6229 }
6230 }
6231
6232 /**
Hall Liu27d24262020-09-18 19:04:59 -07006233 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006234 */
6235 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006236 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006237 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006238 long identity = Binder.clearCallingIdentity();
6239 try {
Hall Liu27d24262020-09-18 19:04:59 -07006240 Phone phone = getPhone(subId);
6241 if (phone == null) {
6242 try {
6243 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6244 } catch (RemoteException e) {
6245 // ignore
6246 }
6247 return;
6248 }
SongFerngWang0e767992021-03-31 22:08:45 +08006249 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6250 PersistableBundle c = configManager.getConfigForSubId(subId);
6251 boolean requireUssd = c.getBoolean(
6252 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006253
Shuo Qian4a594052020-01-23 11:59:30 -08006254 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006255 if (requireUssd) {
6256 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6257 getSubscriptionCarrierId(subId));
6258 String newUssdCommand = "";
6259 try {
6260 newUssdCommand = carrierXmlParser.getFeature(
6261 CarrierXmlParser.FEATURE_CALL_WAITING)
6262 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6263 } catch (NullPointerException e) {
6264 loge("Failed to generate USSD number" + e);
6265 }
6266 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6267 mMainThreadHandler, callback, carrierXmlParser,
6268 CarrierXmlParser.SsEntry.SSAction.QUERY);
6269 final String ussdCommand = newUssdCommand;
6270 Executors.newSingleThreadExecutor().execute(() -> {
6271 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6272 });
6273 } else {
6274 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6275 callback::accept);
6276 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6277 }
Shuo Qian4a594052020-01-23 11:59:30 -08006278 } finally {
6279 Binder.restoreCallingIdentity(identity);
6280 }
6281 }
6282
6283 /**
Hall Liu27d24262020-09-18 19:04:59 -07006284 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006285 */
6286 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006287 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006288 enforceModifyPermission();
6289 long identity = Binder.clearCallingIdentity();
6290 try {
Hall Liu27d24262020-09-18 19:04:59 -07006291 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6292
6293 Phone phone = getPhone(subId);
6294 if (phone == null) {
6295 try {
6296 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6297 } catch (RemoteException e) {
6298 // ignore
6299 }
6300 return;
6301 }
6302
SongFerngWang0e767992021-03-31 22:08:45 +08006303 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6304 PersistableBundle c = configManager.getConfigForSubId(subId);
6305 boolean requireUssd = c.getBoolean(
6306 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006307
SongFerngWang0e767992021-03-31 22:08:45 +08006308 if (DBG) log("getCallWaitingStatus: subId " + subId);
6309 if (requireUssd) {
6310 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6311 getSubscriptionCarrierId(subId));
6312 CarrierXmlParser.SsEntry.SSAction ssAction =
6313 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6314 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6315 String newUssdCommand = "";
6316 try {
6317 newUssdCommand = carrierXmlParser.getFeature(
6318 CarrierXmlParser.FEATURE_CALL_WAITING)
6319 .makeCommand(ssAction, null);
6320 } catch (NullPointerException e) {
6321 loge("Failed to generate USSD number" + e);
6322 }
6323 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6324 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6325 final String ussdCommand = newUssdCommand;
6326 Executors.newSingleThreadExecutor().execute(() -> {
6327 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6328 });
6329 } else {
6330 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6331 FunctionalUtils.ignoreRemoteException(callback::accept));
6332
6333 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6334 }
Shuo Qian4a594052020-01-23 11:59:30 -08006335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
6338 }
6339
6340 /**
yinxub1bed742017-04-17 11:45:04 -07006341 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006342 *
yinxub1bed742017-04-17 11:45:04 -07006343 * @param subId id of the subscription
6344 * @param request contains the radio access networks with bands/channels to scan
6345 * @param messenger callback messenger for scan results or errors
6346 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006347 * @return the id of the requested scan which can be used to stop the scan.
6348 */
6349 @Override
6350 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006351 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6353 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006354 LocationAccessPolicy.LocationPermissionResult locationResult =
6355 LocationAccessPolicy.checkLocationPermission(mApp,
6356 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6357 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006358 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006359 .setCallingPid(Binder.getCallingPid())
6360 .setCallingUid(Binder.getCallingUid())
6361 .setMethod("requestNetworkScan")
6362 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006363 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6364 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006365 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006366 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006367 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6368 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006369 if (e != null) {
6370 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6371 throw e;
6372 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006373 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006374 return TelephonyScanManager.INVALID_SCAN_ID;
6375 }
6376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 }
Hall Liu912dfd32019-04-25 14:02:26 -07006378 int callingUid = Binder.getCallingUid();
6379 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006380 final long identity = Binder.clearCallingIdentity();
6381 try {
6382 return mNetworkScanRequestTracker.startNetworkScan(
6383 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006384 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006385 } finally {
6386 Binder.restoreCallingIdentity(identity);
6387 }
yinxu504e1392017-04-12 16:03:22 -07006388 }
6389
Hall Liub2ac8ef2019-02-28 15:56:23 -08006390 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006391 NetworkScanRequest request, int subId, String callingPackage) {
6392 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006393 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6394 boolean hasNetworkScanPermission =
6395 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6396 == PERMISSION_GRANTED;
6397
6398 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6399 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6400 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006401 }
6402
6403 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6404 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006405 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6406 return new SecurityException("Specific channels must not be"
6407 + " scanned without location access.");
6408 }
6409 }
6410 }
6411
Hall Liub2ac8ef2019-02-28 15:56:23 -08006412 return null;
6413 }
6414
yinxu504e1392017-04-12 16:03:22 -07006415 /**
6416 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006417 *
6418 * @param subId id of the subscription
6419 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006420 */
6421 @Override
6422 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6424 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425
Hall Liu912dfd32019-04-25 14:02:26 -07006426 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427 final long identity = Binder.clearCallingIdentity();
6428 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006429 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006430 } finally {
6431 Binder.restoreCallingIdentity(identity);
6432 }
yinxu504e1392017-04-12 16:03:22 -07006433 }
6434
6435 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006436 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006437 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006438 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006439 */
6440 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006441 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006442 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006443 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006444 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006445
6446 final long identity = Binder.clearCallingIdentity();
6447 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006448 if (DBG) log("getAllowedNetworkTypesBitmask");
6449 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6450 int networkTypesBitmask = (result != null ? result[0] : -1);
6451 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6452 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453 } finally {
6454 Binder.restoreCallingIdentity(identity);
6455 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006456 }
6457
6458 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006459 * Get the allowed network types for certain reason.
6460 *
6461 * @param subId the id of the subscription.
6462 * @param reason the reason the allowed network type change is taking place
6463 * @return the allowed network types.
6464 */
6465 @Override
6466 public long getAllowedNetworkTypesForReason(int subId,
6467 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006468 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006469 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006470 final long identity = Binder.clearCallingIdentity();
6471 try {
6472 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6473 } finally {
6474 Binder.restoreCallingIdentity(identity);
6475 }
6476 }
6477
6478 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006479 * Enable/Disable E-UTRA-NR Dual Connectivity
6480 * @param subId subscription id of the sim card
6481 * @param nrDualConnectivityState expected NR dual connectivity state
6482 * This can be passed following states
6483 * <ol>
6484 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6485 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6486 * <li>Disable NR dual connectivity and force secondary cell to be released
6487 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6488 * </ol>
6489 * @return operation result.
6490 */
6491 @Override
6492 public int setNrDualConnectivityState(int subId,
6493 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6495 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006496 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006497 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6498 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6499 }
6500
Sooraj Sasindran37444802020-08-11 10:40:43 -07006501 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6502 final long identity = Binder.clearCallingIdentity();
6503 try {
6504 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6505 nrDualConnectivityState, subId,
6506 workSource);
6507 if (DBG) log("enableNRDualConnectivity result: " + result);
6508 return result;
6509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
6512 }
6513
6514 /**
6515 * Is E-UTRA-NR Dual Connectivity enabled
6516 * @return true if dual connectivity is enabled else false
6517 */
6518 @Override
6519 public boolean isNrDualConnectivityEnabled(int subId) {
6520 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006521 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006522 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006523 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006524 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6525 return false;
6526 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006527 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6528 final long identity = Binder.clearCallingIdentity();
6529 try {
6530 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6531 null, subId, workSource);
6532 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6533 return isEnabled;
6534 } finally {
6535 Binder.restoreCallingIdentity(identity);
6536 }
6537 }
6538
6539 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006540 * Set the allowed network types of the device and
6541 * provide the reason triggering the allowed network change.
6542 *
6543 * @param subId the id of the subscription.
6544 * @param reason the reason the allowed network type change is taking place
6545 * @param allowedNetworkTypes the allowed network types.
6546 * @return true on success; false on any failure.
6547 */
6548 @Override
6549 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006550 @TelephonyManager.AllowedNetworkTypesReason int reason,
6551 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6553 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006554 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006555 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6556 return false;
6557 }
6558 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6559 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006560 return false;
6561 }
6562
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006563 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6564 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6565
6566
6567 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6568 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6569 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006570 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006571
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006572 final long identity = Binder.clearCallingIdentity();
6573 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006574 Boolean success = (Boolean) sendRequest(
6575 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6576 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6577
6578 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6579 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006580 } finally {
6581 Binder.restoreCallingIdentity(identity);
6582 }
6583 }
6584
6585 /**
Miaoa84611c2019-03-15 09:21:10 +08006586 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006587 *
Miaoa84611c2019-03-15 09:21:10 +08006588 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006589 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006590 * @hide
6591 */
6592 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006593 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006594 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006595 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006596 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597 try {
Miaoa84611c2019-03-15 09:21:10 +08006598 if (phone != null) {
6599 return phone.hasMatchedTetherApnSetting();
6600 } else {
6601 return false;
6602 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006603 } finally {
6604 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006605 }
Junda Liu475951f2014-11-07 16:45:03 -08006606 }
6607
6608 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006609 * Get the user enabled state of Mobile Data.
6610 *
6611 * TODO: remove and use isUserDataEnabled.
6612 * This can't be removed now because some vendor codes
6613 * calls through ITelephony directly while they should
6614 * use TelephonyManager.
6615 *
6616 * @return true on enabled
6617 */
6618 @Override
6619 public boolean getDataEnabled(int subId) {
6620 return isUserDataEnabled(subId);
6621 }
6622
6623 /**
6624 * Get whether mobile data is enabled per user setting.
6625 *
6626 * There are other factors deciding whether mobile data is actually enabled, but they are
6627 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006628 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006629 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6630 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006631 *
6632 * @return {@code true} if data is enabled else {@code false}
6633 */
6634 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006635 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006636 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006637 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006638 try {
6639 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6640 functionName);
6641 } catch (Exception e) {
6642 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6643 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006644 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006646 mApp, subId, functionName);
6647
Robert Greenwalt646120a2014-05-23 11:54:03 -07006648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649
6650 final long identity = Binder.clearCallingIdentity();
6651 try {
6652 int phoneId = mSubscriptionController.getPhoneId(subId);
6653 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6654 Phone phone = PhoneFactory.getPhone(phoneId);
6655 if (phone != null) {
6656 boolean retVal = phone.isUserDataEnabled();
6657 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6658 return retVal;
6659 } else {
6660 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6661 return false;
6662 }
6663 } finally {
6664 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006665 }
6666 }
6667
6668 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006669 * Checks if the device is capable of mobile data by considering whether whether the
6670 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6671 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006672 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006673 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006674 */
6675 @Override
6676 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006677 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006678 try {
6679 try {
6680 mApp.enforceCallingOrSelfPermission(
6681 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006682 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006683 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006684 try {
6685 mApp.enforceCallingOrSelfPermission(
6686 android.Manifest.permission.READ_PHONE_STATE,
6687 functionName);
6688 } catch (Exception e2) {
6689 mApp.enforceCallingOrSelfPermission(
6690 permission.READ_BASIC_PHONE_STATE, functionName);
6691 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006692 }
6693 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006694 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696
6697 final long identity = Binder.clearCallingIdentity();
6698 try {
6699 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 Phone phone = PhoneFactory.getPhone(phoneId);
6701 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006702 boolean retVal;
6703 if (phone.isUsingNewDataStack()) {
6704 retVal = phone.getDataNetworkController().getDataSettingsManager()
6705 .isDataEnabled();
6706 } else {
6707 retVal = phone.getDataEnabledSettings().isDataEnabled();
6708 }
6709 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006710 return retVal;
6711 } else {
6712 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6713 return false;
6714 }
6715 } finally {
6716 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006717 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006718 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006719
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006720 /**
6721 * Check if data is enabled for a specific reason
6722 * @param subId Subscription index
6723 * @param reason the reason the data enable change is taking place
6724 * @return {@code true} if the overall data is enabled; {@code false} if not.
6725 */
6726 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006727 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006728 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006729 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006730 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006731 try {
6732 mApp.enforceCallingOrSelfPermission(
6733 android.Manifest.permission.ACCESS_NETWORK_STATE,
6734 functionName);
6735 } catch (Exception e) {
6736 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6737 functionName);
6738 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006739 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006740 try {
6741 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006742 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006743 } catch (Exception e2) {
6744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006745 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006746 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006747 }
6748
6749
6750 final long identity = Binder.clearCallingIdentity();
6751 try {
6752 int phoneId = mSubscriptionController.getPhoneId(subId);
6753 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006754 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006755 + " reason=" + reason);
6756 }
6757 Phone phone = PhoneFactory.getPhone(phoneId);
6758 if (phone != null) {
6759 boolean retVal;
6760 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6761 retVal = phone.isUserDataEnabled();
6762 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006763 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006764 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006765 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006766 return retVal;
6767 } else {
6768 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006769 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006770 + subId + " retVal=false");
6771 }
6772 return false;
6773 }
6774 } finally {
6775 Binder.restoreCallingIdentity(identity);
6776 }
6777 }
6778
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006779 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006780 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006781 if (uid == Process.PHONE_UID) {
6782 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6783 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006784 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6785 }
6786
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006787 //load access rules from carrier configs, and check those as well: b/139133814
6788 SubscriptionController subController = SubscriptionController.getInstance();
6789 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6790 || subController == null) return privilegeFromSim;
6791
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006792 PackageManager pkgMgr = phone.getContext().getPackageManager();
6793 String[] packages = pkgMgr.getPackagesForUid(uid);
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 for (String pkg : packages) {
6807 if (subManager.canManageSubscription(subInfo, pkg)) {
6808 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6809 }
6810 }
6811 return privilegeFromSim;
6812 } finally {
6813 Binder.restoreCallingIdentity(identity);
6814 }
6815 }
6816
6817 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6818 String pkgName) {
6819 //load access rules from carrier configs, and check those as well: b/139133814
6820 SubscriptionController subController = SubscriptionController.getInstance();
6821 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6822 || subController == null) return privilegeFromSim;
6823
6824 final long identity = Binder.clearCallingIdentity();
6825 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006826 int subId = phone.getSubId();
6827 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6828 // A test override is in place for the privileges for this subId, so don't try to
6829 // read the subscription privileges.
6830 return privilegeFromSim;
6831 }
6832 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006833 SubscriptionManager subManager = (SubscriptionManager)
6834 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6835 return subManager.canManageSubscription(subInfo, pkgName)
6836 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6837 } finally {
6838 Binder.restoreCallingIdentity(identity);
6839 }
6840 }
6841
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006842 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006843 public int getCarrierPrivilegeStatus(int subId) {
6844 final Phone phone = getPhone(subId);
6845 if (phone == null) {
6846 loge("getCarrierPrivilegeStatus: Invalid subId");
6847 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6848 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006849 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6850 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006851 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006852 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6853 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006854
6855 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006856 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006857 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006858 }
Junda Liu29340342014-07-10 15:23:27 -07006859
6860 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006861 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006862 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006863 final Phone phone = getPhone(subId);
6864 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006865 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006866 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6867 }
6868 UiccProfile profile =
6869 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6870 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006871 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006872 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6873 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006874 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006875 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006876 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006877 }
6878
6879 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006880 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006881 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006882 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006883 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006884 }
6885
6886 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006887 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6888 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006889 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006890 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6891 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006892 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006893 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006894 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006895 }
6896
6897 @Override
6898 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006899 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006900 if (TextUtils.isEmpty(pkgName))
6901 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006902 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6903 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006904 UiccPort port = UiccController.getInstance().getUiccPort(i);
6905 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006906 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006907 continue;
6908 }
6909
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006910 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006911 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006912 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006913 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6914 break;
6915 }
6916 }
6917
6918 return result;
Junda Liu29340342014-07-10 15:23:27 -07006919 }
Derek Tan89e89d42014-07-08 17:00:10 -07006920
6921 @Override
Junda Liue64de782015-04-16 17:19:16 -07006922 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006923 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006924 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6925 loge("phoneId " + phoneId + " is not valid.");
6926 return null;
6927 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006928 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6929 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006930 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006931 return null ;
6932 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006933 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006934 }
6935
Amith Yamasani6e118872016-02-19 12:53:51 -08006936 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006937 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006938 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006939 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006940 List<String> privilegedPackages = new ArrayList<>();
6941 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006942 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006943 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006944 if (port != null) {
6945 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006946 if (packages == null) {
6947 // Only check packages in user 0 for now
6948 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006949 PackageManager.MATCH_DISABLED_COMPONENTS
6950 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006951 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006952 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006953 }
6954 for (int p = packages.size() - 1; p >= 0; p--) {
6955 PackageInfo pkgInfo = packages.get(p);
6956 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006957 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6958 port.getCarrierPrivilegeStatus(pkgInfo),
6959 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006960 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006961 privilegedPackages.add(pkgInfo.packageName);
6962 }
6963 }
6964 }
6965 }
6966 return privilegedPackages;
6967 }
6968
chen xuf7e9fe82019-05-09 19:31:02 -07006969 @Override
6970 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006971 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6972
6973 final long identity = Binder.clearCallingIdentity();
6974
chen xuf7e9fe82019-05-09 19:31:02 -07006975 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006976 try {
6977 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6978 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6979 }
6980 } finally {
6981 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006982 }
6983 return privilegedPackages;
6984 }
6985
Wink Savilleb564aae2014-10-23 10:18:09 -07006986 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006987 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006988 UiccPort port = phone == null ? null : phone.getUiccPort();
6989 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006990 return null;
6991 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006992 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006993 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006994 return null;
6995 }
6996 return iccId;
6997 }
6998
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006999 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007000 public void setCallComposerStatus(int subId, int status) {
7001 enforceModifyPermission();
7002
7003 final long identity = Binder.clearCallingIdentity();
7004 try {
7005 Phone phone = getPhone(subId);
7006 if (phone != null) {
7007 Phone defaultPhone = phone.getImsPhone();
7008 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7009 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7010 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007011 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7012 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007013 }
7014 }
Shuo Qian284ae752020-12-22 19:10:14 -08007015 } catch (ImsException e) {
7016 throw new ServiceSpecificException(e.getCode());
7017 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007018 Binder.restoreCallingIdentity(identity);
7019 }
7020 }
7021
7022 @Override
7023 public int getCallComposerStatus(int subId) {
7024 enforceReadPrivilegedPermission("getCallComposerStatus");
7025
7026 final long identity = Binder.clearCallingIdentity();
7027 try {
7028 Phone phone = getPhone(subId);
7029 if (phone != null) {
7030 Phone defaultPhone = phone.getImsPhone();
7031 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7032 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7033 return imsPhone.getCallComposerStatus();
7034 }
7035 }
7036 } finally {
7037 Binder.restoreCallingIdentity(identity);
7038 }
7039 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7040 }
7041
7042 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007043 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7044 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007045 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007046 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 final long identity = Binder.clearCallingIdentity();
7049 try {
7050 final String iccId = getIccId(subId);
7051 final Phone phone = getPhone(subId);
7052 if (phone == null) {
7053 return false;
7054 }
7055 final String subscriberId = phone.getSubscriberId();
7056
7057 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007058 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 + subscriberId + " to " + number);
7060 }
7061
7062 if (TextUtils.isEmpty(iccId)) {
7063 return false;
7064 }
7065
7066 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7067
7068 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7069 if (alphaTag == null) {
7070 editor.remove(alphaTagPrefKey);
7071 } else {
7072 editor.putString(alphaTagPrefKey, alphaTag);
7073 }
7074
7075 // Record both the line number and IMSI for this ICCID, since we need to
7076 // track all merged IMSIs based on line number
7077 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7078 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7079 if (number == null) {
7080 editor.remove(numberPrefKey);
7081 editor.remove(subscriberPrefKey);
7082 } else {
7083 editor.putString(numberPrefKey, number);
7084 editor.putString(subscriberPrefKey, subscriberId);
7085 }
7086
7087 editor.commit();
7088 return true;
7089 } finally {
7090 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007091 }
Derek Tan7226c842014-07-02 17:42:23 -07007092 }
7093
7094 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007095 public String getLine1NumberForDisplay(int subId, String callingPackage,
7096 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007097 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007099 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007100 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007101 return null;
7102 }
Derek Tan97ebb422014-09-05 16:55:38 -07007103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 final long identity = Binder.clearCallingIdentity();
7105 try {
7106 String iccId = getIccId(subId);
7107 if (iccId != null) {
7108 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7109 if (DBG_MERGE) {
7110 log("getLine1NumberForDisplay returning "
7111 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7112 }
7113 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007114 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7116 return null;
7117 } finally {
7118 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007119 }
Derek Tan7226c842014-07-02 17:42:23 -07007120 }
7121
7122 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007123 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7124 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007125 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007126 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007127 return null;
7128 }
Derek Tan97ebb422014-09-05 16:55:38 -07007129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130 final long identity = Binder.clearCallingIdentity();
7131 try {
7132 String iccId = getIccId(subId);
7133 if (iccId != null) {
7134 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7135 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7136 }
7137 return null;
7138 } finally {
7139 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007140 }
Derek Tan7226c842014-07-02 17:42:23 -07007141 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007142
7143 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007144 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7145 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007146 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7147 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007149 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007150 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007151 return null;
7152 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007153
Jordan Liub49b04b2019-05-06 14:45:15 -07007154 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7155 // the process, where TelephonyManager was instantiated.
7156 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007157 final long identity = Binder.clearCallingIdentity();
7158 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007159 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007160 final TelephonyManager tele = TelephonyManager.from(context);
7161 final SubscriptionManager sub = SubscriptionManager.from(context);
7162
7163 // Figure out what subscribers are currently active
7164 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007165
Jordan Liub49b04b2019-05-06 14:45:15 -07007166 // Only consider subs which match the current subId
7167 // This logic can be simplified. See b/131189269 for progress.
7168 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007169 activeSubscriberIds.add(tele.getSubscriberId(subId));
7170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171
7172 // First pass, find a number override for an active subscriber
7173 String mergeNumber = null;
7174 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7175 for (String key : prefs.keySet()) {
7176 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7177 final String subscriberId = (String) prefs.get(key);
7178 if (activeSubscriberIds.contains(subscriberId)) {
7179 final String iccId = key.substring(
7180 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7181 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7182 mergeNumber = (String) prefs.get(numberKey);
7183 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007184 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185 + " for active subscriber " + subscriberId);
7186 }
7187 if (!TextUtils.isEmpty(mergeNumber)) {
7188 break;
7189 }
7190 }
7191 }
7192 }
7193
7194 // Shortcut when no active merged subscribers
7195 if (TextUtils.isEmpty(mergeNumber)) {
7196 return null;
7197 }
7198
7199 // Second pass, find all subscribers under that line override
7200 final ArraySet<String> result = new ArraySet<>();
7201 for (String key : prefs.keySet()) {
7202 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7203 final String number = (String) prefs.get(key);
7204 if (mergeNumber.equals(number)) {
7205 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7206 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7207 final String subscriberId = (String) prefs.get(subscriberKey);
7208 if (!TextUtils.isEmpty(subscriberId)) {
7209 result.add(subscriberId);
7210 }
7211 }
7212 }
7213 }
7214
7215 final String[] resultArray = result.toArray(new String[result.size()]);
7216 Arrays.sort(resultArray);
7217 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007218 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007219 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7220 }
7221 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007222 } finally {
7223 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007224 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007225 }
7226
7227 @Override
zoey chen38003472019-12-13 17:16:31 +08007228 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7229 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007230
7231 final long identity = Binder.clearCallingIdentity();
7232 try {
7233 final TelephonyManager telephonyManager = mApp.getSystemService(
7234 TelephonyManager.class);
7235 String subscriberId = telephonyManager.getSubscriberId(subId);
7236 if (subscriberId == null) {
7237 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007238 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007239 + subId);
7240 }
7241 return null;
7242 }
7243
7244 final SubscriptionInfo info = SubscriptionController.getInstance()
7245 .getSubscriptionInfo(subId);
7246 final ParcelUuid groupUuid = info.getGroupUuid();
7247 // If it doesn't belong to any group, return just subscriberId of itself.
7248 if (groupUuid == null) {
7249 return new String[]{subscriberId};
7250 }
7251
7252 // Get all subscriberIds from the group.
7253 final List<String> mergedSubscriberIds = new ArrayList<>();
7254 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007255 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007256 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007257 for (SubscriptionInfo subInfo : groupInfos) {
7258 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7259 if (subscriberId != null) {
7260 mergedSubscriberIds.add(subscriberId);
7261 }
7262 }
7263
7264 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7265 } finally {
7266 Binder.restoreCallingIdentity(identity);
7267
7268 }
7269 }
7270
7271 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007272 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007273 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007274 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007275
7276 final long identity = Binder.clearCallingIdentity();
7277 try {
7278 final Phone phone = getPhone(subId);
7279 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7280 } finally {
7281 Binder.restoreCallingIdentity(identity);
7282 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007283 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007284
7285 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007286 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007287 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7288 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007289 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7290 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007291
7292 final long identity = Binder.clearCallingIdentity();
7293 try {
7294 final Phone phone = getPhone(subId);
7295 if (phone == null) {
7296 return false;
7297 }
7298 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7299 cdmaNonRoamingList);
7300 } finally {
7301 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007302 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007303 }
7304
7305 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007306 @Deprecated
7307 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7308 enforceModifyPermission();
7309
7310 int returnValue = 0;
7311 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007312 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007313 if(result.exception == null) {
7314 if (result.result != null) {
7315 byte[] responseData = (byte[])(result.result);
7316 if(responseData.length > oemResp.length) {
7317 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7318 responseData.length + "bytes. Buffer Size is " +
7319 oemResp.length + "bytes.");
7320 }
7321 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7322 returnValue = responseData.length;
7323 }
7324 } else {
7325 CommandException ex = (CommandException) result.exception;
7326 returnValue = ex.getCommandError().ordinal();
7327 if(returnValue > 0) returnValue *= -1;
7328 }
7329 } catch (RuntimeException e) {
7330 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7331 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7332 if(returnValue > 0) returnValue *= -1;
7333 }
7334
7335 return returnValue;
7336 }
7337
7338 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007339 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007340 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007341 try {
7342 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007343 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007344 mApp, phone.getSubId(), "getRadioAccessFamily");
7345 } catch (SecurityException e) {
7346 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7347 throw e;
7348 }
chen xub97461a2018-10-26 14:17:57 -07007349 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007350 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007351 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007352 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007353 final long identity = Binder.clearCallingIdentity();
7354 try {
chen xub97461a2018-10-26 14:17:57 -07007355 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007356 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007357 mApp, phone.getSubId(), "getRadioAccessFamily");
7358 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007359 } finally {
7360 Binder.restoreCallingIdentity(identity);
7361 }
chen xub97461a2018-10-26 14:17:57 -07007362 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007363 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007364
7365 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007366 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007367 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007368 try {
7369 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7370 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007371 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007372 }
7373 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007374 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007375 }
7376 RoleManager rm = mApp.getSystemService(RoleManager.class);
7377 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7378 if (!dialerRoleHolders.contains(callingPackage)) {
7379 throw new SecurityException("App must be the dialer role holder to"
7380 + " upload a call composer pic");
7381 }
7382
7383 Executors.newSingleThreadExecutor().execute(() -> {
7384 ByteArrayOutputStream output = new ByteArrayOutputStream(
7385 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7386 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7387 boolean readUntilEnd = false;
7388 int totalBytesRead = 0;
7389 byte[] buffer = new byte[16 * 1024];
7390 while (true) {
7391 int numRead;
7392 try {
7393 numRead = input.read(buffer);
7394 } catch (IOException e) {
7395 try {
7396 fd.checkError();
7397 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7398 null);
7399 } catch (IOException e1) {
7400 // This means that the other side closed explicitly with an error. If this
7401 // happens, log and ignore.
7402 loge("Remote end of call composer picture pipe closed: " + e1);
7403 }
7404 break;
7405 }
7406 if (numRead == -1) {
7407 readUntilEnd = true;
7408 break;
7409 }
7410 totalBytesRead += numRead;
7411 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7412 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7413 try {
7414 input.close();
7415 } catch (IOException e) {
7416 // ignore
7417 }
7418 break;
7419 }
7420 output.write(buffer, 0, numRead);
7421 }
7422 // Generally, the remote end will close the file descriptors. The only case where we
7423 // close is above, where the picture size is too big.
7424
7425 try {
7426 fd.checkError();
7427 } catch (IOException e) {
7428 loge("Remote end for call composer closed with an error: " + e);
7429 return;
7430 }
7431
Hall Liuaa4211e2021-01-20 15:43:39 -08007432 if (!readUntilEnd) {
7433 loge("Did not finish reading entire image; aborting");
7434 return;
7435 }
Hall Liu82694d52020-12-11 18:22:04 -08007436
Hall Liuaa4211e2021-01-20 15:43:39 -08007437 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7438 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7439 new CallComposerPictureTransfer.Factory() {},
7440 imageData,
7441 (result) -> {
7442 if (result.first != null) {
7443 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7444 Bundle outputResult = new Bundle();
7445 outputResult.putParcelable(
7446 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7447 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7448 outputResult);
7449 } else {
7450 callback.send(result.second, null);
7451 }
7452 }
7453 );
Hall Liu82694d52020-12-11 18:22:04 -08007454 });
7455 }
7456
7457 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007458 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007459 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007460 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461
7462 final long identity = Binder.clearCallingIdentity();
7463 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007464 ImsManager.getInstance(defaultPhone.getContext(),
7465 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 } finally {
7467 Binder.restoreCallingIdentity(identity);
7468 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007469 }
7470
7471 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007472 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007473 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7475 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007476 return false;
7477 }
Svet Ganovb320e182015-04-16 12:30:10 -07007478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 final long identity = Binder.clearCallingIdentity();
7480 try {
7481 // Check the user preference and the system-level IMS setting. Even if the user has
7482 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7483 // In the long run, we may instead need to check if there exists a connection service
7484 // which can support video calling.
7485 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007486 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 return imsManager.isVtEnabledByPlatform()
7488 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7489 && imsManager.isVtEnabledByUser();
7490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007493 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007494
Andrew Leea1239f22015-03-02 17:44:07 -08007495 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007496 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7497 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007499 mApp, subId, callingPackage, callingFeatureId,
7500 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 return false;
7502 }
7503
7504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 CarrierConfigManager configManager =
7507 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007508 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
7512 }
Andrew Leea1239f22015-03-02 17:44:07 -08007513 }
7514
7515 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007516 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007518 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007519 return false;
7520 }
7521
7522 final long identity = Binder.clearCallingIdentity();
7523 try {
7524 CarrierConfigManager configManager =
7525 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007526 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
Andrew Leea1239f22015-03-02 17:44:07 -08007531 }
7532
Andrew Lee9431b832015-03-09 18:46:45 -07007533 @Override
7534 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007535 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007536 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007537 }
7538
7539 @Override
7540 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 final long identity = Binder.clearCallingIdentity();
7542 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007543 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
Andrew Lee9431b832015-03-09 18:46:45 -07007547 }
7548
Hall Liuf6668912018-10-31 17:05:23 -07007549 /**
7550 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7551 * support for the feature and device firmware support.
7552 *
7553 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7554 */
7555 @Override
7556 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007558 final Phone phone = getPhone(subscriptionId);
7559 if (phone == null) {
7560 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7561 return false;
7562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007564 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7566 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007567 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568 return isCarrierSupported && isDeviceSupported;
7569 } finally {
7570 Binder.restoreCallingIdentity(identity);
7571 }
Hall Liu98187582018-01-22 19:15:32 -08007572 }
7573
Hall Liuf6668912018-10-31 17:05:23 -07007574 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007575 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7576 * RTT setting, will return true if the device and carrier both support RTT.
7577 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007578 */
7579 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580 final long identity = Binder.clearCallingIdentity();
7581 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007582 boolean isRttSupported = isRttSupported(subscriptionId);
7583 boolean isUserRttSettingOn = Settings.Secure.getInt(
7584 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7585 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7586 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7587 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007588 } finally {
7589 Binder.restoreCallingIdentity(identity);
7590 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007591 }
7592
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007593 @Deprecated
7594 @Override
7595 public String getDeviceId(String callingPackage) {
7596 return getDeviceIdWithFeature(callingPackage, null);
7597 }
7598
Sanket Padawe7310cc72015-01-14 09:53:20 -08007599 /**
7600 * Returns the unique device ID of phone, for example, the IMEI for
7601 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7602 *
7603 * <p>Requires Permission:
7604 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7605 */
7606 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007607 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007608 try {
7609 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7610 } catch (SecurityException se) {
7611 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7612 throw new SecurityException("Package " + callingPackage + " does not belong to "
7613 + Binder.getCallingUid());
7614 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007615 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007616 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007617 return null;
7618 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007619 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007620 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007621 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007622 return null;
7623 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007624
7625 final long identity = Binder.clearCallingIdentity();
7626 try {
7627 return phone.getDeviceId();
7628 } finally {
7629 Binder.restoreCallingIdentity(identity);
7630 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007631 }
7632
Ping Sunc67b7c22016-03-02 19:16:45 +08007633 /**
7634 * {@hide}
7635 * Returns the IMS Registration Status on a particular subid
7636 *
7637 * @param subId
7638 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007639 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007640 Phone phone = getPhone(subId);
7641 if (phone != null) {
7642 return phone.isImsRegistered();
7643 } else {
7644 return false;
7645 }
7646 }
7647
Santos Cordon7a1885b2015-02-03 11:15:19 -08007648 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007649 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007650 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007652 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007653 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7654 }
7655 final long identity = Binder.clearCallingIdentity();
7656 try {
7657 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
7660 }
7661 }
7662
7663 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007664 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007665 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007666 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007667 mApp,
7668 subscriptionId,
7669 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007670 final long identity = Binder.clearCallingIdentity();
7671 try {
7672 Phone phone = getPhone(subscriptionId);
7673 if (phone == null) {
7674 return null;
7675 }
7676 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7677 } finally {
7678 Binder.restoreCallingIdentity(identity);
7679 }
7680 }
7681
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007682 /**
7683 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007684 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007685 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 final long identity = Binder.clearCallingIdentity();
7687 try {
7688 Phone phone = getPhone(subId);
7689 if (phone != null) {
7690 return phone.isWifiCallingEnabled();
7691 } else {
7692 return false;
7693 }
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007696 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007697 }
7698
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007699 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007700 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007701 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007702 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007703 final long identity = Binder.clearCallingIdentity();
7704 try {
7705 Phone phone = getPhone(subId);
7706 if (phone != null) {
7707 return phone.isVideoEnabled();
7708 } else {
7709 return false;
7710 }
7711 } finally {
7712 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007713 }
7714 }
7715
7716 /**
7717 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7718 * defined in {@link ImsRegistrationImplBase}.
7719 */
7720 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007721 final long identity = Binder.clearCallingIdentity();
7722 try {
7723 Phone phone = getPhone(subId);
7724 if (phone != null) {
7725 return phone.getImsRegistrationTech();
7726 } else {
7727 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7728 }
7729 } finally {
7730 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007731 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007732 }
7733
Stuart Scott8eef64f2015-04-08 15:13:54 -07007734 @Override
7735 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007736 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007737 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7738 return;
7739 }
Kai Shif70f46f2021-03-03 13:59:46 -08007740 Phone defaultPhone = getDefaultPhone();
7741 if (defaultPhone != null) {
7742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7743 mApp, getDefaultPhone().getSubId(), "factoryReset");
7744 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007745 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007746
Svet Ganovcc087f82015-05-12 20:35:54 -07007747 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007748 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7749 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007750 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007751 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007752 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007753 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007754 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007755 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007756 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007757 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007758 // There has been issues when Sms raw table somehow stores orphan
7759 // fragments. They lead to garbled message when new fragments come
7760 // in and combined with those stale ones. In case this happens again,
7761 // user can reset all network settings which will clean up this table.
7762 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007763 // Clean up IMS settings as well here.
7764 int slotId = getSlotIndex(subId);
7765 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7766 ImsManager.getInstance(mApp, slotId).factoryReset();
7767 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007768
Kai Shif70f46f2021-03-03 13:59:46 -08007769 if (defaultPhone == null) {
7770 return;
7771 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007772 // Erase modem config if erase modem on network setting is enabled.
7773 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7774 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7775 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007776 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007777 }
Kai Shif70f46f2021-03-03 13:59:46 -08007778
7779 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007780 } finally {
7781 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007782 }
7783 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007784
SongFerngWangfd89b102021-05-27 22:44:54 +08007785 @VisibleForTesting
7786 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7787 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7788 return;
7789 }
7790 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7791 RILConstants.PREFERRED_NETWORK_MODE);
7792 SubscriptionManager.setSubscriptionProperty(subId,
7793 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7794 "user=" + defaultNetworkType);
7795 phone.loadAllowedNetworksFromSubscriptionDatabase();
7796 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7797 defaultNetworkType, null);
7798 }
7799
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007800 private void cleanUpSmsRawTable(Context context) {
7801 ContentResolver resolver = context.getContentResolver();
7802 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7803 resolver.delete(uri, null, null);
7804 }
7805
Narayan Kamath1c496c22015-04-16 14:40:19 +01007806 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007807 public String getSimLocaleForSubscriber(int subId) {
7808 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7809 final Phone phone = getPhone(subId);
7810 if (phone == null) {
7811 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007812 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 final long identity = Binder.clearCallingIdentity();
7815 try {
chen xu5d3637b2019-01-21 23:31:38 -08007816 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007817 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007818 if (info == null) {
7819 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7820 return null;
7821 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822 // Try and fetch the locale from the carrier properties or from the SIM language
7823 // preferences (EF-PL and EF-LI)...
7824 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007826 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7827 if (localeFromDefaultSim != null) {
7828 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7829 if (DBG) log("Using locale from subId: " + subId + " locale: "
7830 + localeFromDefaultSim);
7831 return localeFromDefaultSim.toLanguageTag();
7832 } else {
7833 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007834 }
7835 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007836
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837 // The SIM language preferences only store a language (e.g. fr = French), not an
7838 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7839 // the SIM and carrier preferences does not include a country we add the country
7840 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007841 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007842 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007843 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007844 return mccLocale.toLanguageTag();
7845 }
7846
7847 if (DBG) log("No locale found - returning null");
7848 return null;
7849 } finally {
7850 Binder.restoreCallingIdentity(identity);
7851 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007852 }
7853
7854 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007855 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007856 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007857 }
7858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007859 /**
7860 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7861 */
7862 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007863 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007864 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007865 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007866
Chenjie Yu1ba97252018-01-11 18:16:20 -08007867 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007868 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007869
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007870 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007871 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7872 * representing the state of the modem.
7873 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007874 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7875 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007876 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007877 */
7878 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007879 public void requestModemActivityInfo(ResultReceiver result) {
7880 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007881 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007882
7883 final long identity = Binder.clearCallingIdentity();
7884 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007885 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007886 } finally {
7887 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007888 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007889 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007890
Siddharth Rayb8114062018-06-17 15:02:38 -07007891 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7892 // less than total activity duration.
7893 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7894 if (info == null) {
7895 return false;
7896 }
7897 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007898 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7899 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7900
Siddharth Rayb8114062018-06-17 15:02:38 -07007901 return (info.isValid()
7902 && (info.getSleepTimeMillis() <= activityDurationMs)
7903 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007904 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007905 && (totalTxTimeMs <= activityDurationMs));
7906 }
7907
Jack Yu85bd38a2015-11-09 11:34:32 -08007908 /**
7909 * {@hide}
7910 * Returns the service state information on specified subscription.
7911 */
7912 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007913 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7914 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007916 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007917 return null;
7918 }
7919
Hall Liuf19c44f2018-11-27 14:38:17 -08007920 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7921 LocationAccessPolicy.checkLocationPermission(mApp,
7922 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7923 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007924 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007925 .setCallingPid(Binder.getCallingPid())
7926 .setCallingUid(Binder.getCallingUid())
7927 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007928 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007929 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007930 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7931 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007932 .build());
7933
7934 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7935 LocationAccessPolicy.checkLocationPermission(mApp,
7936 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7937 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007938 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007939 .setCallingPid(Binder.getCallingPid())
7940 .setCallingUid(Binder.getCallingUid())
7941 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007942 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007943 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007944 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7945 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007946 .build());
7947 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7948 boolean hasFinePermission =
7949 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7950 boolean hasCoarsePermission =
7951 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7952
Jack Yu479f40e2020-10-27 21:29:25 -07007953 final Phone phone = getPhone(subId);
7954 if (phone == null) {
7955 return null;
7956 }
7957
Jordan Liu0f2bc442020-11-18 16:47:37 -08007958 final long identity = Binder.clearCallingIdentity();
7959
Jack Yu479f40e2020-10-27 21:29:25 -07007960 boolean isCallingPackageDataService = phone.getDataServicePackages()
7961 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007962 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007963 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7964 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7965 Rlog.d(LOG_TAG,
7966 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7967 return null;
7968 }
7969
Hall Liuf19c44f2018-11-27 14:38:17 -08007970 ServiceState ss = phone.getServiceState();
7971
7972 // Scrub out the location info in ServiceState depending on what level of access
7973 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007974 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007975 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7976 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007977 } finally {
7978 Binder.restoreCallingIdentity(identity);
7979 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007980 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007981
7982 /**
7983 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7984 *
7985 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7986 * voicemail ringtone.
7987 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7988 * PhoneAccount.
7989 */
7990 @Override
7991 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992 final long identity = Binder.clearCallingIdentity();
7993 try {
7994 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7995 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007996 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007999 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8000 } finally {
8001 Binder.restoreCallingIdentity(identity);
8002 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008003 }
8004
8005 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008006 * Sets the per-account voicemail ringtone.
8007 *
8008 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8009 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8010 *
8011 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8012 * voicemail ringtone.
8013 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8014 * PhoneAccount.
8015 */
8016 @Override
8017 public void setVoicemailRingtoneUri(String callingPackage,
8018 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008019 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008020 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008021 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8022 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8024 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8025 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008027
8028 final long identity = Binder.clearCallingIdentity();
8029 try {
8030 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8031 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008032 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008033 }
8034 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8035 } finally {
8036 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008037 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008038 }
8039
8040 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008041 * Returns whether vibration is set for voicemail notification in Phone settings.
8042 *
8043 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8044 * voicemail vibration setting.
8045 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8046 */
8047 @Override
8048 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049 final long identity = Binder.clearCallingIdentity();
8050 try {
8051 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8052 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008053 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8057 } finally {
8058 Binder.restoreCallingIdentity(identity);
8059 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008060 }
8061
Youhan Wange64578a2016-05-02 15:32:42 -07008062 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008063 * Sets the per-account voicemail vibration.
8064 *
8065 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8066 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8067 *
8068 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8069 * voicemail vibration setting.
8070 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8071 * specific PhoneAccount.
8072 */
8073 @Override
8074 public void setVoicemailVibrationEnabled(String callingPackage,
8075 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008076 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008077 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008078 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8079 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8081 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8082 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008083 }
8084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085 final long identity = Binder.clearCallingIdentity();
8086 try {
8087 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8088 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008089 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 }
8091 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8092 } finally {
8093 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008094 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008095 }
8096
8097 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008098 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8099 *
8100 * @throws SecurityException if the caller does not have the required permission
8101 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008102 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008103 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008104 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008105 }
8106
8107 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008108 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8109 * permission.
8110 *
8111 * @throws SecurityException if the caller does not have the required permission
8112 */
8113 private void enforceSendSmsPermission() {
8114 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8115 }
8116
8117 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008118 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008119 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008120 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008121 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008122 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008123 final long identity = Binder.clearCallingIdentity();
8124 try {
8125 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008126 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127 if (componentName == null) {
8128 throw new SecurityException(
8129 "Caller not current active visual voicemail package[null]");
8130 }
8131 String vvmPackage = componentName.getPackageName();
8132 if (!callingPackage.equals(vvmPackage)) {
8133 throw new SecurityException("Caller not current active visual voicemail package["
8134 + vvmPackage + "]");
8135 }
8136 } finally {
8137 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008138 }
8139 }
8140
8141 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008142 * Return the application ID for the app type.
8143 *
8144 * @param subId the subscription ID that this request applies to.
8145 * @param appType the uicc app type.
8146 * @return Application ID for specificied app type, or null if no uicc.
8147 */
8148 @Override
8149 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008150 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008151 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152
8153 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008154 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155 if (phone == null) {
8156 return null;
8157 }
8158 String aid = null;
8159 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008160 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161 .getApplicationByType(appType).getAid();
8162 } catch (Exception e) {
8163 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8164 }
8165 return aid;
8166 } finally {
8167 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008168 }
Youhan Wange64578a2016-05-02 15:32:42 -07008169 }
8170
Youhan Wang4001d252016-05-11 10:29:41 -07008171 /**
8172 * Return the Electronic Serial Number.
8173 *
8174 * @param subId the subscription ID that this request applies to.
8175 * @return ESN or null if error.
8176 */
8177 @Override
8178 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008179 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008180 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008181
8182 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008183 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184 if (phone == null) {
8185 return null;
8186 }
8187 String esn = null;
8188 try {
8189 esn = phone.getEsn();
8190 } catch (Exception e) {
8191 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8192 }
8193 return esn;
8194 } finally {
8195 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008196 }
Youhan Wang4001d252016-05-11 10:29:41 -07008197 }
8198
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008199 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008200 * Return the Preferred Roaming List Version.
8201 *
8202 * @param subId the subscription ID that this request applies to.
8203 * @return PRLVersion or null if error.
8204 */
8205 @Override
8206 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008207 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008208 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209
8210 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008211 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008212 if (phone == null) {
8213 return null;
8214 }
8215 String cdmaPrlVersion = null;
8216 try {
8217 cdmaPrlVersion = phone.getCdmaPrlVersion();
8218 } catch (Exception e) {
8219 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8220 }
8221 return cdmaPrlVersion;
8222 } finally {
8223 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008224 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008225 }
8226
8227 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008228 * Get snapshot of Telephony histograms
8229 * @return List of Telephony histograms
8230 * @hide
8231 */
8232 @Override
8233 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8235 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236
8237 final long identity = Binder.clearCallingIdentity();
8238 try {
8239 return RIL.getTelephonyRILTimingHistograms();
8240 } finally {
8241 Binder.restoreCallingIdentity(identity);
8242 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008243 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008244
8245 /**
8246 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008247 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8248 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008249 * Require system privileges. In the future we may add this to carrier APIs.
8250 *
Michele Berionne482f8202018-11-27 18:57:59 -08008251 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008252 */
8253 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008254 @TelephonyManager.SetCarrierRestrictionResult
8255 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008256 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008257 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008258
Michele Berionne482f8202018-11-27 18:57:59 -08008259 if (carrierRestrictionRules == null) {
8260 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008261 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008263 final long identity = Binder.clearCallingIdentity();
8264 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008265 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008266 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008267 } finally {
8268 Binder.restoreCallingIdentity(identity);
8269 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008270 }
8271
8272 /**
8273 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008274 * Get the allowed carrier list and the excluded carrier list, including the priority between
8275 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008276 * Require system privileges. In the future we may add this to carrier APIs.
8277 *
Michele Berionne482f8202018-11-27 18:57:59 -08008278 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008279 */
8280 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008281 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008282 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008283 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008284
8285 final long identity = Binder.clearCallingIdentity();
8286 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008287 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8288 if (response instanceof CarrierRestrictionRules) {
8289 return (CarrierRestrictionRules) response;
8290 }
8291 // Response is an Exception of some kind,
8292 // which is signalled to the user as a NULL retval
8293 return null;
8294 } catch (Exception e) {
8295 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8296 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 } finally {
8298 Binder.restoreCallingIdentity(identity);
8299 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008300 }
8301
fionaxu59545b42016-05-25 15:53:37 -07008302 /**
fionaxu59545b42016-05-25 15:53:37 -07008303 * Action set from carrier signalling broadcast receivers to enable/disable radio
8304 * @param subId the subscription ID that this action applies to.
8305 * @param enabled control enable or disable radio.
8306 * {@hide}
8307 */
8308 @Override
8309 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8310 enforceModifyPermission();
8311 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312
8313 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008314 if (phone == null) {
8315 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8316 return;
8317 }
8318 try {
8319 phone.carrierActionSetRadioEnabled(enabled);
8320 } catch (Exception e) {
8321 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322 } finally {
8323 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008324 }
8325 }
8326
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008327 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008328 * Enable or disable Voice over NR (VoNR)
8329 * @param subId the subscription ID that this action applies to.
8330 * @param enabled enable or disable VoNR.
8331 * @return operation result.
8332 */
8333 @Override
8334 public int setVoNrEnabled(int subId, boolean enabled) {
8335 enforceModifyPermission();
8336 final Phone phone = getPhone(subId);
8337
8338 final long identity = Binder.clearCallingIdentity();
8339 if (phone == null) {
8340 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8341 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8342 }
8343
8344 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8345 try {
8346 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8347 workSource);
8348 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008349
8350 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8351 if (DBG) {
8352 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8353 }
8354 SubscriptionManager.setSubscriptionProperty(
8355 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8356 (enabled ? "1" : "0"));
8357 }
8358
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008359 return result;
8360 } finally {
8361 Binder.restoreCallingIdentity(identity);
8362 }
8363 }
8364
8365 /**
8366 * Is voice over NR enabled
8367 * @return true if VoNR is enabled else false
8368 */
8369 @Override
8370 public boolean isVoNrEnabled(int subId) {
8371 enforceReadPrivilegedPermission("isVoNrEnabled");
8372 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8373 final long identity = Binder.clearCallingIdentity();
8374 try {
8375 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8376 null, subId, workSource);
8377 if (DBG) log("isVoNrEnabled: " + isEnabled);
8378 return isEnabled;
8379 } finally {
8380 Binder.restoreCallingIdentity(identity);
8381 }
8382 }
8383
8384 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008385 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8386 * network status based on which carrier apps could apply actions accordingly,
8387 * enable/disable default url handler for example.
8388 *
8389 * @param subId the subscription ID that this action applies to.
8390 * @param report control start/stop reporting the default network status.
8391 * {@hide}
8392 */
8393 @Override
8394 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8395 enforceModifyPermission();
8396 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008397
8398 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008399 if (phone == null) {
8400 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8401 return;
8402 }
8403 try {
8404 phone.carrierActionReportDefaultNetworkStatus(report);
8405 } catch (Exception e) {
8406 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407 } finally {
8408 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008409 }
8410 }
8411
8412 /**
fionaxud9622282017-07-17 17:51:30 -07008413 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8414 * @param subId the subscription ID that this action applies to.
8415 * {@hide}
8416 */
8417 @Override
8418 public void carrierActionResetAll(int subId) {
8419 enforceModifyPermission();
8420 final Phone phone = getPhone(subId);
8421 if (phone == null) {
8422 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8423 return;
8424 }
8425 try {
8426 phone.carrierActionResetAll();
8427 } catch (Exception e) {
8428 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8429 }
8430 }
8431
8432 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008433 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8434 * bug report is being generated.
8435 */
8436 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008437 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008438 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8439 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008440 writer.println("Permission Denial: can't dump Phone from pid="
8441 + Binder.getCallingPid()
8442 + ", uid=" + Binder.getCallingUid()
8443 + "without permission "
8444 + android.Manifest.permission.DUMP);
8445 return;
8446 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008447 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008448 }
Jack Yueb89b242016-06-22 13:27:47 -07008449
Brad Ebingerdac2f002018-04-03 15:17:52 -07008450 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008451 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8452 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8453 @NonNull String[] args) {
8454 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8455 this, in.getFileDescriptor(), out.getFileDescriptor(),
8456 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008457 }
8458
Jack Yueb89b242016-06-22 13:27:47 -07008459 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008460 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008461 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008462 * @param reason the reason the data enable change is taking place
8463 * @param enabled True if enabling the data, otherwise disabling.
8464 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008465 */
8466 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008467 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008468 boolean enabled) {
8469 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8470 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8471 try {
8472 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008473 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008474 } catch (SecurityException se) {
8475 enforceModifyPermission();
8476 }
8477 } else {
8478 enforceModifyPermission();
8479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008480
8481 final long identity = Binder.clearCallingIdentity();
8482 try {
8483 Phone phone = getPhone(subId);
8484 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008485 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8486 phone.carrierActionSetMeteredApnsEnabled(enabled);
8487 } else {
8488 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008490 }
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008493 }
8494 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008495
8496 /**
8497 * Get Client request stats
8498 * @return List of Client Request Stats
8499 * @hide
8500 */
8501 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008502 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8503 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008504 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008505 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008506 return null;
8507 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008508 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008510 final long identity = Binder.clearCallingIdentity();
8511 try {
8512 if (phone != null) {
8513 return phone.getClientRequestStats();
8514 }
8515
8516 return null;
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008520 }
8521
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008522 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008523 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008524 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008525 }
Jack Yueb4124c2017-02-16 15:32:43 -08008526
8527 /**
Grace Chen70990072017-03-24 17:21:30 -07008528 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008529 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008530 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008531 * @param state State of SIM (power down, power up, pass through)
8532 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8533 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8534 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008535 *
8536 **/
8537 @Override
Grace Chen70990072017-03-24 17:21:30 -07008538 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008539 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008540 Phone phone = PhoneFactory.getPhone(slotIndex);
8541
vagdeviaf9a5b92018-08-15 16:01:53 -07008542 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008544 final long identity = Binder.clearCallingIdentity();
8545 try {
8546 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008547 phone.setSimPowerState(state, null, workSource);
8548 }
8549 } finally {
8550 Binder.restoreCallingIdentity(identity);
8551 }
8552 }
8553
8554 /**
8555 * Set SIM card power state.
8556 *
8557 * @param slotIndex SIM slot id.
8558 * @param state State of SIM (power down, power up, pass through)
8559 * @param callback callback to trigger after success or failure
8560 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8561 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8562 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8563 *
8564 **/
8565 @Override
8566 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8567 IIntegerConsumer callback) {
8568 enforceModifyPermission();
8569 Phone phone = PhoneFactory.getPhone(slotIndex);
8570
8571 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8572
8573 final long identity = Binder.clearCallingIdentity();
8574 try {
8575 if (phone != null) {
8576 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8577 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008578 }
8579 } finally {
8580 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008581 }
8582 }
Shuo Qiandd210312017-04-12 22:11:33 +00008583
Tyler Gunn65d45c22017-06-05 11:22:26 -07008584 private boolean isUssdApiAllowed(int subId) {
8585 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008586 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008587 if (configManager == null) {
8588 return false;
8589 }
8590 PersistableBundle pb = configManager.getConfigForSubId(subId);
8591 if (pb == null) {
8592 return false;
8593 }
8594 return pb.getBoolean(
8595 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8596 }
8597
Shuo Qiandd210312017-04-12 22:11:33 +00008598 /**
8599 * Check if phone is in emergency callback mode
8600 * @return true if phone is in emergency callback mode
8601 * @param subId sub id
8602 */
goneil9c5f4872017-12-05 14:07:56 -08008603 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008604 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008605 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008606 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008607
8608 final long identity = Binder.clearCallingIdentity();
8609 try {
8610 if (phone != null) {
8611 return phone.isInEcm();
8612 } else {
8613 return false;
8614 }
8615 } finally {
8616 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008617 }
8618 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008619
8620 /**
8621 * Get the current signal strength information for the given subscription.
8622 * Because this information is not updated when the device is in a low power state
8623 * it should not be relied-upon to be current.
8624 * @param subId Subscription index
8625 * @return the most recent cached signal strength info from the modem
8626 */
8627 @Override
8628 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008629 final long identity = Binder.clearCallingIdentity();
8630 try {
8631 Phone p = getPhone(subId);
8632 if (p == null) {
8633 return null;
8634 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008636 return p.getSignalStrength();
8637 } finally {
8638 Binder.restoreCallingIdentity(identity);
8639 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008640 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008641
Pengquan Meng77b7f132018-08-22 14:49:57 -07008642 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008643 * Get the current modem radio state for the given slot.
8644 * @param slotIndex slot index.
8645 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008646 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008647 * @return the current radio power state from the modem
8648 */
8649 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008650 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008651 Phone phone = PhoneFactory.getPhone(slotIndex);
8652 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008653 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8654 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008655 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8656 }
8657
8658 final long identity = Binder.clearCallingIdentity();
8659 try {
8660 return phone.getRadioPowerState();
8661 } finally {
8662 Binder.restoreCallingIdentity(identity);
8663 }
8664 }
8665 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8666 }
8667
8668 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008669 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8670 *
8671 * <p>Requires one of the following permissions:
8672 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008673 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008674 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8675 * privileges.
8676 *
8677 * @param subId subscription id
8678 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8679 * {@code false}.
8680 */
8681 @Override
8682 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008683 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008684 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008685 try {
8686 mApp.enforceCallingOrSelfPermission(
8687 android.Manifest.permission.ACCESS_NETWORK_STATE,
8688 functionName);
8689 } catch (Exception e) {
8690 mApp.enforceCallingOrSelfPermission(
8691 permission.READ_BASIC_PHONE_STATE, functionName);
8692 }
Shuo Qian093013d2020-08-13 15:42:55 -07008693 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008694 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008695 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008696 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008697
Pengquan Menga1bb6272018-09-06 09:59:22 -07008698 boolean isEnabled = false;
8699 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008700 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008701 Phone phone = getPhone(subId);
8702 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008703 } finally {
8704 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008706 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008707 }
8708
8709
8710 /**
8711 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8712 *
8713 * <p> Requires permission:
8714 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8715 * privileges.
8716 *
8717 * @param subId subscription id
8718 * @param isEnabled {@code true} means enable, {@code false} means disable.
8719 */
8720 @Override
8721 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8723 mApp, subId, "setDataRoamingEnabled");
8724
Pengquan Menga1bb6272018-09-06 09:59:22 -07008725 final long identity = Binder.clearCallingIdentity();
8726 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008727 Phone phone = getPhone(subId);
8728 if (phone != null) {
8729 phone.setDataRoamingEnabled(isEnabled);
8730 }
8731 } finally {
8732 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008733 }
8734 }
8735
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008736 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008737 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008738 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008739 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008740 mApp, subId, "isManualNetworkSelectionAllowed");
8741
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008742 boolean isAllowed = true;
8743 final long identity = Binder.clearCallingIdentity();
8744 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008745 Phone phone = getPhone(subId);
8746 if (phone != null) {
8747 isAllowed = phone.isCspPlmnEnabled();
8748 }
8749 } finally {
8750 Binder.restoreCallingIdentity(identity);
8751 }
8752 return isAllowed;
8753 }
8754
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008755 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8756 UiccProfile profile = port.getUiccProfile();
8757 if (profile == null ||
8758 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8759 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8760 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008761 }
8762 return true;
8763 }
8764
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008765 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008766 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008767 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008768 mApp.getSystemService(AppOpsManager.class)
8769 .checkPackage(Binder.getCallingUid(), callingPackage);
8770
Jordan Liu1e142fc2019-04-22 15:10:43 -07008771 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008772 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008773 try {
8774 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008775 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008776 } catch (SecurityException e) {
8777 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8778 // has carrier privileges on an active UICC
8779 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8780 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008781 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008782 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008783 }
sandeepjsb6c87872021-09-27 15:34:44 +00008784 // checking compatibility, if calling app's target SDK is T and beyond.
8785 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8786 Binder.getCallingUid())) {
8787 isIccIdAccessRestricted = true;
8788 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008789 final long identity = Binder.clearCallingIdentity();
8790 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008791 UiccController uiccController = UiccController.getInstance();
8792 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008793 if (hasReadPermission) {
8794 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008795 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008796
8797 // Remove private info if the caller doesn't have access
8798 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8799 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008800 //setting the value after compatibility check
8801 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008802 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8803 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008804 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008805 if (card == null) {
8806 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008807 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008808 continue;
8809 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008810 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8811 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008812 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008813 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008814 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008815 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8816 for (UiccPortInfo portInfo : portInfos) {
8817 UiccPort port = uiccController.getUiccPortForSlot(
8818 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8819 if (port == null) {
8820 // assume no access if port is null
8821 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8822 continue;
8823 }
8824 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8825 uiccPortInfos.add(portInfo);
8826 } else {
8827 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8828 }
8829 }
8830 filteredInfos.add(new UiccCardInfo(
8831 cardInfo.isEuicc(),
8832 cardInfo.getCardId(),
8833 null,
8834 cardInfo.getPhysicalSlotIndex(),
8835 cardInfo.isRemovable(),
8836 cardInfo.isMultipleEnabledProfilesSupported(),
8837 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008838 }
8839 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008840 } finally {
8841 Binder.restoreCallingIdentity(identity);
8842 }
8843 }
8844
sandeepjsb6c87872021-09-27 15:34:44 +00008845 /**
8846 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8847 * generally private and require carrier privileges to view.
8848 *
8849 * @hide
8850 */
8851 @NonNull
8852 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8853 List<UiccPortInfo> portinfo = new ArrayList<>();
8854 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8855 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8856 }
8857 return new UiccCardInfo(
8858 cardInfo.isEuicc(),
8859 cardInfo.getCardId(),
8860 null,
8861 cardInfo.getPhysicalSlotIndex(),
8862 cardInfo.isRemovable(),
8863 cardInfo.isMultipleEnabledProfilesSupported(),
8864 portinfo
8865 );
8866 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008867
sandeepjsb6c87872021-09-27 15:34:44 +00008868 /**
8869 * @hide
8870 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8871 * These values are generally private and require carrier privileges to view.
8872 */
8873 @NonNull
8874 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8875 return new UiccPortInfo(
8876 UiccPortInfo.ICCID_REDACTED,
8877 portInfo.getPortIndex(),
8878 portInfo.getLogicalSlotIndex(),
8879 portInfo.isActive()
8880 );
8881 }
8882 @Override
8883 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008884 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008885 mApp.getSystemService(AppOpsManager.class)
8886 .checkPackage(Binder.getCallingUid(), callingPackage);
8887
8888 boolean hasReadPermission = false;
8889 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008890
8891 try {
8892 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8893 hasReadPermission = true;
8894 } catch (SecurityException e) {
8895 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8896 // has carrier privileges on an active UICC
8897 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8898 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8899 hasReadPermission = true;
8900 }
8901 }
8902
8903 // checking compatibility, if calling app's target SDK is T and beyond.
8904 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8905 Binder.getCallingUid())) {
8906 isLogicalSlotAccessRestricted = true;
8907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008908 final long identity = Binder.clearCallingIdentity();
8909 try {
8910 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8911 if (slots == null) {
8912 Rlog.i(LOG_TAG, "slots is null.");
8913 return null;
8914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008915 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8916 for (int i = 0; i < slots.length; i++) {
8917 UiccSlot slot = slots[i];
8918 if (slot == null) {
8919 continue;
8920 }
8921
Jordan Liu7be7e652019-05-06 18:55:02 +00008922 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008923 UiccCard card = slot.getUiccCard();
8924 if (card != null) {
8925 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008926 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008927 cardId = slot.getEid();
8928 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008929 // If cardId is null, use iccId of default port as cardId. Check if has
8930 // read permission otherwise set to null.(card is null which means no
8931 // carrier permission)
8932 cardId = hasReadPermission ? slot.getIccId(
8933 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008934 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 }
8936
Jordan Liu857451f2019-05-09 16:35:35 -07008937 if (cardId != null) {
8938 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8939 // if cardId is an EID, it's all digits so this is fine
8940 cardId = IccUtils.stripTrailingFs(cardId);
8941 }
8942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008943 int cardState = 0;
8944 switch (slot.getCardState()) {
8945 case CARDSTATE_ABSENT:
8946 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8947 break;
8948 case CARDSTATE_PRESENT:
8949 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8950 break;
8951 case CARDSTATE_ERROR:
8952 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8953 break;
8954 case CARDSTATE_RESTRICTED:
8955 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8956 break;
8957 default:
8958 break;
8959
8960 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008961 List<UiccPortInfo> portInfos = new ArrayList<>();
8962 int[] portIndexes = slot.getPortList();
8963 for (int portIdx : portIndexes) {
8964 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8965 callingPackage, hasReadPermission));
8966 if (slot.isPortActive(portIdx)) {
8967 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8968 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8969 port.getPhoneId(), true));
8970 } else {
8971 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8972 }
8973 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008974 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008975 slot.isEuicc(),
8976 cardId,
8977 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008978 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008979 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008980 //setting the value after compatibility check
8981 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008982 }
8983 return infos;
8984 } finally {
8985 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008986 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008987 }
8988
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008989 /* Returns null if doesn't have read permission or carrier privilege access. */
8990 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8991 boolean hasReadPermission) {
8992 String iccId = slot.getIccId(portIndex);
8993 if (hasReadPermission) { // if has read permission
8994 return iccId;
8995 } else {
8996 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8997 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8998 // if no read permission, checking carrier privilege access
8999 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9000 return iccId;
9001 }
9002 }
9003 }
9004 // No read permission or carrier privilege access.
9005 return UiccPortInfo.ICCID_REDACTED;
9006 }
9007
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009008 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009009 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009010 public boolean switchSlots(int[] physicalSlots) {
9011 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009012
9013 final long identity = Binder.clearCallingIdentity();
9014 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009015 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9016 for (int i = 0; i < physicalSlots.length; i++) {
9017 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9018 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9019 physicalSlots[i], i));
9020 }
9021 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009022 } finally {
9023 Binder.restoreCallingIdentity(identity);
9024 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009025 }
Jack Yu4c988042018-02-27 15:30:01 -08009026
9027 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009028 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9029 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9030 enforceModifyPermission();
9031
9032 final long identity = Binder.clearCallingIdentity();
9033 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009034 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009035 } finally {
9036 Binder.restoreCallingIdentity(identity);
9037 }
9038 }
9039
9040 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009041 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009042 final long identity = Binder.clearCallingIdentity();
9043 try {
9044 return UiccController.getInstance().getCardIdForDefaultEuicc();
9045 } finally {
9046 Binder.restoreCallingIdentity(identity);
9047 }
9048 }
9049
Pengquan Meng85728fb2018-03-12 16:31:21 -07009050 /**
goneil47ffb6e2018-04-06 15:40:58 -07009051 * A test API to reload the UICC profile.
9052 *
9053 * <p>Requires that the calling app has permission
9054 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9055 * @hide
9056 */
9057 @Override
9058 public void refreshUiccProfile(int subId) {
9059 enforceModifyPermission();
9060
9061 final long identity = Binder.clearCallingIdentity();
9062 try {
9063 Phone phone = getPhone(subId);
9064 if (phone == null) {
9065 return;
9066 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009067 UiccPort uiccPort = phone.getUiccPort();
9068 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009069 return;
9070 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009071 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009072 if (uiccProfile == null) {
9073 return;
9074 }
9075 uiccProfile.refresh();
9076 } finally {
9077 Binder.restoreCallingIdentity(identity);
9078 }
9079 }
9080
9081 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009082 * Returns false if the mobile data is disabled by default, otherwise return true.
9083 */
9084 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009085 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009086 }
9087
9088 /**
9089 * Returns true if the data roaming is enabled by default, i.e the system property
9090 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9091 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9092 */
9093 private boolean getDefaultDataRoamingEnabled(int subId) {
9094 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009095 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009096 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009097 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9098 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9099 return isDataRoamingEnabled;
9100 }
9101
9102 /**
9103 * Returns the default network type for the given {@code subId}, if the default network type is
9104 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9105 */
9106 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009107 List<Integer> list = TelephonyProperties.default_network();
9108 int phoneId = mSubscriptionController.getPhoneId(subId);
9109 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9110 return list.get(phoneId);
9111 }
9112 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009113 }
fionaxua13278b2018-03-21 00:08:13 -07009114
9115 @Override
9116 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009117 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009118 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009119
9120 final long identity = Binder.clearCallingIdentity();
9121 try {
9122 final Phone phone = getPhone(subId);
9123 if (phone == null) {
9124 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9125 return;
9126 }
chen xueaba88a2019-03-15 13:15:10 -07009127 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9128 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009129 if (carrierPrivilegeRules == null) {
9130 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9131 } else {
9132 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009134 } finally {
9135 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009136 }
fionaxua13278b2018-03-21 00:08:13 -07009137 }
9138
9139 @Override
9140 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009141 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009142
9143 final long identity = Binder.clearCallingIdentity();
9144 try {
9145 final Phone phone = getPhone(subId);
9146 if (phone == null) {
9147 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9148 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9149 }
9150 return phone.getCarrierIdListVersion();
9151 } finally {
9152 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009153 }
fionaxua13278b2018-03-21 00:08:13 -07009154 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009155
9156 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009157 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9158 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009159 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009160 mApp, subId, callingPackage, callingFeatureId,
9161 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009162 return -1;
9163 }
9164
9165 final long identity = Binder.clearCallingIdentity();
9166 try {
9167 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9168 } finally {
9169 Binder.restoreCallingIdentity(identity);
9170 }
9171 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009172
9173 @Override
9174 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009175 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009176 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009177 mApp, subId, "getCdmaRoamingMode");
9178
9179 final long identity = Binder.clearCallingIdentity();
9180 try {
9181 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9182 } finally {
9183 Binder.restoreCallingIdentity(identity);
9184 }
9185 }
9186
9187 @Override
9188 public boolean setCdmaRoamingMode(int subId, int mode) {
9189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9190 mApp, subId, "setCdmaRoamingMode");
9191
9192 final long identity = Binder.clearCallingIdentity();
9193 try {
9194 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9195 } finally {
9196 Binder.restoreCallingIdentity(identity);
9197 }
9198 }
9199
9200 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009201 public int getCdmaSubscriptionMode(int subId) {
9202 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009203 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009204 mApp, subId, "getCdmaSubscriptionMode");
9205
9206 final long identity = Binder.clearCallingIdentity();
9207 try {
9208 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9209 } finally {
9210 Binder.restoreCallingIdentity(identity);
9211 }
9212 }
9213
9214 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009215 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9217 mApp, subId, "setCdmaSubscriptionMode");
9218
9219 final long identity = Binder.clearCallingIdentity();
9220 try {
9221 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9222 } finally {
9223 Binder.restoreCallingIdentity(identity);
9224 }
9225 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009226
sqianc5eccab2018-10-19 18:46:41 -07009227 @Override
sqian8c685422019-02-22 15:55:18 -08009228 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009229 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009230 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009231 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9232 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009233 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9234 }
9235 final long identity = Binder.clearCallingIdentity();
9236 try {
sqian854d44b2018-12-12 16:48:18 -08009237 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9238 for (Phone phone: PhoneFactory.getPhones()) {
9239 if (phone.getEmergencyNumberTracker() != null
9240 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9241 emergencyNumberListInternal.put(
9242 phone.getSubId(),
9243 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9244 }
sqian11b7a0e2018-12-05 18:48:28 -08009245 }
sqian854d44b2018-12-12 16:48:18 -08009246 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009247 } finally {
9248 Binder.restoreCallingIdentity(identity);
9249 }
sqianc5eccab2018-10-19 18:46:41 -07009250 }
9251
9252 @Override
sqian8c685422019-02-22 15:55:18 -08009253 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009254 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009255 if (!exactMatch) {
9256 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009257 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009258 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009259 }
9260 final long identity = Binder.clearCallingIdentity();
9261 try {
sqian854d44b2018-12-12 16:48:18 -08009262 for (Phone phone: PhoneFactory.getPhones()) {
9263 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009264 && phone.getEmergencyNumberTracker()
9265 .isEmergencyNumber(number, exactMatch)) {
9266 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009267 }
sqian11b7a0e2018-12-05 18:48:28 -08009268 }
9269 return false;
9270 } finally {
9271 Binder.restoreCallingIdentity(identity);
9272 }
9273 }
9274
sqianf4ca7ed2019-01-15 18:32:07 -08009275 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009276 * Start emergency callback mode for GsmCdmaPhone for testing.
9277 */
9278 @Override
9279 public void startEmergencyCallbackMode() {
9280 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9281 "startEmergencyCallbackMode");
9282 enforceModifyPermission();
9283 final long identity = Binder.clearCallingIdentity();
9284 try {
9285 for (Phone phone : PhoneFactory.getPhones()) {
9286 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9287 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9288 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9289 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9290 gsmCdmaPhone.obtainMessage(
9291 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9292 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9293 }
9294 }
9295 } finally {
9296 Binder.restoreCallingIdentity(identity);
9297 }
9298 }
9299
9300 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009301 * Update emergency number list for test mode.
9302 */
9303 @Override
9304 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9305 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9306 "updateEmergencyNumberListTestMode");
9307
9308 final long identity = Binder.clearCallingIdentity();
9309 try {
9310 for (Phone phone: PhoneFactory.getPhones()) {
9311 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9312 if (tracker != null) {
9313 tracker.executeEmergencyNumberTestModeCommand(action, num);
9314 }
9315 }
9316 } finally {
9317 Binder.restoreCallingIdentity(identity);
9318 }
9319 }
9320
9321 /**
9322 * Get the full emergency number list for test mode.
9323 */
9324 @Override
9325 public List<String> getEmergencyNumberListTestMode() {
9326 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9327 "getEmergencyNumberListTestMode");
9328
9329 final long identity = Binder.clearCallingIdentity();
9330 try {
9331 Set<String> emergencyNumbers = new HashSet<>();
9332 for (Phone phone: PhoneFactory.getPhones()) {
9333 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9334 if (tracker != null) {
9335 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9336 emergencyNumbers.add(num.getNumber());
9337 }
9338 }
9339 }
9340 return new ArrayList<>(emergencyNumbers);
9341 } finally {
9342 Binder.restoreCallingIdentity(identity);
9343 }
9344 }
9345
chen xud6b45bd2018-10-30 22:27:10 -07009346 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009347 public int getEmergencyNumberDbVersion(int subId) {
9348 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9349
9350 final long identity = Binder.clearCallingIdentity();
9351 try {
9352 final Phone phone = getPhone(subId);
9353 if (phone == null) {
9354 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9355 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9356 }
9357 return phone.getEmergencyNumberDbVersion();
9358 } finally {
9359 Binder.restoreCallingIdentity(identity);
9360 }
9361 }
9362
9363 @Override
9364 public void notifyOtaEmergencyNumberDbInstalled() {
9365 enforceModifyPermission();
9366
9367 final long identity = Binder.clearCallingIdentity();
9368 try {
9369 for (Phone phone: PhoneFactory.getPhones()) {
9370 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9371 if (tracker != null) {
9372 tracker.updateOtaEmergencyNumberDatabase();
9373 }
9374 }
9375 } finally {
9376 Binder.restoreCallingIdentity(identity);
9377 }
9378 }
9379
9380 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009381 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009382 enforceActiveEmergencySessionPermission();
9383
9384 final long identity = Binder.clearCallingIdentity();
9385 try {
9386 for (Phone phone: PhoneFactory.getPhones()) {
9387 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9388 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009389 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9390 }
9391 }
9392 } finally {
9393 Binder.restoreCallingIdentity(identity);
9394 }
9395 }
9396
9397 @Override
9398 public void resetOtaEmergencyNumberDbFilePath() {
9399 enforceActiveEmergencySessionPermission();
9400
9401 final long identity = Binder.clearCallingIdentity();
9402 try {
9403 for (Phone phone: PhoneFactory.getPhones()) {
9404 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9405 if (tracker != null) {
9406 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009407 }
9408 }
9409 } finally {
9410 Binder.restoreCallingIdentity(identity);
9411 }
9412 }
9413
9414 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009415 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9416 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9417 Phone phone = getPhone(subId);
9418 if (phone == null) {
9419 return null;
9420 }
9421 final long identity = Binder.clearCallingIdentity();
9422 try {
9423 UiccProfile profile = UiccController.getInstance()
9424 .getUiccProfileForPhone(phone.getPhoneId());
9425 if (profile != null) {
9426 return profile.getCertsFromCarrierPrivilegeAccessRules();
9427 }
9428 } finally {
9429 Binder.restoreCallingIdentity(identity);
9430 }
9431 return null;
9432 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009433
9434 /**
9435 * Enable or disable a modem stack.
9436 */
9437 @Override
9438 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9439 enforceModifyPermission();
9440
9441 final long identity = Binder.clearCallingIdentity();
9442 try {
9443 Phone phone = PhoneFactory.getPhone(slotIndex);
9444 if (phone == null) {
9445 return false;
9446 } else {
9447 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9448 }
9449 } finally {
9450 Binder.restoreCallingIdentity(identity);
9451 }
9452 }
Michelecea4cf22018-12-21 15:00:11 -08009453
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009454 /**
9455 * Whether a modem stack is enabled or not.
9456 */
9457 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009458 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9459 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009460 Phone phone = PhoneFactory.getPhone(slotIndex);
9461 if (phone == null) return false;
9462
9463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009464 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9465 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009466 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9467 }
9468
9469 final long identity = Binder.clearCallingIdentity();
9470 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009471 try {
9472 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9473 } catch (NoSuchElementException ex) {
9474 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9475 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009476 } finally {
9477 Binder.restoreCallingIdentity(identity);
9478 }
9479 }
9480
Michelecea4cf22018-12-21 15:00:11 -08009481 @Override
Michele0ea7d782019-03-19 14:58:42 -07009482 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009483 enforceModifyPermission();
9484
9485 final long identity = Binder.clearCallingIdentity();
9486 try {
9487 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009488 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009489 .commit();
9490 } finally {
9491 Binder.restoreCallingIdentity(identity);
9492 }
9493 }
9494
9495 @Override
Michele0ea7d782019-03-19 14:58:42 -07009496 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009497 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009499 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9500 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009501 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009502 }
Michelecea4cf22018-12-21 15:00:11 -08009503
9504 final long identity = Binder.clearCallingIdentity();
9505 try {
Michele0ea7d782019-03-19 14:58:42 -07009506 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009507 } finally {
9508 Binder.restoreCallingIdentity(identity);
9509 }
9510 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009511
Michele0ea7d782019-03-19 14:58:42 -07009512 @TelephonyManager.IsMultiSimSupportedResult
9513 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009514 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9515 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9516 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009517 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9518 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009519 }
9520 // Check if the hardware supports multisim functionality. If usage of multisim is not
9521 // supported by the modem, indicate that it is restricted.
9522 PhoneCapability staticCapability =
9523 mPhoneConfigurationManager.getStaticPhoneCapability();
9524 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009525 loge("isMultiSimSupportedInternal: no static configuration available");
9526 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009527 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009528 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009529 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9530 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009531 }
9532 // Check if support of multiple SIMs is restricted by carrier
9533 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009534 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009535 }
9536
Michele0ea7d782019-03-19 14:58:42 -07009537 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009538 }
9539
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009540 /**
9541 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009542 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9543 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9544 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009545 * @param numOfSims number of active sims we want to switch to
9546 */
9547 @Override
9548 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009549 if (numOfSims == 1) {
9550 enforceModifyPermission();
9551 } else {
9552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9553 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9554 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009555 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009556
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009557 try {
Michele30b57b22019-03-01 12:01:14 -08009558 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009559 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009560 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9561 return;
9562 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009563 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9564 } finally {
9565 Binder.restoreCallingIdentity(identity);
9566 }
9567 }
9568
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009569 @Override
9570 public boolean isApplicationOnUicc(int subId, int appType) {
9571 enforceReadPrivilegedPermission("isApplicationOnUicc");
9572 Phone phone = getPhone(subId);
9573 if (phone == null) {
9574 return false;
9575 }
9576 final long identity = Binder.clearCallingIdentity();
9577 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009578 UiccPort uiccPort = phone.getUiccPort();
9579 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009580 return false;
9581 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009582 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009583 if (uiccProfile == null) {
9584 return false;
9585 }
9586 if (TelephonyManager.APPTYPE_SIM <= appType
9587 && appType <= TelephonyManager.APPTYPE_ISIM) {
9588 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9589 }
9590 return false;
9591 } finally {
9592 Binder.restoreCallingIdentity(identity);
9593 }
9594 }
9595
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009596 /**
chen xub4baa772019-04-03 10:23:41 -07009597 * Get whether making changes to modem configurations will trigger reboot.
9598 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009599 */
9600 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009601 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9602 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009604 mApp, subId, callingPackage, callingFeatureId,
9605 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009606 return false;
9607 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009608 final long identity = Binder.clearCallingIdentity();
9609 try {
9610 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9611 } finally {
9612 Binder.restoreCallingIdentity(identity);
9613 }
9614 }
9615
Nathan Harold29f5f052019-02-15 13:41:57 -08009616 private void updateModemStateMetrics() {
9617 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9618 // TODO: check the state for each modem if the api is ready.
9619 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9620 }
9621
Pengquan Meng3889a572019-01-23 11:16:29 -08009622 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009623 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009624 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009625 // Verify that the callingPackage belongs to the calling UID
9626 mApp.getSystemService(AppOpsManager.class)
9627 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009628 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009629 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009630 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009631 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9632 if (slotInfos != null) {
9633 for (int i = 0; i < slotInfos.length; i++) {
9634 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9635 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9636 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9637 portInfo.getLogicalSlotIndex()));
9638 }
9639 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009640 }
9641 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009642 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009643 } finally {
9644 Binder.restoreCallingIdentity(identity);
9645 }
9646 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009647
9648 /**
9649 * Get the IRadio HAL Version
9650 */
9651 @Override
9652 public int getRadioHalVersion() {
9653 Phone phone = getDefaultPhone();
9654 if (phone == null) return -1;
9655 HalVersion hv = phone.getHalVersion();
9656 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9657 return hv.major * 100 + hv.minor;
9658 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009659
9660 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009661 * Get the current calling package name.
9662 * @return the current calling package name
9663 */
9664 @Override
9665 public String getCurrentPackageName() {
9666 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9667 }
9668
9669 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009670 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9671 * corresponding network requests on a subId.
9672 *
9673 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009674 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009675 * 2) APN is un-metered for this subscription, or
9676 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009677 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009678 *
9679 * @return whether data is allowed for a apn type.
9680 *
9681 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009682 */
9683 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009684 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009685 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9686 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009687
9688 // Now that all security checks passes, perform the operation as ourselves.
9689 final long identity = Binder.clearCallingIdentity();
9690 try {
9691 Phone phone = getPhone(subId);
9692 if (phone == null) return false;
9693
Jack Yu41407ee2019-05-13 16:54:09 -07009694 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009695 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9696 } finally {
9697 Binder.restoreCallingIdentity(identity);
9698 }
9699 }
9700
9701 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009702 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009703 enforceReadPrivilegedPermission("isApnMetered");
9704
9705 // Now that all security checks passes, perform the operation as ourselves.
9706 final long identity = Binder.clearCallingIdentity();
9707 try {
9708 Phone phone = getPhone(subId);
9709 if (phone == null) return true; // By default return true.
9710
Jack Yu41407ee2019-05-13 16:54:09 -07009711 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009712 } finally {
9713 Binder.restoreCallingIdentity(identity);
9714 }
9715 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009716
9717 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009718 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9719 int subscriptionId, IBooleanConsumer resultCallback) {
9720 enforceModifyPermission();
9721 long token = Binder.clearCallingIdentity();
9722 try {
9723 Phone phone = getPhone(subscriptionId);
9724 if (phone == null) {
9725 try {
9726 if (resultCallback != null) {
9727 resultCallback.accept(false);
9728 }
9729 } catch (RemoteException e) {
9730 // ignore
9731 }
9732 return;
9733 }
9734 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9735 Pair.create(specifiers, (x) -> {
9736 try {
9737 if (resultCallback != null) {
9738 resultCallback.accept(x);
9739 }
9740 } catch (RemoteException e) {
9741 // ignore
9742 }
9743 });
9744 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9745 } finally {
9746 Binder.restoreCallingIdentity(token);
9747 }
9748 }
9749
9750 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009751 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9752 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009753 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009754 mApp, subId, "getSystemSelectionChannels");
9755 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9756 final long identity = Binder.clearCallingIdentity();
9757 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009758 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9759 if (result instanceof IllegalStateException) {
9760 throw (IllegalStateException) result;
9761 }
9762 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009763 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9764 return specifiers;
9765 } finally {
9766 Binder.restoreCallingIdentity(identity);
9767 }
9768 }
9769
9770 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009771 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009772 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009773 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9774 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9775 if (iccRecords == null) {
9776 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9777 return false;
9778 }
9779 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9780 }
9781
9782 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009783 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9784 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009785 if (callingPackage == null) {
9786 callingPackage = getCurrentPackageName();
9787 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009788 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9789 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009790 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9791 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009792 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9793 }
9794 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9795 Intent intent = new Intent();
9796 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9797 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9798 // Bring up choose default SMS subscription dialog right now
9799 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9800 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9801 mApp.startActivity(intent);
9802 }
chen xud5ca2d52019-05-28 15:20:57 -07009803
9804 @Override
9805 public String getMmsUAProfUrl(int subId) {
9806 //TODO investigate if this API should require proper permission check in R b/133791609
9807 final long identity = Binder.clearCallingIdentity();
9808 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009809 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9810 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9811 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9812 return carrierUAProfUrl;
9813 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009814 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9815 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009816 } finally {
9817 Binder.restoreCallingIdentity(identity);
9818 }
9819 }
9820
9821 @Override
9822 public String getMmsUserAgent(int subId) {
9823 //TODO investigate if this API should require proper permission check in R b/133791609
9824 final long identity = Binder.clearCallingIdentity();
9825 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009826 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9827 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9828 if (!TextUtils.isEmpty(carrierUserAgent)) {
9829 return carrierUserAgent;
9830 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009831 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9832 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009833 } finally {
9834 Binder.restoreCallingIdentity(identity);
9835 }
9836 }
Jack Yub07d4972019-05-28 16:12:25 -07009837
9838 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009839 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9840 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009841
Jack Yub07d4972019-05-28 16:12:25 -07009842 final long identity = Binder.clearCallingIdentity();
9843 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009844 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009845 if (phone == null) return false;
9846
Hall Liua62f5da2020-09-25 10:42:19 -07009847 switch (policy) {
9848 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9849 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9850 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9851 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9852 default:
9853 throw new IllegalArgumentException(policy + " is not a valid policy");
9854 }
Jack Yub07d4972019-05-28 16:12:25 -07009855 } finally {
9856 Binder.restoreCallingIdentity(identity);
9857 }
9858 }
9859
9860 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009861 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009862 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009863 enforceModifyPermission();
9864
changbettyd5c246e2019-12-24 15:40:37 +08009865 final long identity = Binder.clearCallingIdentity();
9866 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009867 Phone phone = getPhone(subscriptionId);
9868 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009869
Hall Liua62f5da2020-09-25 10:42:19 -07009870 switch (policy) {
9871 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9872 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9873 break;
9874 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9875 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9876 break;
9877 default:
9878 throw new IllegalArgumentException(policy + " is not a valid policy");
9879 }
changbettyd5c246e2019-12-24 15:40:37 +08009880 } finally {
9881 Binder.restoreCallingIdentity(identity);
9882 }
9883 }
9884
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009885 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009886 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009887 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9888 * otherwise.
9889 */
9890 @Override
9891 public void setCepEnabled(boolean isCepEnabled) {
9892 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9893
9894 final long identity = Binder.clearCallingIdentity();
9895 try {
9896 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9897 for (Phone phone : PhoneFactory.getPhones()) {
9898 Phone defaultPhone = phone.getImsPhone();
9899 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9900 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9901 ImsPhoneCallTracker imsPhoneCallTracker =
9902 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9903 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9904 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9905 + imsPhone.getMsisdn());
9906 }
9907 }
9908 } finally {
9909 Binder.restoreCallingIdentity(identity);
9910 }
9911 }
allenwtsu46dcc572020-01-08 18:24:03 +08009912
9913 /**
9914 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9915 *
9916 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9917 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9918 * before being read.
9919 */
9920 @Override
9921 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9922 isCompressed) {
9923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9924 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009925 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9926 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9927 }
9928 if (!isImsAvailableOnDevice()) {
9929 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9930 "IMS not available on device.");
9931 }
9932
9933 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009934 try {
Hui Wang761a6682020-10-31 05:12:53 +00009935 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9936 } finally {
9937 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009938 }
9939 }
zoey chene02881a2019-12-30 16:11:23 +08009940
9941 @Override
9942 public boolean isIccLockEnabled(int subId) {
9943 enforceReadPrivilegedPermission("isIccLockEnabled");
9944
9945 // Now that all security checks passes, perform the operation as ourselves.
9946 final long identity = Binder.clearCallingIdentity();
9947 try {
9948 Phone phone = getPhone(subId);
9949 if (phone != null && phone.getIccCard() != null) {
9950 return phone.getIccCard().getIccLockEnabled();
9951 } else {
9952 return false;
9953 }
9954 } finally {
9955 Binder.restoreCallingIdentity(identity);
9956 }
9957 }
9958
9959 /**
9960 * Set the ICC pin lock enabled or disabled.
9961 *
9962 * @return an integer representing the status of IccLock enabled or disabled in the following
9963 * three cases:
9964 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9965 * successfully.
9966 * - Positive number and zero for remaining password attempts.
9967 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9968 *
9969 */
9970 @Override
9971 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9972 enforceModifyPermission();
9973
9974 Phone phone = getPhone(subId);
9975 if (phone == null) {
9976 return 0;
9977 }
9978 // Now that all security checks passes, perform the operation as ourselves.
9979 final long identity = Binder.clearCallingIdentity();
9980 try {
9981 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9982 new Pair<Boolean, String>(enabled, password), phone, null);
9983 return attemptsRemaining;
9984
9985 } catch (Exception e) {
9986 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9987 } finally {
9988 Binder.restoreCallingIdentity(identity);
9989 }
9990 return 0;
9991 }
9992
9993 /**
9994 * Change the ICC password used in ICC pin lock.
9995 *
9996 * @return an integer representing the status of IccLock changed in the following three cases:
9997 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9998 * - Positive number and zero for remaining password attempts.
9999 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10000 *
10001 */
10002 @Override
10003 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10004 enforceModifyPermission();
10005
10006 Phone phone = getPhone(subId);
10007 if (phone == null) {
10008 return 0;
10009 }
10010 // Now that all security checks passes, perform the operation as ourselves.
10011 final long identity = Binder.clearCallingIdentity();
10012 try {
10013 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10014 new Pair<String, String>(oldPassword, newPassword), phone, null);
10015 return attemptsRemaining;
10016
10017 } catch (Exception e) {
10018 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10019 } finally {
10020 Binder.restoreCallingIdentity(identity);
10021 }
10022 return 0;
10023 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010024
10025 /**
10026 * Request for receiving user activity notification
10027 */
10028 @Override
10029 public void requestUserActivityNotification() {
10030 if (!mNotifyUserActivity.get()
10031 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10032 mNotifyUserActivity.set(true);
10033 }
10034 }
10035
10036 /**
10037 * Called when userActivity is signalled in the power manager.
10038 * This is safe to call from any thread, with any window manager locks held or not.
10039 */
10040 @Override
10041 public void userActivity() {
10042 // ***************************************
10043 // * Inherited from PhoneWindowManager *
10044 // ***************************************
10045 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10046 // WITH ITS LOCKS HELD.
10047 //
10048 // This code must be VERY careful about the locks
10049 // it acquires.
10050 // In fact, the current code acquires way too many,
10051 // and probably has lurking deadlocks.
10052
10053 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10054 throw new SecurityException("Only the OS may call notifyUserActivity()");
10055 }
10056
10057 if (mNotifyUserActivity.getAndSet(false)) {
10058 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10059 USER_ACTIVITY_NOTIFICATION_DELAY);
10060 }
10061 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010062
10063 @Override
10064 public boolean canConnectTo5GInDsdsMode() {
10065 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10066 }
Jack Yud10cdd42020-09-28 20:28:01 -070010067
10068 @Override
10069 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10070 String callingFeatureId) {
10071 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10072 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10073 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10074 }
10075
10076 Phone phone = getPhone(subId);
10077 if (phone == null) {
10078 throw new RuntimeException("phone is not available");
10079 }
10080 // Now that all security checks passes, perform the operation as ourselves.
10081 final long identity = Binder.clearCallingIdentity();
10082 try {
10083 return phone.getEquivalentHomePlmns();
10084 } finally {
10085 Binder.restoreCallingIdentity(identity);
10086 }
10087 }
Daniel Bright59e67312020-11-13 11:49:37 -080010088
10089 @Override
10090 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010091 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10092 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010093 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010094 if (radioInterfaceCapabilities == null) {
10095 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010096 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010097 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010098 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010099
Hui Wang641e81c2020-10-12 12:14:23 -070010100 @Override
10101 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10102 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010103 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10104 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10105 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10106 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10107 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010108 if (DBG) {
10109 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10110 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10111 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10112 }
10113
10114 if (!SubscriptionManager.isValidSubscriptionId(subId)
10115 || appType < TelephonyManager.APPTYPE_UNKNOWN
10116 || appType > TelephonyManager.APPTYPE_ISIM
10117 || nafUrl == null || securityProtocol == null || callback == null) {
10118 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10119 if (callback != null) {
10120 try {
10121 callback.onAuthenticationFailure(
10122 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10123 } catch (RemoteException exception) {
10124 log("Fail to notify onAuthenticationFailure due to " + exception);
10125 }
10126 return;
10127 }
10128 }
10129
10130 final long token = Binder.clearCallingIdentity();
10131 try {
10132 getGbaManager(subId).bootstrapAuthenticationRequest(
10133 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10134 forceBootStrapping, callback));
10135 } finally {
10136 Binder.restoreCallingIdentity(token);
10137 }
10138 }
10139
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010140 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010141 * Attempts to set the radio power state for all phones for thermal reason.
10142 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010143 * requested radio power state will actually be set. See {@link
10144 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10145 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010146 * @param enable {@code true} if trying to turn radio on.
10147 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10148 * false}.
10149 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010150 private boolean setRadioPowerForThermal(boolean enable) {
10151 boolean isPhoneAvailable = false;
10152 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10153 Phone phone = PhoneFactory.getPhone(i);
10154 if (phone != null) {
10155 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10156 isPhoneAvailable = true;
10157 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010158 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010159
10160 // return true if successfully informed the phone object about the thermal radio power
10161 // request.
10162 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010163 }
10164
10165 private int handleDataThrottlingRequest(int subId,
10166 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010167 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10168 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10169 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10170 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10171 throw new IllegalArgumentException("modem does not support data throttling");
10172 }
10173
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010174 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10175 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010176 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010177 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10178 }
10179
10180 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10181
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010182 if (isDataThrottlingSupported) {
10183 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010184 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010185 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10186 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10187 } else if (thermalMitigationResult
10188 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010189 log("Modem likely does not support data throttling on secondary carrier. Data " +
10190 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10191 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010192 }
10193 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010194 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010195
10196 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010197 }
10198
Jack Nudelman644b91a2021-03-12 14:09:48 -080010199 private static List<String> getThermalMitigationAllowlist(Context context) {
10200 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10201 for (String pckg : context.getResources()
10202 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10203 sThermalMitigationAllowlistedPackages.add(pckg);
10204 }
10205 }
10206
10207 return sThermalMitigationAllowlistedPackages;
10208 }
10209
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010210 private boolean isAnyPhoneInEmergencyState() {
10211 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10212 if (tm.isInEmergencyCall()) {
10213 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10214 return true;
10215 }
10216 for (Phone phone : PhoneFactory.getPhones()) {
10217 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10218 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10219 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10220 + phone.isInEcm());
10221 return true;
10222 }
10223 }
10224
10225 return false;
10226 }
10227
Jack Nudelman644b91a2021-03-12 14:09:48 -080010228 /**
10229 * Used by shell commands to add an authorized package name for thermal mitigation.
10230 * @param packageName name of package to be allowlisted
10231 * @param context
10232 */
10233 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10234 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10235 sThermalMitigationAllowlistedPackages.add(packageName);
10236 }
10237
10238 /**
10239 * Used by shell commands to remove an authorized package name for thermal mitigation.
10240 * @param packageName name of package to remove from allowlist
10241 * @param context
10242 */
10243 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10244 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10245 sThermalMitigationAllowlistedPackages.remove(packageName);
10246 }
10247
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010248 /**
10249 * Thermal mitigation request to control functionalities at modem.
10250 *
10251 * @param subId the id of the subscription.
10252 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010253 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010254 *
10255 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10256 */
10257 @Override
10258 @ThermalMitigationResult
10259 public int sendThermalMitigationRequest(
10260 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010261 ThermalMitigationRequest thermalMitigationRequest,
10262 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010263 enforceModifyPermission();
10264
Jack Nudelman644b91a2021-03-12 14:09:48 -080010265 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10266 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10267 .contains(callingPackage)) {
10268 throw new SecurityException("Calling package must be configured in the device config. "
10269 + "calling package: " + callingPackage);
10270 }
10271
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010272 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10273 final long identity = Binder.clearCallingIdentity();
10274
10275 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10276 try {
10277 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10278 switch (thermalMitigationAction) {
10279 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10280 thermalMitigationResult =
10281 handleDataThrottlingRequest(subId,
10282 thermalMitigationRequest.getDataThrottlingRequest());
10283 break;
10284 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10285 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10286 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10287 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10288 }
10289
10290 // Ensure that radio is on. If not able to power on due to phone being
10291 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010292 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010293 thermalMitigationResult =
10294 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10295 break;
10296 }
10297
10298 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10299 false);
10300 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10301 break;
10302 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10303 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10304 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10305 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10306 }
10307
10308 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10309 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010310 Phone phone = getPhone(subId);
10311 if (phone == null) {
10312 thermalMitigationResult =
10313 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10314 break;
10315 }
10316
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010317 TelephonyConnectionService service =
10318 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010319 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010320 Log.e(LOG_TAG, "An emergency call is pending");
10321 thermalMitigationResult =
10322 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10323 break;
10324 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010325 thermalMitigationResult =
10326 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10327 break;
10328 }
10329 } else {
10330 thermalMitigationResult =
10331 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10332 break;
10333 }
10334
10335 // Turn radio off. If not able to power off due to phone being unavailable,
10336 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010337 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010338 thermalMitigationResult =
10339 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10340 break;
10341 }
10342 thermalMitigationResult =
10343 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10344 break;
10345 default:
10346 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10347 + "not exist. Requested action: " + thermalMitigationAction);
10348 }
10349 } catch (IllegalArgumentException e) {
10350 throw e;
10351 } catch (Exception e) {
10352 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10353 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10354 } finally {
10355 Binder.restoreCallingIdentity(identity);
10356 }
10357
10358 if (DBG) {
10359 log("thermalMitigationRequest returning with thermalMitigationResult: "
10360 + thermalMitigationResult);
10361 }
10362
10363 return thermalMitigationResult;
10364 }
Hui Wang641e81c2020-10-12 12:14:23 -070010365
10366 /**
10367 * Set the GbaService Package Name that Telephony will bind to.
10368 *
10369 * @param subId The sim that the GbaService is associated with.
10370 * @param packageName The name of the package to be replaced with.
10371 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10372 */
10373 @Override
10374 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10375 enforceModifyPermission();
10376
10377 final long identity = Binder.clearCallingIdentity();
10378 try {
10379 return getGbaManager(subId).overrideServicePackage(packageName);
10380 } finally {
10381 Binder.restoreCallingIdentity(identity);
10382 }
10383 }
10384
10385 /**
10386 * Return the package name of the currently bound GbaService.
10387 *
10388 * @param subId The sim that the GbaService is associated with.
10389 * @return the package name of the GbaService configuration, null if GBA is not supported.
10390 */
10391 @Override
10392 public String getBoundGbaService(int subId) {
10393 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10394
10395 final long identity = Binder.clearCallingIdentity();
10396 try {
10397 return getGbaManager(subId).getServicePackage();
10398 } finally {
10399 Binder.restoreCallingIdentity(identity);
10400 }
10401 }
10402
10403 /**
10404 * Set the release time for telephony to unbind GbaService.
10405 *
10406 * @param subId The sim that the GbaService is associated with.
10407 * @param interval The release time to unbind GbaService by millisecond.
10408 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10409 */
10410 @Override
10411 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10412 enforceModifyPermission();
10413
10414 final long identity = Binder.clearCallingIdentity();
10415 try {
10416 return getGbaManager(subId).overrideReleaseTime(interval);
10417 } finally {
10418 Binder.restoreCallingIdentity(identity);
10419 }
10420 }
10421
10422 /**
10423 * Return the release time for telephony to unbind GbaService.
10424 *
10425 * @param subId The sim that the GbaService is associated with.
10426 * @return The release time to unbind GbaService by millisecond.
10427 */
10428 @Override
10429 public int getGbaReleaseTime(int subId) {
10430 enforceReadPrivilegedPermission("getGbaReleaseTime");
10431
10432 final long identity = Binder.clearCallingIdentity();
10433 try {
10434 return getGbaManager(subId).getReleaseTime();
10435 } finally {
10436 Binder.restoreCallingIdentity(identity);
10437 }
10438 }
10439
10440 private GbaManager getGbaManager(int subId) {
10441 GbaManager instance = GbaManager.getInstance(subId);
10442 if (instance == null) {
10443 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10444 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10445 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10446 }
10447 return instance;
10448 }
Hui Wang761a6682020-10-31 05:12:53 +000010449
10450 /**
10451 * indicate whether the device and the carrier can support
10452 * RCS VoLTE single registration.
10453 */
10454 @Override
10455 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010456 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10457 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10458 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10459 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010460
10461 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10462 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10463 }
10464
10465 final long identity = Binder.clearCallingIdentity();
10466 try {
10467 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10468 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010469 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10470 if (isCapable != null) {
10471 return isCapable;
10472 }
Hui Wang761a6682020-10-31 05:12:53 +000010473 }
Hui Wang67af90e2021-06-04 16:57:15 -070010474 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10475 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010476 } finally {
10477 Binder.restoreCallingIdentity(identity);
10478 }
10479 }
10480
10481 /**
10482 * Register RCS provisioning callback.
10483 */
10484 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010485 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010486 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010487 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010488 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010489 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10490 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010491
10492 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10493 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10494 }
10495 if (!isImsAvailableOnDevice()) {
10496 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10497 "IMS not available on device.");
10498 }
10499
10500 final long identity = Binder.clearCallingIdentity();
10501 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010502 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010503 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010504 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10505 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010506 }
Hui Wang761a6682020-10-31 05:12:53 +000010507 } finally {
10508 Binder.restoreCallingIdentity(identity);
10509 }
10510 }
10511
10512 /**
10513 * Unregister RCS provisioning callback.
10514 */
10515 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010516 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010517 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010518 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010519 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010520 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10521 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010522
10523 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10524 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10525 }
10526 if (!isImsAvailableOnDevice()) {
10527 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10528 "IMS not available on device.");
10529 }
10530
10531 final long identity = Binder.clearCallingIdentity();
10532 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010533 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010534 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010535 } finally {
10536 Binder.restoreCallingIdentity(identity);
10537 }
10538 }
10539
10540 /**
10541 * trigger RCS reconfiguration.
10542 */
10543 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010544 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10545 "triggerRcsReconfiguration",
10546 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010547
10548 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10549 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10550 }
10551 if (!isImsAvailableOnDevice()) {
10552 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10553 "IMS not available on device.");
10554 }
10555
10556 final long identity = Binder.clearCallingIdentity();
10557 try {
10558 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10559 } finally {
10560 Binder.restoreCallingIdentity(identity);
10561 }
10562 }
10563
10564 /**
10565 * Provide the client configuration parameters of the RCS application.
10566 */
10567 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010568 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10569 "setRcsClientConfiguration",
10570 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010571
10572 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10573 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10574 }
10575 if (!isImsAvailableOnDevice()) {
10576 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10577 "IMS not available on device.");
10578 }
10579
10580 final long identity = Binder.clearCallingIdentity();
10581
10582 try {
10583 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10584 if (configBinder == null) {
10585 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010586 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10587 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010588 } else {
10589 configBinder.setRcsClientConfiguration(rcc);
10590 }
joonhunshin3e154242021-09-17 06:33:39 +000010591
10592 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10593 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010594 } catch (RemoteException e) {
10595 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010596 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10597 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010598 } finally {
10599 Binder.restoreCallingIdentity(identity);
10600 }
10601 }
10602
10603 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010604 * Enables or disables the test mode for RCS VoLTE single registration.
10605 */
10606 @Override
10607 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10608 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10609 "setRcsSingleRegistrationTestModeEnabled");
10610
10611 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10612 }
10613
10614 /**
10615 * Gets the test mode for RCS VoLTE single registration.
10616 */
10617 @Override
10618 public boolean getRcsSingleRegistrationTestModeEnabled() {
10619 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10620 "getRcsSingleRegistrationTestModeEnabled");
10621
10622 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10623 }
10624
10625 /**
Hui Wang761a6682020-10-31 05:12:53 +000010626 * Overrides the config of RCS VoLTE single registration enabled for the device.
10627 */
10628 @Override
10629 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10630 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10631 "setDeviceSingleRegistrationEnabledOverride");
10632 enforceModifyPermission();
10633
10634 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10635 : Boolean.parseBoolean(enabledStr);
10636 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010637 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010638 }
10639
10640 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010641 * Sends a device to device communication message. Only usable via shell.
10642 * @param message message to send.
10643 * @param value message value.
10644 */
10645 @Override
10646 public void sendDeviceToDeviceMessage(int message, int value) {
10647 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010648 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010649 enforceModifyPermission();
10650
10651 final long identity = Binder.clearCallingIdentity();
10652 try {
10653 TelephonyConnectionService service =
10654 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10655 if (service == null) {
10656 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10657 return;
10658 }
10659 service.sendTestDeviceToDeviceMessage(message, value);
10660 } finally {
10661 Binder.restoreCallingIdentity(identity);
10662 }
10663 }
10664
Tyler Gunnbabbda02021-02-10 11:05:02 -080010665 /**
10666 * Sets the specified device to device transport active.
10667 * @param transport The transport to set active.
10668 */
10669 @Override
10670 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10671 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10672 "setActiveDeviceToDeviceTransport");
10673 enforceModifyPermission();
10674
10675 final long identity = Binder.clearCallingIdentity();
10676 try {
10677 TelephonyConnectionService service =
10678 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10679 if (service == null) {
10680 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10681 return;
10682 }
10683 service.setActiveDeviceToDeviceTransport(transport);
10684 } finally {
10685 Binder.restoreCallingIdentity(identity);
10686 }
10687 }
Tyler Gunn92479152021-01-20 16:30:10 -080010688
Tyler Gunnd4339262021-05-03 14:46:49 -070010689 @Override
10690 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10691 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10692 "setDeviceToDeviceForceEnabled");
10693
10694 final long identity = Binder.clearCallingIdentity();
10695 try {
10696 Arrays.stream(PhoneFactory.getPhones()).forEach(
10697 p -> {
10698 Phone thePhone = p.getImsPhone();
10699 if (thePhone != null && thePhone instanceof ImsPhone) {
10700 ImsPhone imsPhone = (ImsPhone) thePhone;
10701 CallTracker tracker = imsPhone.getCallTracker();
10702 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10703 ImsPhoneCallTracker imsPhoneCallTracker =
10704 (ImsPhoneCallTracker) tracker;
10705 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10706 }
10707 }
10708 }
10709 );
10710 } finally {
10711 Binder.restoreCallingIdentity(identity);
10712 }
10713 }
10714
Tyler Gunn92479152021-01-20 16:30:10 -080010715 /**
Hui Wang761a6682020-10-31 05:12:53 +000010716 * Gets the config of RCS VoLTE single registration enabled for the device.
10717 */
10718 @Override
10719 public boolean getDeviceSingleRegistrationEnabled() {
10720 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10721 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10722 }
10723
10724 /**
10725 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10726 */
10727 @Override
10728 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10729 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10730 "setCarrierSingleRegistrationEnabledOverride");
10731 enforceModifyPermission();
10732
10733 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10734 : Boolean.parseBoolean(enabledStr);
10735 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10736 subId, enabled);
10737 }
10738
10739 /**
10740 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10741 */
10742 @Override
10743 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10744 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10745 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10746 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010747
10748 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010749 * Overrides the ims feature validation result
10750 */
10751 @Override
10752 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10753 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10754 "setImsFeatureValidationOverride");
10755
10756 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10757 : Boolean.parseBoolean(enabledStr);
10758 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10759 subId, enabled);
10760 }
10761
10762 /**
10763 * Gets the ims feature validation override value
10764 */
10765 @Override
10766 public boolean getImsFeatureValidationOverride(int subId) {
10767 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10768 "getImsFeatureValidationOverride");
10769 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10770 }
10771
10772 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010773 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10774 * their mobile plan.
10775 */
10776 @Override
10777 public String getMobileProvisioningUrl() {
10778 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10779 final long identity = Binder.clearCallingIdentity();
10780 try {
10781 return getDefaultPhone().getMobileProvisioningUrl();
10782 } finally {
10783 Binder.restoreCallingIdentity(identity);
10784 }
10785 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010786
James.cf Linbcdf8b32021-01-14 16:44:13 +080010787 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010788 * Get the EAB contact from the EAB database.
10789 */
10790 @Override
10791 public String getContactFromEab(String contact) {
10792 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10793 enforceModifyPermission();
10794 final long identity = Binder.clearCallingIdentity();
10795 try {
10796 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10797 } finally {
10798 Binder.restoreCallingIdentity(identity);
10799 }
10800 }
10801
10802 /**
Calvin Pana1434322021-07-01 19:27:01 +080010803 * Get the EAB capability from the EAB database.
10804 */
10805 @Override
10806 public String getCapabilityFromEab(String contact) {
10807 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10808 enforceModifyPermission();
10809 final long identity = Binder.clearCallingIdentity();
10810 try {
10811 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10812 } finally {
10813 Binder.restoreCallingIdentity(identity);
10814 }
10815 }
10816
10817 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010818 * Remove the EAB contacts from the EAB database.
10819 */
10820 @Override
10821 public int removeContactFromEab(int subId, String contacts) {
10822 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10823 enforceModifyPermission();
10824 final long identity = Binder.clearCallingIdentity();
10825 try {
10826 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10827 } finally {
10828 Binder.restoreCallingIdentity(identity);
10829 }
10830 }
10831
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010832 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010833 public boolean getDeviceUceEnabled() {
10834 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10835 final long identity = Binder.clearCallingIdentity();
10836 try {
10837 return mApp.getDeviceUceEnabled();
10838 } finally {
10839 Binder.restoreCallingIdentity(identity);
10840 }
10841 }
10842
10843 @Override
10844 public void setDeviceUceEnabled(boolean isEnabled) {
10845 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10846 final long identity = Binder.clearCallingIdentity();
10847 try {
10848 mApp.setDeviceUceEnabled(isEnabled);
10849 } finally {
10850 Binder.restoreCallingIdentity(identity);
10851 }
10852 }
10853
Brad Ebinger14d467f2021-02-12 06:18:28 +000010854 /**
10855 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10856 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10857 */
10858 // Used for SHELL command only right now.
10859 @Override
10860 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10861 List<String> featureTags) {
10862 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10863 "addUceRegistrationOverrideShell");
10864 final long identity = Binder.clearCallingIdentity();
10865 try {
10866 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10867 new ArraySet<>(featureTags));
10868 } catch (ImsException e) {
10869 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10870 } finally {
10871 Binder.restoreCallingIdentity(identity);
10872 }
10873 }
10874
10875 /**
10876 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10877 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10878 */
10879 // Used for SHELL command only right now.
10880 @Override
10881 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10882 List<String> featureTags) {
10883 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10884 "removeUceRegistrationOverrideShell");
10885 final long identity = Binder.clearCallingIdentity();
10886 try {
10887 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10888 new ArraySet<>(featureTags));
10889 } catch (ImsException e) {
10890 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10891 } finally {
10892 Binder.restoreCallingIdentity(identity);
10893 }
10894 }
10895
10896 /**
10897 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10898 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10899 */
10900 // Used for SHELL command only right now.
10901 @Override
10902 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10903 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10904 "clearUceRegistrationOverrideShell");
10905 final long identity = Binder.clearCallingIdentity();
10906 try {
10907 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10908 } catch (ImsException e) {
10909 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10910 } finally {
10911 Binder.restoreCallingIdentity(identity);
10912 }
10913 }
10914
10915 /**
10916 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10917 */
10918 // Used for SHELL command only right now.
10919 @Override
10920 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10921 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10922 "getLatestRcsContactUceCapabilityShell");
10923 final long identity = Binder.clearCallingIdentity();
10924 try {
10925 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10926 } catch (ImsException e) {
10927 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10928 } finally {
10929 Binder.restoreCallingIdentity(identity);
10930 }
10931 }
10932
10933 /**
10934 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10935 * device does not have an active PUBLISH.
10936 */
10937 // Used for SHELL command only right now.
10938 @Override
10939 public String getLastUcePidfXmlShell(int subId) {
10940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10941 final long identity = Binder.clearCallingIdentity();
10942 try {
10943 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10944 } catch (ImsException e) {
10945 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10946 } finally {
10947 Binder.restoreCallingIdentity(identity);
10948 }
10949 }
10950
James.cf Line8713a42021-04-29 16:04:26 +080010951 /**
10952 * Remove UCE requests cannot be sent to the network status.
10953 */
10954 // Used for SHELL command only right now.
10955 @Override
10956 public boolean removeUceRequestDisallowedStatus(int subId) {
10957 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10958 final long identity = Binder.clearCallingIdentity();
10959 try {
10960 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10961 } catch (ImsException e) {
10962 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10963 } finally {
10964 Binder.restoreCallingIdentity(identity);
10965 }
10966 }
10967
James.cf Lin18bb9002021-05-25 01:37:38 +080010968 /**
10969 * Remove UCE requests cannot be sent to the network status.
10970 */
10971 // Used for SHELL command only.
10972 @Override
10973 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10974 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10975 final long identity = Binder.clearCallingIdentity();
10976 try {
10977 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10978 } catch (ImsException e) {
10979 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10980 } finally {
10981 Binder.restoreCallingIdentity(identity);
10982 }
10983 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010984
James.cf Lin4b784aa2021-01-31 03:25:15 +080010985 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010986 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10987 String callingPackage) {
10988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10989 mApp, subId, "setSignalStrengthUpdateRequest");
10990
10991 final int callingUid = Binder.getCallingUid();
10992 // Verify that tha callingPackage belongs to the calling UID
10993 mApp.getSystemService(AppOpsManager.class)
10994 .checkPackage(callingUid, callingPackage);
10995
Rambo Wang3607f502021-02-01 21:51:40 -080010996 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010997
10998 final long identity = Binder.clearCallingIdentity();
10999 try {
11000 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11001 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11002
11003 if (result instanceof IllegalStateException) {
11004 throw (IllegalStateException) result;
11005 }
11006 } finally {
11007 Binder.restoreCallingIdentity(identity);
11008 }
11009 }
11010
11011 @Override
11012 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11013 String callingPackage) {
11014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11015 mApp, subId, "clearSignalStrengthUpdateRequest");
11016
11017 final int callingUid = Binder.getCallingUid();
11018 // Verify that tha callingPackage belongs to the calling UID
11019 mApp.getSystemService(AppOpsManager.class)
11020 .checkPackage(callingUid, callingPackage);
11021
11022 final long identity = Binder.clearCallingIdentity();
11023 try {
11024 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11025 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11026
11027 if (result instanceof IllegalStateException) {
11028 throw (IllegalStateException) result;
11029 }
11030 } finally {
11031 Binder.restoreCallingIdentity(identity);
11032 }
11033 }
11034
Rambo Wang3607f502021-02-01 21:51:40 -080011035 private static void validateSignalStrengthUpdateRequest(Context context,
11036 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011037 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11038 // phone/system process do not have further restriction on request
11039 return;
11040 }
11041
11042 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011043 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011044 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011045 context.enforceCallingOrSelfPermission(
11046 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11047 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011048 }
11049
11050 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11051 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11052 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11053 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11054 || info.isEnabled()) {
11055 throw new IllegalArgumentException(
11056 "Only system can set hide fields in SignalThresholdInfo");
11057 }
11058
11059 // Thresholds length for each RAN need in range. This has been validated in
11060 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11061 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11062 final int[] thresholds = info.getThresholds();
11063 Objects.requireNonNull(thresholds);
11064 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11065 || thresholds.length
11066 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11067 throw new IllegalArgumentException(
11068 "thresholds length is out of range: " + thresholds.length);
11069 }
11070 }
11071 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011072
11073 /**
11074 * Gets the current phone capability.
11075 *
11076 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11077 * @return the PhoneCapability which describes the data connection capability of modem.
11078 * It's used to evaluate possible phone config change, for example from single
11079 * SIM device to multi-SIM device.
11080 */
11081 @Override
11082 public PhoneCapability getPhoneCapability() {
11083 enforceReadPrivilegedPermission("getPhoneCapability");
11084 final long identity = Binder.clearCallingIdentity();
11085 try {
11086 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11087 } finally {
11088 Binder.restoreCallingIdentity(identity);
11089 }
11090 }
Michele Berionne5e411512020-11-13 02:36:59 +000011091
11092 /**
11093 * Prepare TelephonyManager for an unattended reboot. The reboot is
11094 * required to be done shortly after the API is invoked.
11095 */
11096 @Override
11097 @TelephonyManager.PrepareUnattendedRebootResult
11098 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011099 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011100 enforceRebootPermission();
11101
11102 final long identity = Binder.clearCallingIdentity();
11103 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011104 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011105 } finally {
11106 Binder.restoreCallingIdentity(identity);
11107 }
11108 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011109
11110 /**
11111 * Request to get the current slicing configuration including URSP rules and
11112 * NSSAIs (configured, allowed and rejected).
11113 *
11114 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11115 */
11116 @Override
11117 public void getSlicingConfig(ResultReceiver callback) {
11118 enforceReadPrivilegedPermission("getSlicingConfig");
11119
11120 final long identity = Binder.clearCallingIdentity();
11121 try {
11122 Phone phone = getDefaultPhone();
11123 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11124 } finally {
11125 Binder.restoreCallingIdentity(identity);
11126 }
11127 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011128
11129 /**
11130 * Register an IMS connection state callback
11131 */
11132 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011133 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11134 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011135 if (feature == ImsFeature.FEATURE_MMTEL) {
11136 // ImsMmTelManager
11137 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11138 TelephonyPermissions
11139 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11140 mApp, subId, "registerImsStateCallback");
11141 } else if (feature == ImsFeature.FEATURE_RCS) {
11142 // ImsRcsManager or SipDelegateManager
11143 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11144 Binder.getCallingUid(), "registerImsStateCallback",
11145 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11146 Manifest.permission.READ_PRECISE_PHONE_STATE,
11147 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11148 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11149 }
11150
11151 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11152 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11153 "IMS not available on device.");
11154 }
11155
11156 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11157 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11158 }
11159
11160 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11161 if (controller == null) {
11162 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11163 "IMS not available on device.");
11164 }
11165
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011166 if (callingPackage == null) {
11167 callingPackage = getCurrentPackageName();
11168 }
11169
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011170 final long token = Binder.clearCallingIdentity();
11171 try {
11172 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011173 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011174 } catch (ImsException e) {
11175 throw new ServiceSpecificException(e.getCode());
11176 } finally {
11177 Binder.restoreCallingIdentity(token);
11178 }
11179 }
11180
11181 /**
11182 * Unregister an IMS connection state callback
11183 */
11184 @Override
11185 public void unregisterImsStateCallback(IImsStateCallback cb) {
11186 final long token = Binder.clearCallingIdentity();
11187 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11188 if (controller == null) {
11189 return;
11190 }
11191 try {
11192 controller.unregisterImsStateCallback(cb);
11193 } finally {
11194 Binder.restoreCallingIdentity(token);
11195 }
11196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011197}