blob: ba8b33017c1a0524879d83011138c468aeab72dd [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;
Tyler Gunn64144d92022-03-17 14:16:41 -070034import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000035import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080036import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
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;
Gary Jian3aa9a762022-01-24 16:41:19 +080075import android.telephony.AccessNetworkConstants;
76import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070077import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070078import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080079import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080080import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070081import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080082import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070083import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080084import android.telephony.CellIdentityCdma;
85import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070087import android.telephony.CellInfoGsm;
88import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070089import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080090import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070091import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070092import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070093import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080094import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070095import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080096import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070097import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080098import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080099import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700100import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800101import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800103import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800104import android.telephony.SignalStrengthUpdateRequest;
105import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800106import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800107import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800108import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700109import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700110import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800111import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800112import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800113import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000114import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000115import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000116import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700117import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700118import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800119import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800120import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700121import android.telephony.gba.GbaAuthRequest;
122import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700123import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000126import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700127import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000128import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700129import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800130import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700131import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800132import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700133import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000134import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700135import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800136import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800137import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700140import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800142import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800143
Andrew Lee312e8172014-10-23 17:01:36 -0700144import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800145import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800146import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800147import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700150import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700151import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800152import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800153import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800156import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700157import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800158import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800159import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800160import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700161import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000162import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800164import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800166import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800167import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700168import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700169import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700170import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700172import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800173import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700174import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700175import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700176import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700177import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800178import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800179import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700180import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700181import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700182import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800183import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800184import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800185import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700186import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700188import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800189import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700190import com.android.internal.telephony.imsphone.ImsPhone;
191import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000192import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800193import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700194import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195import com.android.internal.telephony.uicc.IccIoResult;
196import 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;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800228import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800229import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800230import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800231import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100232import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800233import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700234import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800235import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800236import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800237import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800238import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800239import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240
241/**
242 * Implementation of the ITelephony interface.
243 */
Santos Cordon117fee72014-05-16 17:56:12 -0700244public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245 private static final String LOG_TAG = "PhoneInterfaceManager";
246 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
247 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800248 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249
250 // Message codes used with mMainThreadHandler
251 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700252 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
253 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700254 private static final int CMD_OPEN_CHANNEL = 9;
255 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
256 private static final int CMD_CLOSE_CHANNEL = 11;
257 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800258 private static final int CMD_NV_READ_ITEM = 13;
259 private static final int EVENT_NV_READ_ITEM_DONE = 14;
260 private static final int CMD_NV_WRITE_ITEM = 15;
261 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
262 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
263 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700264 private static final int CMD_RESET_MODEM_CONFIG = 19;
265 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800266 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
267 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800268 private static final int CMD_SEND_ENVELOPE = 25;
269 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000270 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
271 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700272 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
273 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
274 private static final int CMD_EXCHANGE_SIM_IO = 31;
275 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800276 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
277 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700278 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
279 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700280 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
281 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700282 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
283 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
284 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
285 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700286 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
287 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
288 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
289 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700290 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800291 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
292 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000293 private static final int CMD_SWITCH_SLOTS = 50;
294 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700295 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
296 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
297 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
298 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
299 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
300 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
301 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
302 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700303 private static final int CMD_GET_ALL_CELL_INFO = 60;
304 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
305 private static final int CMD_GET_CELL_LOCATION = 62;
306 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700307 private static final int CMD_MODEM_REBOOT = 64;
308 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700309 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
310 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800311 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
312 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700313 private static final int CMD_GET_MODEM_STATUS = 70;
314 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700315 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
316 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700317 private static final int CMD_ERASE_MODEM_CONFIG = 74;
318 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800319 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
320 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
321 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
322 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800323 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
324 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800325 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800326 private static final int CMD_GET_CALL_FORWARDING = 83;
327 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
328 private static final int CMD_SET_CALL_FORWARDING = 85;
329 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
330 private static final int CMD_GET_CALL_WAITING = 87;
331 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
332 private static final int CMD_SET_CALL_WAITING = 89;
333 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700334 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
335 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
336 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
337 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700338 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
339 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800340 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
341 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800342 private static final int CMD_SET_DATA_THROTTLING = 99;
343 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800344 private static final int CMD_SET_SIM_POWER = 101;
345 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800346 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
347 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
348 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
349 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800350 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
351 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000352 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800353 private static final int CMD_GET_SLICING_CONFIG = 110;
354 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800355 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700356 private static final int CMD_ENABLE_VONR = 113;
357 private static final int EVENT_ENABLE_VONR_DONE = 114;
358 private static final int CMD_IS_VONR_ENABLED = 115;
359 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800361 // Parameters of select command.
362 private static final int SELECT_COMMAND = 0xA4;
363 private static final int SELECT_P1 = 0x04;
364 private static final int SELECT_P2 = 0;
365 private static final int SELECT_P3 = 0x10;
366
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 /** The singleton instance. */
368 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800369 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Wink Saville3ab207e2014-11-20 13:07:20 -0800371 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800373 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700374 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700376 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800378 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700380 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800381 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000382 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383
Peter Wangdafb9ac2020-01-15 14:13:38 -0800384 /** User Activity */
385 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800386 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
387
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700388 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
389
Derek Tan97ebb422014-09-05 16:55:38 -0700390 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
391 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800392 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800393 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700394
Michelecea4cf22018-12-21 15:00:11 -0800395 // String to store multi SIM allowed
396 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
397
Derek Tan740e1672017-06-27 14:56:27 -0700398 // The AID of ISD-R.
399 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
400
yinxub1bed742017-04-17 11:45:04 -0700401 private NetworkScanRequestTracker mNetworkScanRequestTracker;
402
David Kelly5e06a7f2018-03-12 14:10:59 +0000403 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
404 private static final int MANUFACTURER_CODE_LENGTH = 8;
405
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800406 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800407 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800408
Derek Tan89e89d42014-07-08 17:00:10 -0700409 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700410 * Experiment flag to enable erase modem config on reset network, default value is false
411 */
412 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
413 "reset_network_erase_modem_config_enabled";
414
Rambo Wang0f050d82021-02-12 11:43:36 -0800415 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800416
sandeepjsb6c87872021-09-27 15:34:44 +0000417 /**
418 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
419 * one ICCID active at the same time.
420 * Apps should use below API signatures if targeting SDK is T and beyond.
421 *
422 * @hide
423 */
424 @ChangeId
425 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
426 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800427
Naina Nallurid63128d2019-09-17 14:10:30 -0700428 /**
Chen Xu540470b2021-12-14 17:15:47 -0800429 * Apps targeting on Android T and beyond will get exception whenever icc close channel
430 * operation fails.
431 */
432 @ChangeId
433 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
434 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
435
436 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 * A request object to use for transmitting data to an ICC.
438 */
439 private static final class IccAPDUArgument {
440 public int channel, cla, command, p1, p2, p3;
441 public String data;
442
443 public IccAPDUArgument(int channel, int cla, int command,
444 int p1, int p2, int p3, String data) {
445 this.channel = channel;
446 this.cla = cla;
447 this.command = command;
448 this.p1 = p1;
449 this.p2 = p2;
450 this.p3 = p3;
451 this.data = data;
452 }
453 }
454
455 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700456 * A request object to use for transmitting data to an ICC.
457 */
458 private static final class ManualNetworkSelectionArgument {
459 public OperatorInfo operatorInfo;
460 public boolean persistSelection;
461
462 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
463 this.operatorInfo = operatorInfo;
464 this.persistSelection = persistSelection;
465 }
466 }
467
468 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
470 * request after sending. The main thread will notify the request when it is complete.
471 */
472 private static final class MainThreadRequest {
473 /** The argument to use for the request */
474 public Object argument;
475 /** The result of the request that is run on the main thread */
476 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800477 // The subscriber id that this request applies to. Defaults to
478 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
479 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480
Nathan Harold92bed182018-10-12 18:16:49 -0700481 // In cases where subId is unavailable, the caller needs to specify the phone.
482 public Phone phone;
483
vagdeviaf9a5b92018-08-15 16:01:53 -0700484 public WorkSource workSource;
485
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 public MainThreadRequest(Object argument) {
487 this.argument = argument;
488 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800489
Nathan Harold92bed182018-10-12 18:16:49 -0700490 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
491 this.argument = argument;
492 if (phone != null) {
493 this.phone = phone;
494 }
495 this.workSource = workSource;
496 }
497
vagdeviaf9a5b92018-08-15 16:01:53 -0700498 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800499 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800500 if (subId != null) {
501 this.subId = subId;
502 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700503 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505 }
506
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800507 private static final class IncomingThirdPartyCallArgs {
508 public final ComponentName component;
509 public final String callId;
510 public final String callerDisplayName;
511
512 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
513 String callerDisplayName) {
514 this.component = component;
515 this.callId = callId;
516 this.callerDisplayName = callerDisplayName;
517 }
518 }
519
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 /**
521 * A handler that processes messages on the main thread in the phone process. Since many
522 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
523 * inbound binder threads to the main thread in the phone process. The Binder thread
524 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
525 * on, which will be notified when the operation completes and will contain the result of the
526 * request.
527 *
528 * <p>If a MainThreadRequest object is provided in the msg.obj field,
529 * note that request.result must be set to something non-null for the calling thread to
530 * unblock.
531 */
532 private final class MainThreadHandler extends Handler {
533 @Override
534 public void handleMessage(Message msg) {
535 MainThreadRequest request;
536 Message onCompleted;
537 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000538 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800540 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541
542 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 case CMD_HANDLE_USSD_REQUEST: {
544 request = (MainThreadRequest) msg.obj;
545 final Phone phone = getPhoneFromRequest(request);
546 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800547 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700549
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 if (!isUssdApiAllowed(request.subId)) {
551 // Carrier does not support use of this API, return failure.
552 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
553 UssdResponse response = new UssdResponse(ussdRequest, null);
554 Bundle returnData = new Bundle();
555 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
556 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700557
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 request.result = true;
559 notifyRequester(request);
560 return;
561 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700562
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 try {
564 request.result = phone != null
565 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
566 } catch (CallStateException cse) {
567 request.result = false;
568 }
569 // Wake up the requesting thread
570 notifyRequester(request);
571 break;
pkanwar32d516d2016-10-14 19:37:38 -0700572 }
573
Yorke Lee716f67e2015-06-17 15:39:16 -0700574 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700575 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700576 final Phone phone = getPhoneFromRequest(request);
577 request.result = phone != null ?
578 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
579 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700580 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700582 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700584
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000588 uiccPort = getUiccPortFromRequest(request);
589 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800591 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800595 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000596 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800597 iccArgument.channel, iccArgument.cla, iccArgument.command,
598 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
599 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 break;
602
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
608 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800609 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 if (ar.result == null) {
611 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800612 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800614 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 } else {
616 loge("iccTransmitApduLogicalChannel: Unknown exception");
617 }
618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 break;
621
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
624 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000625 uiccPort = getUiccPortFromRequest(request);
626 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800628 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800632 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000633 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800634 iccArgument.cla, iccArgument.command, iccArgument.p1,
635 iccArgument.p2,
636 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 }
638 break;
639
640 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
645 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800646 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 if (ar.result == null) {
648 loge("iccTransmitApduBasicChannel: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("iccTransmitApduBasicChannel: CommandException: " +
651 ar.exception);
652 } else {
653 loge("iccTransmitApduBasicChannel: Unknown exception");
654 }
655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 break;
658
659 case CMD_EXCHANGE_SIM_IO:
660 request = (MainThreadRequest) msg.obj;
661 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000662 uiccPort = getUiccPortFromRequest(request);
663 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800665 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 } else {
668 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
669 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000670 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
672 iccArgument.data, onCompleted);
673 }
674 break;
675
676 case EVENT_EXCHANGE_SIM_IO_DONE:
677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result;
681 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 break;
686
Derek Tan4d5e5c12014-02-04 11:54:58 -0800687 case CMD_SEND_ENVELOPE:
688 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000689 uiccPort = getUiccPortFromRequest(request);
690 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800692 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 } else {
695 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800696 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800698 break;
699
700 case EVENT_SEND_ENVELOPE_DONE:
701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800706 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700707 if (ar.result == null) {
708 loge("sendEnvelopeWithStatus: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("sendEnvelopeWithStatus: CommandException: " +
711 ar.exception);
712 } else {
713 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
714 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800717 break;
718
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 case CMD_OPEN_CHANNEL:
720 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000721 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800722 IccLogicalChannelRequest openChannelRequest =
723 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800726 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800727 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 } else {
730 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800731 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
732 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 break;
735
736 case EVENT_OPEN_CHANNEL_DONE:
737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 int[] result = (int[]) ar.result;
742 int channelId = result[0];
743 byte[] selectResponse = null;
744 if (result.length > 1) {
745 selectResponse = new byte[result.length - 1];
746 for (int i = 1; i < result.length; ++i) {
747 selectResponse[i - 1] = (byte) result[i];
748 }
749 }
750 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800751 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800752
753 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700754 if (uiccPort == null) {
755 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
756 } else {
757 IccLogicalChannelRequest channelRequest =
758 (IccLogicalChannelRequest) request.argument;
759 channelRequest.channel = channelId;
760 uiccPort.onLogicalChannelOpened(channelRequest);
761 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 if (ar.result == null) {
764 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700766 if (ar.exception != null) {
767 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
768 }
769
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700770 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700771 if (ar.exception instanceof CommandException) {
772 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800773 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700774 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700775 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700776 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700777 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700778 }
779 }
780 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800781 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700783 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700784 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 break;
786
787 case CMD_CLOSE_CHANNEL:
788 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000789 uiccPort = getUiccPortFromRequest(request);
790 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700791 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800792 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800793 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800794 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700795 } else {
796 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000797 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700798 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 break;
800
801 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
804 if (ar.exception == null) {
805 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800806 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700807 if (uiccPort == null) {
808 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
809 } else {
810 final int channelId = (Integer) request.argument;
811 uiccPort.onLogicalChannelClosed(channelId);
812 }
Chen Xu540470b2021-12-14 17:15:47 -0800813 } else {
814 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800815 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800816 if (ar.exception instanceof CommandException) {
817 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
818 CommandException.Error error =
819 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800820 if (error == CommandException.Error.INVALID_ARGUMENTS) {
821 // should only throw exceptions from the binder threads.
822 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800823 "iccCloseLogicalChannel: invalid argument ");
824 }
825 } else {
826 loge("iccCloseLogicalChannel: Unknown exception");
827 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800828 request.result = (exception != null) ? exception :
829 new IllegalStateException(
830 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800831 }
832 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800833 break;
834
835 case CMD_NV_READ_ITEM:
836 request = (MainThreadRequest) msg.obj;
837 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800838 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
839 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800840 break;
841
842 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800845 if (ar.exception == null && ar.result != null) {
846 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700847 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800848 request.result = "";
849 if (ar.result == null) {
850 loge("nvReadItem: Empty response");
851 } else if (ar.exception instanceof CommandException) {
852 loge("nvReadItem: CommandException: " +
853 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700854 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800855 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700856 }
857 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700858 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700859 break;
860
Jake Hambye994d462014-02-03 13:10:13 -0800861 case CMD_NV_WRITE_ITEM:
862 request = (MainThreadRequest) msg.obj;
863 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
864 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800865 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700866 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800867 break;
868
869 case EVENT_NV_WRITE_ITEM_DONE:
870 handleNullReturnEvent(msg, "nvWriteItem");
871 break;
872
873 case CMD_NV_WRITE_CDMA_PRL:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800876 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800877 break;
878
879 case EVENT_NV_WRITE_CDMA_PRL_DONE:
880 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
881 break;
882
chen xu6dac5ab2018-10-26 17:39:23 -0700883 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800884 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700885 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800886 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800887 break;
888
chen xu6dac5ab2018-10-26 17:39:23 -0700889 case EVENT_RESET_MODEM_CONFIG_DONE:
890 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800891 break;
892
Sooraj Sasindran37444802020-08-11 10:40:43 -0700893 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
894 request = (MainThreadRequest) msg.obj;
895 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
896 request);
897 Phone phone = getPhoneFromRequest(request);
898 if (phone != null) {
899 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
900 } else {
901 loge("isNRDualConnectivityEnabled: No phone object");
902 request.result = false;
903 notifyRequester(request);
904 }
905 break;
906 }
907
908 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result;
913 } else {
914 // request.result must be set to something non-null
915 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700916 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700917 request.result = ar.result;
918 } else {
919 request.result = false;
920 }
921 if (ar.result == null) {
922 loge("isNRDualConnectivityEnabled: Empty response");
923 } else if (ar.exception instanceof CommandException) {
924 loge("isNRDualConnectivityEnabled: CommandException: "
925 + ar.exception);
926 } else {
927 loge("isNRDualConnectivityEnabled: Unknown exception");
928 }
929 }
930 notifyRequester(request);
931 break;
932
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700933 case CMD_IS_VONR_ENABLED: {
934 request = (MainThreadRequest) msg.obj;
935 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
936 request);
937 Phone phone = getPhoneFromRequest(request);
938 if (phone != null) {
939 phone.isVoNrEnabled(onCompleted, request.workSource);
940 } else {
941 loge("isVoNrEnabled: No phone object");
942 request.result = false;
943 notifyRequester(request);
944 }
945 break;
946 }
947
948 case EVENT_IS_VONR_ENABLED_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 if (ar.exception == null && ar.result != null) {
952 request.result = ar.result;
953 } else {
954 // request.result must be set to something non-null
955 // for the calling thread to unblock
956 if (ar.result != null) {
957 request.result = ar.result;
958 } else {
959 request.result = false;
960 }
961 if (ar.result == null) {
962 loge("isVoNrEnabled: Empty response");
963 } else if (ar.exception instanceof CommandException) {
964 loge("isVoNrEnabled: CommandException: "
965 + ar.exception);
966 } else {
967 loge("isVoNrEnabled: Unknown exception");
968 }
969 }
970 notifyRequester(request);
971 break;
972
Sooraj Sasindran37444802020-08-11 10:40:43 -0700973 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
974 request = (MainThreadRequest) msg.obj;
975 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
976 Phone phone = getPhoneFromRequest(request);
977 if (phone != null) {
978 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
979 request.workSource);
980 } else {
981 loge("enableNrDualConnectivity: No phone object");
982 request.result =
983 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
984 notifyRequester(request);
985 }
986 break;
987 }
988
989 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 if (ar.exception == null) {
993 request.result =
994 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
995 } else {
996 request.result =
997 TelephonyManager
998 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
999 if (ar.exception instanceof CommandException) {
1000 CommandException.Error error =
1001 ((CommandException) (ar.exception)).getCommandError();
1002 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1003 request.result =
1004 TelephonyManager
1005 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001006 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1007 request.result =
1008 TelephonyManager
1009 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001010 }
1011 loge("enableNrDualConnectivity" + ": CommandException: "
1012 + ar.exception);
1013 } else {
1014 loge("enableNrDualConnectivity" + ": Unknown exception");
1015 }
1016 }
1017 notifyRequester(request);
1018 break;
1019 }
1020
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001021 case CMD_ENABLE_VONR: {
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1024 Phone phone = getPhoneFromRequest(request);
1025 if (phone != null) {
1026 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1027 request.workSource);
1028 } else {
1029 loge("setVoNrEnabled: No phone object");
1030 request.result =
1031 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1032 notifyRequester(request);
1033 }
1034 break;
1035 }
1036
1037 case EVENT_ENABLE_VONR_DONE: {
1038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
1040 if (ar.exception == null) {
1041 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1042 } else {
1043 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1044 if (ar.exception instanceof CommandException) {
1045 CommandException.Error error =
1046 ((CommandException) (ar.exception)).getCommandError();
1047 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1048 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1049 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1050 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1051 } else {
1052 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1053 }
1054 loge("setVoNrEnabled" + ": CommandException: "
1055 + ar.exception);
1056 } else {
1057 loge("setVoNrEnabled" + ": Unknown exception");
1058 }
1059 }
1060 notifyRequester(request);
1061 break;
1062 }
1063
SongFerngWang3ef3e072020-12-21 16:41:52 +08001064 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001065 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001066 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1067 request);
1068 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001069 break;
1070
SongFerngWang3ef3e072020-12-21 16:41:52 +08001071 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001072 ar = (AsyncResult) msg.obj;
1073 request = (MainThreadRequest) ar.userObj;
1074 if (ar.exception == null && ar.result != null) {
1075 request.result = ar.result; // Integer
1076 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301077 // request.result must be set to something non-null
1078 // for the calling thread to unblock
1079 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001080 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001081 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001082 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001083 loge("getAllowedNetworkTypesBitmask: CommandException: "
1084 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001087 }
1088 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001089 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 break;
1091
SongFerngWang3ef3e072020-12-21 16:41:52 +08001092 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001093 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001094 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1095 request);
1096 Pair<Integer, Long> reasonWithNetworkTypes =
1097 (Pair<Integer, Long>) request.argument;
1098 getPhoneFromRequest(request).setAllowedNetworkTypes(
1099 reasonWithNetworkTypes.first,
1100 reasonWithNetworkTypes.second,
1101 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001102 break;
1103
SongFerngWang3ef3e072020-12-21 16:41:52 +08001104 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1105 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001106 break;
1107
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001108 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1109 request = (MainThreadRequest)msg.obj;
1110 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001111 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001112 break;
1113
1114 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1115 ar = (AsyncResult)msg.obj;
1116 request = (MainThreadRequest)ar.userObj;
1117 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001118 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001119 break;
1120
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001121 case CMD_SET_VOICEMAIL_NUMBER:
1122 request = (MainThreadRequest) msg.obj;
1123 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1124 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001125 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1126 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001127 break;
1128
1129 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1130 handleNullReturnEvent(msg, "setVoicemailNumber");
1131 break;
1132
Stuart Scott54788802015-03-30 13:18:01 -07001133 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1134 request = (MainThreadRequest) msg.obj;
1135 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1136 request);
1137 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1138 break;
1139
1140 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1141 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1142 break;
1143
Shishir Agrawal302c8692015-06-19 13:49:39 -07001144 case CMD_PERFORM_NETWORK_SCAN:
1145 request = (MainThreadRequest) msg.obj;
1146 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1147 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1148 break;
1149
Hall Liu27d24262020-09-18 19:04:59 -07001150 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001151 request = (MainThreadRequest) msg.obj;
1152 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001153 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1154 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1155 request.argument;
1156 int callForwardingReason = args.first;
1157 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001158 break;
Hall Liu27d24262020-09-18 19:04:59 -07001159 }
1160 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001163 TelephonyManager.CallForwardingInfoCallback callback =
1164 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1165 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001166 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001167 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001168 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1169 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1170 // Service Class is a bit mask per 3gpp 27.007. Search for
1171 // any service for voice call.
1172 if ((callForwardInfo.serviceClass
1173 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001174 callForwardingInfo = new CallForwardingInfo(
1175 callForwardInfo.status
1176 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001177 callForwardInfo.reason,
1178 callForwardInfo.number,
1179 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001180 break;
1181 }
1182 }
1183 // Didn't find a call forward info for voice call.
1184 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001185 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1186 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001187 }
Hall Liu27d24262020-09-18 19:04:59 -07001188 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001189 } else {
1190 if (ar.result == null) {
1191 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1192 }
1193 if (ar.exception != null) {
1194 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1195 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001196 int errorCode = TelephonyManager
1197 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001198 if (ar.exception instanceof CommandException) {
1199 CommandException.Error error =
1200 ((CommandException) (ar.exception)).getCommandError();
1201 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001202 errorCode = TelephonyManager
1203 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001204 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001205 errorCode = TelephonyManager
1206 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 }
1208 }
Hall Liu27d24262020-09-18 19:04:59 -07001209 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001210 }
Shuo Qian4a594052020-01-23 11:59:30 -08001211 break;
Hall Liu27d24262020-09-18 19:04:59 -07001212 }
Shuo Qian4a594052020-01-23 11:59:30 -08001213
Hall Liu27d24262020-09-18 19:04:59 -07001214 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001215 request = (MainThreadRequest) msg.obj;
1216 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001217 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001218 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001219 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1220 request.argument).first;
1221 request.phone.setCallForwardingOption(
1222 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001223 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001224 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001225 callForwardingInfoToSet.getReason(),
1226 callForwardingInfoToSet.getNumber(),
1227 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1228 break;
Hall Liu27d24262020-09-18 19:04:59 -07001229 }
Shuo Qian4a594052020-01-23 11:59:30 -08001230
Hall Liu27d24262020-09-18 19:04:59 -07001231 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001232 ar = (AsyncResult) msg.obj;
1233 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001234 Consumer<Integer> callback =
1235 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1236 request.argument).second;
1237 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001238 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001239 int errorCode = TelephonyManager.CallForwardingInfoCallback
1240 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001241 if (ar.exception instanceof CommandException) {
1242 CommandException.Error error =
1243 ((CommandException) (ar.exception)).getCommandError();
1244 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001245 errorCode = TelephonyManager.CallForwardingInfoCallback
1246 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001247 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001248 errorCode = TelephonyManager.CallForwardingInfoCallback
1249 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001250 }
1251 }
1252 callback.accept(errorCode);
1253 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001254 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001255 }
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 CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001260 request = (MainThreadRequest) msg.obj;
1261 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1262 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1263 break;
Hall Liu27d24262020-09-18 19:04:59 -07001264 }
Shuo Qian4a594052020-01-23 11:59:30 -08001265
Hall Liu27d24262020-09-18 19:04:59 -07001266 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001269 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001270 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001271 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001272 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 // Service Class is a bit mask per 3gpp 27.007.
1274 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001275 if (callForwardResults.length > 1
1276 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001277 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001278 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001279 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1280 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001281 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001282 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001283 }
1284 } else {
1285 if (ar.result == null) {
1286 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1287 }
1288 if (ar.exception != null) {
1289 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1290 }
1291 if (ar.exception instanceof CommandException) {
1292 CommandException.Error error =
1293 ((CommandException) (ar.exception)).getCommandError();
1294 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001295 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001296 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001297 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1298 callWaitingStatus =
1299 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001300 }
1301 }
1302 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001303 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001304 break;
Hall Liu27d24262020-09-18 19:04:59 -07001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306
Hall Liu27d24262020-09-18 19:04:59 -07001307 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001308 request = (MainThreadRequest) msg.obj;
1309 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001310 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1311 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001312 break;
Hall Liu27d24262020-09-18 19:04:59 -07001313 }
Shuo Qian4a594052020-01-23 11:59:30 -08001314
Hall Liu27d24262020-09-18 19:04:59 -07001315 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001316 ar = (AsyncResult) msg.obj;
1317 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001318 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1319 Consumer<Integer> callback =
1320 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1321 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001322 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001323 if (ar.exception instanceof CommandException) {
1324 CommandException.Error error =
1325 ((CommandException) (ar.exception)).getCommandError();
1326 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1327 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1329 callback.accept(
1330 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001331 } else {
1332 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1333 }
1334 } else {
1335 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1336 }
1337 } else {
1338 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1339 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001340 }
Shuo Qian4a594052020-01-23 11:59:30 -08001341 break;
Hall Liu27d24262020-09-18 19:04:59 -07001342 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001343 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1344 ar = (AsyncResult) msg.obj;
1345 request = (MainThreadRequest) ar.userObj;
1346 CellNetworkScanResult cellScanResult;
1347 if (ar.exception == null && ar.result != null) {
1348 cellScanResult = new CellNetworkScanResult(
1349 CellNetworkScanResult.STATUS_SUCCESS,
1350 (List<OperatorInfo>) ar.result);
1351 } else {
1352 if (ar.result == null) {
1353 loge("getCellNetworkScanResults: Empty response");
1354 }
1355 if (ar.exception != null) {
1356 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1357 }
1358 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1359 if (ar.exception instanceof CommandException) {
1360 CommandException.Error error =
1361 ((CommandException) (ar.exception)).getCommandError();
1362 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1363 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1364 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1365 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1366 }
1367 }
1368 cellScanResult = new CellNetworkScanResult(errorCode, null);
1369 }
1370 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001371 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001372 break;
1373
1374 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1375 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001376 ManualNetworkSelectionArgument selArg =
1377 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001378 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1379 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001380 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1381 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001382 break;
1383
1384 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 if (ar.exception == null) {
1388 request.result = true;
1389 } else {
1390 request.result = false;
1391 loge("setNetworkSelectionModeManual " + ar.exception);
1392 }
1393 notifyRequester(request);
1394 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001395 break;
1396
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001397 case CMD_GET_MODEM_ACTIVITY_INFO:
1398 request = (MainThreadRequest) msg.obj;
1399 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001400 if (defaultPhone != null) {
1401 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001402 } else {
1403 ResultReceiver result = (ResultReceiver) request.argument;
1404 Bundle bundle = new Bundle();
1405 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001406 new ModemActivityInfo(0, 0, 0,
1407 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001408 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001409 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001410 break;
1411
Hall Liud0f208c2020-10-14 16:54:44 -07001412 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001413 ar = (AsyncResult) msg.obj;
1414 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001415 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001416 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001417 if (mLastModemActivityInfo == null) {
1418 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1419 mLastModemActivitySpecificInfo[0] =
1420 new ActivityStatsTechSpecificInfo(
1421 0,
1422 0,
1423 new int[ModemActivityInfo.getNumTxPowerLevels()],
1424 0);
1425 mLastModemActivityInfo =
1426 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1427 }
1428
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001429 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001430 // Update the last modem activity info and the result of the request.
1431 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1432 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001433 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001434 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001435 mLastModemActivityInfo =
1436 new ModemActivityInfo(
1437 mLastModemActivityInfo.getTimestampMillis(),
1438 mLastModemActivityInfo.getSleepTimeMillis(),
1439 mLastModemActivityInfo.getIdleTimeMillis(),
1440 mLastModemActivitySpecificInfo);
1441
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001442 } else {
1443 if (ar.result == null) {
1444 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001445 error = TelephonyManager.ModemActivityInfoException
1446 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001448 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001449 error = TelephonyManager.ModemActivityInfoException
1450 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001451 } else {
1452 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001453 error = TelephonyManager.ModemActivityInfoException
1454 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 }
1456 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001457 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001458 if (mLastModemActivityInfo != null) {
1459 bundle.putParcelable(
1460 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1461 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001462 } else {
1463 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1464 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001466 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001467 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001468 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001469
Meng Wang1a7c35a2016-05-05 20:56:15 -07001470 case CMD_SET_ALLOWED_CARRIERS:
1471 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001472 CarrierRestrictionRules argument =
1473 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001474 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001475 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001476 break;
1477
1478 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1479 ar = (AsyncResult) msg.obj;
1480 request = (MainThreadRequest) ar.userObj;
1481 if (ar.exception == null && ar.result != null) {
1482 request.result = ar.result;
1483 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001484 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1485 if (ar.exception instanceof CommandException) {
1486 loge("setAllowedCarriers: CommandException: " + ar.exception);
1487 CommandException.Error error =
1488 ((CommandException) (ar.exception)).getCommandError();
1489 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1490 request.result =
1491 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1492 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001493 } else {
1494 loge("setAllowedCarriers: Unknown exception");
1495 }
1496 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001497 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001498 break;
1499
1500 case CMD_GET_ALLOWED_CARRIERS:
1501 request = (MainThreadRequest) msg.obj;
1502 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001503 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001504 break;
1505
1506 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1507 ar = (AsyncResult) msg.obj;
1508 request = (MainThreadRequest) ar.userObj;
1509 if (ar.exception == null && ar.result != null) {
1510 request.result = ar.result;
1511 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001512 request.result = new IllegalStateException(
1513 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001514 if (ar.result == null) {
1515 loge("getAllowedCarriers: Empty response");
1516 } else if (ar.exception instanceof CommandException) {
1517 loge("getAllowedCarriers: CommandException: " +
1518 ar.exception);
1519 } else {
1520 loge("getAllowedCarriers: Unknown exception");
1521 }
1522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001523 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001524 break;
1525
Nathan Haroldb3014052017-01-25 15:57:32 -08001526 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1527 ar = (AsyncResult) msg.obj;
1528 request = (MainThreadRequest) ar.userObj;
1529 if (ar.exception == null && ar.result != null) {
1530 request.result = ar.result;
1531 } else {
1532 request.result = new IllegalArgumentException(
1533 "Failed to retrieve Forbidden Plmns");
1534 if (ar.result == null) {
1535 loge("getForbiddenPlmns: Empty response");
1536 } else {
1537 loge("getForbiddenPlmns: Unknown exception");
1538 }
1539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001540 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001541 break;
1542
1543 case CMD_GET_FORBIDDEN_PLMNS:
1544 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001545 uiccPort = getUiccPortFromRequest(request);
1546 if (uiccPort == null) {
1547 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001548 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001549 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001550 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001551 break;
1552 }
1553 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001554 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001555 if (uiccApp == null) {
1556 loge("getForbiddenPlmns() no app with specified type -- "
1557 + appType);
1558 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001559 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001560 break;
1561 } else {
1562 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1563 + " specified type -- " + appType);
1564 }
1565 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1566 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1567 onCompleted);
1568 break;
1569
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001570 case CMD_SWITCH_SLOTS:
1571 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001572 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001573 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001574 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001575 break;
1576
1577 case EVENT_SWITCH_SLOTS_DONE:
1578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
1580 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001581 notifyRequester(request);
1582 break;
1583 case CMD_GET_NETWORK_SELECTION_MODE:
1584 request = (MainThreadRequest) msg.obj;
1585 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1586 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1587 break;
1588
1589 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1590 ar = (AsyncResult) msg.obj;
1591 request = (MainThreadRequest) ar.userObj;
1592 if (ar.exception != null) {
1593 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1594 } else {
1595 int mode = ((int[]) ar.result)[0];
1596 if (mode == 0) {
1597 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1598 } else {
1599 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1600 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001601 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001602 notifyRequester(request);
1603 break;
1604 case CMD_GET_CDMA_ROAMING_MODE:
1605 request = (MainThreadRequest) msg.obj;
1606 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1607 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1608 break;
1609 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1610 ar = (AsyncResult) msg.obj;
1611 request = (MainThreadRequest) ar.userObj;
1612 if (ar.exception != null) {
1613 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1614 } else {
1615 request.result = ((int[]) ar.result)[0];
1616 }
1617 notifyRequester(request);
1618 break;
1619 case CMD_SET_CDMA_ROAMING_MODE:
1620 request = (MainThreadRequest) msg.obj;
1621 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1622 int mode = (int) request.argument;
1623 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1624 break;
1625 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1626 ar = (AsyncResult) msg.obj;
1627 request = (MainThreadRequest) ar.userObj;
1628 request.result = ar.exception == null;
1629 notifyRequester(request);
1630 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001631 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1632 request = (MainThreadRequest) msg.obj;
1633 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1634 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1635 break;
1636 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1637 ar = (AsyncResult) msg.obj;
1638 request = (MainThreadRequest) ar.userObj;
1639 if (ar.exception != null) {
1640 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1641 } else {
1642 request.result = ((int[]) ar.result)[0];
1643 }
1644 notifyRequester(request);
1645 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001646 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1647 request = (MainThreadRequest) msg.obj;
1648 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1649 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001650 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1651 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001652 break;
1653 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1654 ar = (AsyncResult) msg.obj;
1655 request = (MainThreadRequest) ar.userObj;
1656 request.result = ar.exception == null;
1657 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001658 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001659 case CMD_GET_ALL_CELL_INFO:
1660 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001661 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001662 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001663 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001664 case EVENT_GET_ALL_CELL_INFO_DONE:
1665 ar = (AsyncResult) msg.obj;
1666 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001667 // If a timeout occurs, the response will be null
1668 request.result = (ar.exception == null && ar.result != null)
1669 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001670 synchronized (request) {
1671 request.notifyAll();
1672 }
1673 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001674 case CMD_REQUEST_CELL_INFO_UPDATE:
1675 request = (MainThreadRequest) msg.obj;
1676 request.phone.requestCellInfoUpdate(request.workSource,
1677 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1678 break;
1679 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1680 ar = (AsyncResult) msg.obj;
1681 request = (MainThreadRequest) ar.userObj;
1682 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1683 try {
1684 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001685 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001686 cb.onError(
1687 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1688 ar.exception.getClass().getName(),
1689 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001690 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001691 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001692 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001693 } else {
1694 // use the result as returned
1695 cb.onCellInfo((List<CellInfo>) ar.result);
1696 }
1697 } catch (RemoteException re) {
1698 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1699 }
1700 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001701 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001702 request = (MainThreadRequest) msg.obj;
1703 WorkSource ws = (WorkSource) request.argument;
1704 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001705 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001706 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001707 }
1708 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001709 ar = (AsyncResult) msg.obj;
1710 request = (MainThreadRequest) ar.userObj;
1711 if (ar.exception == null) {
1712 request.result = ar.result;
1713 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001714 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001715 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001716 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001717 }
1718
1719 synchronized (request) {
1720 request.notifyAll();
1721 }
1722 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001723 }
chen xu6dac5ab2018-10-26 17:39:23 -07001724 case CMD_MODEM_REBOOT:
1725 request = (MainThreadRequest) msg.obj;
1726 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001727 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001728 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001729 case EVENT_CMD_MODEM_REBOOT_DONE:
1730 handleNullReturnEvent(msg, "rebootModem");
1731 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001732 case CMD_REQUEST_ENABLE_MODEM:
1733 request = (MainThreadRequest) msg.obj;
1734 boolean enable = (boolean) request.argument;
1735 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001736 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001737 PhoneConfigurationManager.getInstance()
1738 .enablePhone(request.phone, enable, onCompleted);
1739 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001740 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001741 ar = (AsyncResult) msg.obj;
1742 request = (MainThreadRequest) ar.userObj;
1743 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001744 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001745 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001746 if ((boolean) request.result) {
1747 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1748 updateModemStateMetrics();
1749 } else {
1750 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1751 + ar.exception);
1752 }
1753 notifyRequester(request);
1754 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001755 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001756 case CMD_GET_MODEM_STATUS:
1757 request = (MainThreadRequest) msg.obj;
1758 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1759 PhoneConfigurationManager.getInstance()
1760 .getPhoneStatusFromModem(request.phone, onCompleted);
1761 break;
1762 case EVENT_GET_MODEM_STATUS_DONE:
1763 ar = (AsyncResult) msg.obj;
1764 request = (MainThreadRequest) ar.userObj;
1765 int id = request.phone.getPhoneId();
1766 if (ar.exception == null && ar.result != null) {
1767 request.result = ar.result;
1768 //update the cache as modem status has changed
1769 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1770 (boolean) request.result);
1771 } else {
1772 // Return true if modem status cannot be retrieved. For most cases,
1773 // modem status is on. And for older version modems, GET_MODEM_STATUS
1774 // and disable modem are not supported. Modem is always on.
1775 // TODO: this should be fixed in R to support a third
1776 // status UNKNOWN b/131631629
1777 request.result = true;
1778 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1779 + ar.exception);
1780 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001781 notifyRequester(request);
1782 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001783 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1784 request = (MainThreadRequest) msg.obj;
1785 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1786 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1787 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1788 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1789 break;
1790 }
1791 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1792 ar = (AsyncResult) msg.obj;
1793 request = (MainThreadRequest) ar.userObj;
1794 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1795 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1796 args.second.accept(ar.exception == null);
1797 notifyRequester(request);
1798 break;
1799 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001800 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1801 request = (MainThreadRequest) msg.obj;
1802 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1803 Phone phone = getPhoneFromRequest(request);
1804 if (phone != null) {
1805 phone.getSystemSelectionChannels(onCompleted);
1806 } else {
1807 loge("getSystemSelectionChannels: No phone object");
1808 request.result = new ArrayList<RadioAccessSpecifier>();
1809 notifyRequester(request);
1810 }
1811 break;
1812 }
1813 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1814 ar = (AsyncResult) msg.obj;
1815 request = (MainThreadRequest) ar.userObj;
1816 if (ar.exception == null && ar.result != null) {
1817 request.result = ar.result;
1818 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001819 request.result = new IllegalStateException(
1820 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001821 if (ar.result == null) {
1822 loge("getSystemSelectionChannels: Empty response");
1823 } else {
1824 loge("getSystemSelectionChannels: Unknown exception");
1825 }
1826 }
1827 notifyRequester(request);
1828 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001829 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1830 ar = (AsyncResult) msg.obj;
1831 request = (MainThreadRequest) ar.userObj;
1832 if (ar.exception == null && ar.result != null) {
1833 request.result = ar.result;
1834 } else {
1835 request.result = -1;
1836 loge("Failed to set Forbidden Plmns");
1837 if (ar.result == null) {
1838 loge("setForbidenPlmns: Empty response");
1839 } else if (ar.exception != null) {
1840 loge("setForbiddenPlmns: Exception: " + ar.exception);
1841 request.result = -1;
1842 } else {
1843 loge("setForbiddenPlmns: Unknown exception");
1844 }
1845 }
1846 notifyRequester(request);
1847 break;
1848 case CMD_SET_FORBIDDEN_PLMNS:
1849 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001850 uiccPort = getUiccPortFromRequest(request);
1851 if (uiccPort == null) {
1852 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001853 request.result = -1;
1854 notifyRequester(request);
1855 break;
1856 }
1857 Pair<Integer, List<String>> setFplmnsArgs =
1858 (Pair<Integer, List<String>>) request.argument;
1859 appType = setFplmnsArgs.first;
1860 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001861 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001862 if (uiccApp == null) {
1863 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1864 request.result = -1;
1865 loge("Failed to get UICC App");
1866 notifyRequester(request);
1867 } else {
1868 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1869 ((SIMRecords) uiccApp.getIccRecords())
1870 .setForbiddenPlmns(onCompleted, fplmns);
1871 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001872 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001873 case CMD_ERASE_MODEM_CONFIG:
1874 request = (MainThreadRequest) msg.obj;
1875 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1876 defaultPhone.eraseModemConfig(onCompleted);
1877 break;
1878 case EVENT_ERASE_MODEM_CONFIG_DONE:
1879 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001880 break;
zoey chene02881a2019-12-30 16:11:23 +08001881
Kai Shif70f46f2021-03-03 13:59:46 -08001882 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1883 request = (MainThreadRequest) msg.obj;
1884 request.result = defaultPhone.eraseDataInSharedPreferences();
1885 notifyRequester(request);
1886 break;
1887
zoey chene02881a2019-12-30 16:11:23 +08001888 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1889 request = (MainThreadRequest) msg.obj;
1890 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1891 Pair<String, String> changed = (Pair<String, String>) request.argument;
1892 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1893 changed.first, changed.second, onCompleted);
1894 break;
1895 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1896 ar = (AsyncResult) msg.obj;
1897 request = (MainThreadRequest) ar.userObj;
1898 if (ar.exception == null) {
1899 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001900 // If the operation is successful, update the PIN storage
1901 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1902 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001903 UiccController.getInstance().getPinStorage()
1904 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001905 } else {
1906 request.result = msg.arg1;
1907 }
1908 notifyRequester(request);
1909 break;
1910
Michele Berionne5e411512020-11-13 02:36:59 +00001911 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001912 request = (MainThreadRequest) msg.obj;
1913 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1914 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1915 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1916 enabled.first, enabled.second, onCompleted);
1917 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001918 }
zoey chene02881a2019-12-30 16:11:23 +08001919 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1920 ar = (AsyncResult) msg.obj;
1921 request = (MainThreadRequest) ar.userObj;
1922 if (ar.exception == null) {
1923 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001924 // If the operation is successful, update the PIN storage
1925 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1926 int phoneId = getPhoneFromRequest(request).getPhoneId();
1927 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001928 UiccController.getInstance().getPinStorage()
1929 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001930 } else {
1931 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1932 }
zoey chene02881a2019-12-30 16:11:23 +08001933 } else {
1934 request.result = msg.arg1;
1935 }
Michele Berionne5e411512020-11-13 02:36:59 +00001936
1937
zoey chene02881a2019-12-30 16:11:23 +08001938 notifyRequester(request);
1939 break;
1940
Peter Wangdafb9ac2020-01-15 14:13:38 -08001941 case MSG_NOTIFY_USER_ACTIVITY:
1942 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001943 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001944 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1945 getDefaultPhone().getContext().sendBroadcastAsUser(
1946 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1947 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001948
1949 case CMD_SET_DATA_THROTTLING: {
1950 request = (MainThreadRequest) msg.obj;
1951 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1952 DataThrottlingRequest dataThrottlingRequest =
1953 (DataThrottlingRequest) request.argument;
1954 Phone phone = getPhoneFromRequest(request);
1955 if (phone != null) {
1956 phone.setDataThrottling(onCompleted,
1957 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1958 dataThrottlingRequest.getCompletionDurationMillis());
1959 } else {
1960 loge("setDataThrottling: No phone object");
1961 request.result =
1962 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1963 notifyRequester(request);
1964 }
1965
1966 break;
1967 }
1968 case EVENT_SET_DATA_THROTTLING_DONE:
1969 ar = (AsyncResult) msg.obj;
1970 request = (MainThreadRequest) ar.userObj;
1971
1972 if (ar.exception == null) {
1973 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1974 } else if (ar.exception instanceof CommandException) {
1975 loge("setDataThrottling: CommandException: " + ar.exception);
1976 CommandException.Error error =
1977 ((CommandException) (ar.exception)).getCommandError();
1978
1979 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1980 request.result = TelephonyManager
1981 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1982 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1983 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001984 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1985 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001986 } else {
1987 request.result =
1988 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1989 }
1990 } else {
1991 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1992 }
1993 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1994 notifyRequester(request);
1995 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001996
1997 case CMD_SET_SIM_POWER: {
1998 request = (MainThreadRequest) msg.obj;
1999 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2000 request = (MainThreadRequest) msg.obj;
2001 int stateToSet =
2002 ((Pair<Integer, IIntegerConsumer>)
2003 request.argument).first;
2004 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2005 break;
2006 }
2007 case EVENT_SET_SIM_POWER_DONE: {
2008 ar = (AsyncResult) msg.obj;
2009 request = (MainThreadRequest) ar.userObj;
2010 IIntegerConsumer callback =
2011 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2012 if (ar.exception != null) {
2013 loge("setSimPower exception: " + ar.exception);
2014 int errorCode = TelephonyManager.CallForwardingInfoCallback
2015 .RESULT_ERROR_UNKNOWN;
2016 if (ar.exception instanceof CommandException) {
2017 CommandException.Error error =
2018 ((CommandException) (ar.exception)).getCommandError();
2019 if (error == CommandException.Error.SIM_ERR) {
2020 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2021 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2022 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2023 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2024 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2025 } else {
2026 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2027 }
2028 }
2029 try {
2030 callback.accept(errorCode);
2031 } catch (RemoteException e) {
2032 // Ignore if the remote process is no longer available to call back.
2033 Log.w(LOG_TAG, "setSimPower: callback not available.");
2034 }
2035 } else {
2036 try {
2037 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2038 } catch (RemoteException e) {
2039 // Ignore if the remote process is no longer available to call back.
2040 Log.w(LOG_TAG, "setSimPower: callback not available.");
2041 }
2042 }
2043 break;
2044 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002045 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2046 request = (MainThreadRequest) msg.obj;
2047
2048 final Phone phone = getPhoneFromRequest(request);
2049 if (phone == null || phone.getServiceStateTracker() == null) {
2050 request.result = new IllegalStateException("Phone or SST is null");
2051 notifyRequester(request);
2052 break;
2053 }
2054
2055 Pair<Integer, SignalStrengthUpdateRequest> pair =
2056 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2057 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2058 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002059 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002060 request.subId, pair.first /*callingUid*/,
2061 pair.second /*request*/, onCompleted);
2062 break;
2063 }
2064 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2065 ar = (AsyncResult) msg.obj;
2066 request = (MainThreadRequest) ar.userObj;
2067 // request.result will be the exception of ar if present, true otherwise.
2068 // Be cautious not to leave result null which will wait() forever
2069 request.result = ar.exception != null ? ar.exception : true;
2070 notifyRequester(request);
2071 break;
2072 }
2073 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2074 request = (MainThreadRequest) msg.obj;
2075
2076 Phone phone = getPhoneFromRequest(request);
2077 if (phone == null || phone.getServiceStateTracker() == null) {
2078 request.result = new IllegalStateException("Phone or SST is null");
2079 notifyRequester(request);
2080 break;
2081 }
2082
2083 Pair<Integer, SignalStrengthUpdateRequest> pair =
2084 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2085 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2086 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002087 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002088 request.subId, pair.first /*callingUid*/,
2089 pair.second /*request*/, onCompleted);
2090 break;
2091 }
2092 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2093 ar = (AsyncResult) msg.obj;
2094 request = (MainThreadRequest) ar.userObj;
2095 request.result = ar.exception != null ? ar.exception : true;
2096 notifyRequester(request);
2097 break;
2098 }
Jordan Liu109698e2020-11-24 14:50:34 -08002099
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002100 case CMD_GET_SLICING_CONFIG: {
2101 request = (MainThreadRequest) msg.obj;
2102 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2103 request.phone.getSlicingConfig(onCompleted);
2104 break;
2105 }
2106 case EVENT_GET_SLICING_CONFIG_DONE: {
2107 ar = (AsyncResult) msg.obj;
2108 request = (MainThreadRequest) ar.userObj;
2109 ResultReceiver result = (ResultReceiver) request.argument;
2110
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002111 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002112 Bundle bundle = new Bundle();
2113 int resultCode = 0;
2114 if (ar.exception != null) {
2115 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2116 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002117 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002118 } else if (ar.result == null) {
2119 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002120 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002121 } else {
2122 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002123 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2124 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002125 }
2126
2127 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002128 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002129 }
2130 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2131 result.send(resultCode, bundle);
2132 notifyRequester(request);
2133 break;
2134 }
2135
Michele Berionne5e411512020-11-13 02:36:59 +00002136 case CMD_PREPARE_UNATTENDED_REBOOT:
2137 request = (MainThreadRequest) msg.obj;
2138 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002139 UiccController.getInstance().getPinStorage()
2140 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002141 notifyRequester(request);
2142 break;
2143
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 default:
2145 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2146 break;
2147 }
2148 }
Jake Hambye994d462014-02-03 13:10:13 -08002149
Pengquan Menga1bb6272018-09-06 09:59:22 -07002150 private void notifyRequester(MainThreadRequest request) {
2151 synchronized (request) {
2152 request.notifyAll();
2153 }
2154 }
2155
Jake Hambye994d462014-02-03 13:10:13 -08002156 private void handleNullReturnEvent(Message msg, String command) {
2157 AsyncResult ar = (AsyncResult) msg.obj;
2158 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2159 if (ar.exception == null) {
2160 request.result = true;
2161 } else {
2162 request.result = false;
2163 if (ar.exception instanceof CommandException) {
2164 loge(command + ": CommandException: " + ar.exception);
2165 } else {
2166 loge(command + ": Unknown exception");
2167 }
2168 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002169 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 }
2172
2173 /**
2174 * Posts the specified command to be executed on the main thread,
2175 * waits for the request to complete, and returns the result.
2176 * @see #sendRequestAsync
2177 */
2178 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002179 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2180 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002181 }
2182
2183 /**
2184 * Posts the specified command to be executed on the main thread,
2185 * waits for the request to complete, and returns the result.
2186 * @see #sendRequestAsync
2187 */
2188 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2189 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002190 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002191 }
2192
2193 /**
2194 * Posts the specified command to be executed on the main thread,
2195 * waits for the request to complete, and returns the result.
2196 * @see #sendRequestAsync
2197 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002198 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002199 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2200 }
2201
2202 /**
2203 * Posts the specified command to be executed on the main thread,
2204 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2205 * if not timeout or null otherwise.
2206 * @see #sendRequestAsync
2207 */
2208 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2209 long timeoutInMs) {
2210 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002211 }
2212
2213 /**
2214 * Posts the specified command to be executed on the main thread,
2215 * waits for the request to complete, and returns the result.
2216 * @see #sendRequestAsync
2217 */
Nathan Harold92bed182018-10-12 18:16:49 -07002218 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002219 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002220 }
2221
2222 /**
2223 * Posts the specified command to be executed on the main thread,
2224 * waits for the request to complete, and returns the result.
2225 * @see #sendRequestAsync
2226 */
2227 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002228 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2229 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002230 }
2231
2232 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002233 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2234 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2235 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002236 * @see #sendRequestAsync
2237 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002238 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2239 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2241 throw new RuntimeException("This method will deadlock if called from the main thread.");
2242 }
2243
Nathan Harold92bed182018-10-12 18:16:49 -07002244 MainThreadRequest request = null;
2245 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2246 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2247 } else if (phone != null) {
2248 request = new MainThreadRequest(argument, phone, workSource);
2249 } else {
2250 request = new MainThreadRequest(argument, subId, workSource);
2251 }
2252
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 Message msg = mMainThreadHandler.obtainMessage(command, request);
2254 msg.sendToTarget();
2255
Rambo Wang0f050d82021-02-12 11:43:36 -08002256
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002258 if (timeoutInMs >= 0) {
2259 // Wait for at least timeoutInMs before returning null request result
2260 long now = SystemClock.elapsedRealtime();
2261 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002262 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002263 try {
2264 request.wait(deadline - now);
2265 } catch (InterruptedException e) {
2266 // Do nothing, go back and check if request is completed or timeout
2267 } finally {
2268 now = SystemClock.elapsedRealtime();
2269 }
2270 }
2271 } else {
2272 // Wait for the request to complete
2273 while (request.result == null) {
2274 try {
2275 request.wait();
2276 } catch (InterruptedException e) {
2277 // Do nothing, go back and wait until the request is complete
2278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280 }
2281 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002282 if (request.result == null) {
2283 Log.wtf(LOG_TAG,
2284 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 return request.result;
2287 }
2288
2289 /**
2290 * Asynchronous ("fire and forget") version of sendRequest():
2291 * Posts the specified command to be executed on the main thread, and
2292 * returns immediately.
2293 * @see #sendRequest
2294 */
2295 private void sendRequestAsync(int command) {
2296 mMainThreadHandler.sendEmptyMessage(command);
2297 }
2298
2299 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002300 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002301 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002302 */
2303 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002304 sendRequestAsync(command, argument, null, null);
2305 }
2306
2307 /**
2308 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2309 * @see {@link #sendRequest(int,Object)}
2310 */
2311 private void sendRequestAsync(
2312 int command, Object argument, Phone phone, WorkSource workSource) {
2313 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002314 Message msg = mMainThreadHandler.obtainMessage(command, request);
2315 msg.sendToTarget();
2316 }
2317
2318 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 * Initialize the singleton PhoneInterfaceManager instance.
2320 * This is only done once, at startup, from PhoneApp.onCreate().
2321 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002322 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 synchronized (PhoneInterfaceManager.class) {
2324 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002325 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 } else {
2327 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2328 }
2329 return sInstance;
2330 }
2331 }
2332
2333 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002334 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002337 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002338 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002340 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002342 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002343 mTelephonySharedPreferences =
2344 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002345 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002346 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002347 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002348 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002349 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukiermand6cae882022-12-29 12:02:31 -05002350 mTelephony2gUpdater = new Telephony2gUpdater(mApp);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002351 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 publish();
2353 }
2354
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002355 private Phone getDefaultPhone() {
2356 Phone thePhone = getPhone(getDefaultSubscription());
2357 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2358 }
2359
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 private void publish() {
2361 if (DBG) log("publish: " + this);
2362
Peter Wangc035ce42020-01-08 21:00:22 -08002363 TelephonyFrameworkInitializer
2364 .getTelephonyServiceManager()
2365 .getTelephonyServiceRegisterer()
2366 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 }
2368
Stuart Scott584921c2015-01-15 17:10:34 -08002369 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002370 if (request.phone != null) {
2371 return request.phone;
2372 } else {
2373 return getPhoneFromSubId(request.subId);
2374 }
2375 }
2376
2377 private Phone getPhoneFromSubId(int subId) {
2378 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2379 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002380 }
2381
Rambo Wange53e07d2022-05-10 13:01:13 -07002382 @Nullable
2383 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002384 Phone phone = getPhoneFromRequest(request);
2385 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002386 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002387 }
2388
Wink Saville36469e72014-06-11 15:17:00 -07002389 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002390 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002391 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393
Kai Shif70f46f2021-03-03 13:59:46 -08002394 private void sendEraseModemConfig(@NonNull Phone phone) {
2395 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2396 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2397 }
2398
2399 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2400 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2401 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002402 }
2403
Peter Wang44b186e2020-01-13 23:33:09 -08002404 private boolean isImsAvailableOnDevice() {
2405 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2406 if (pm == null) {
2407 // For some reason package manger is not available.. This will fail internally anyway,
2408 // so do not throw error and allow.
2409 return true;
2410 }
2411 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2412 }
2413
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002415 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002416 }
2417
Wink Savilleb564aae2014-10-23 10:18:09 -07002418 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 if (DBG) log("dial: " + number);
2420 // No permission check needed here: This is just a wrapper around the
2421 // ACTION_DIAL intent, which is available to any app since it puts up
2422 // the UI before it does anything.
2423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002424 final long identity = Binder.clearCallingIdentity();
2425 try {
2426 String url = createTelUrl(number);
2427 if (url == null) {
2428 return;
2429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002431 // PENDING: should we just silently fail if phone is offhook or ringing?
2432 PhoneConstants.State state = mCM.getState(subId);
2433 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2434 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2435 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2436 mApp.startActivity(intent);
2437 }
2438 } finally {
2439 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 }
2441 }
2442
2443 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002444 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002445 }
2446
Wink Savilleb564aae2014-10-23 10:18:09 -07002447 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 if (DBG) log("call: " + number);
2449
2450 // This is just a wrapper around the ACTION_CALL intent, but we still
2451 // need to do a permission check since we're calling startActivity()
2452 // from the context of the phone app.
2453 enforceCallPermission();
2454
Jordan Liu1617b712019-07-10 15:06:26 -07002455 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 != AppOpsManager.MODE_ALLOWED) {
2457 return;
2458 }
2459
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002460 final long identity = Binder.clearCallingIdentity();
2461 try {
2462 String url = createTelUrl(number);
2463 if (url == null) {
2464 return;
2465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467 boolean isValid = false;
2468 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2469 if (slist != null) {
2470 for (SubscriptionInfo subInfoRecord : slist) {
2471 if (subInfoRecord.getSubscriptionId() == subId) {
2472 isValid = true;
2473 break;
2474 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002475 }
Wink Saville08874612014-08-31 19:19:58 -07002476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477 if (!isValid) {
2478 return;
2479 }
Wink Saville08874612014-08-31 19:19:58 -07002480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2482 intent.putExtra(SUBSCRIPTION_KEY, subId);
2483 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2484 mApp.startActivity(intent);
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
2487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 }
2489
Wink Savilleb564aae2014-10-23 10:18:09 -07002490 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002491 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002492 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2493 }
2494
Wink Savilleb564aae2014-10-23 10:18:09 -07002495 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002496 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002497 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2498 }
2499
Wink Savilleb564aae2014-10-23 10:18:09 -07002500 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002502
2503 final long identity = Binder.clearCallingIdentity();
2504 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002505 Phone phone = getPhone(subId);
2506 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 checkSimPin.start();
2508 return checkSimPin.unlockSim(null, pin);
2509 } finally {
2510 Binder.restoreCallingIdentity(identity);
2511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512 }
2513
Wink Savilleb564aae2014-10-23 10:18:09 -07002514 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002516
2517 final long identity = Binder.clearCallingIdentity();
2518 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002519 Phone phone = getPhone(subId);
2520 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521 checkSimPuk.start();
2522 return checkSimPuk.unlockSim(puk, pin);
2523 } finally {
2524 Binder.restoreCallingIdentity(identity);
2525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 }
2527
2528 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002529 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002530 * a synchronous one.
2531 */
2532 private static class UnlockSim extends Thread {
2533
2534 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002535 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536
2537 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002538 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2539 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540
2541 // For replies from SimCard interface
2542 private Handler mHandler;
2543
2544 // For async handler to identify request type
2545 private static final int SUPPLY_PIN_COMPLETE = 100;
2546
Michele Berionne5e411512020-11-13 02:36:59 +00002547 UnlockSim(int phoneId, IccCard simCard) {
2548 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002549 mSimCard = simCard;
2550 }
2551
2552 @Override
2553 public void run() {
2554 Looper.prepare();
2555 synchronized (UnlockSim.this) {
2556 mHandler = new Handler() {
2557 @Override
2558 public void handleMessage(Message msg) {
2559 AsyncResult ar = (AsyncResult) msg.obj;
2560 switch (msg.what) {
2561 case SUPPLY_PIN_COMPLETE:
2562 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2563 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002564 mRetryCount = msg.arg1;
2565 if (ar.exception != null) {
2566 if (ar.exception instanceof CommandException &&
2567 ((CommandException)(ar.exception)).getCommandError()
2568 == CommandException.Error.PASSWORD_INCORRECT) {
2569 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002570 } //When UiccCardApp dispose,handle message and return exception
2571 else if (ar.exception instanceof CommandException &&
2572 ((CommandException) (ar.exception)).getCommandError()
2573 == CommandException.Error.ABORTED) {
2574 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002575 } else {
2576 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2577 }
2578 } else {
2579 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 mDone = true;
2582 UnlockSim.this.notifyAll();
2583 }
2584 break;
2585 }
2586 }
2587 };
2588 UnlockSim.this.notifyAll();
2589 }
2590 Looper.loop();
2591 }
2592
2593 /*
2594 * Use PIN or PUK to unlock SIM card
2595 *
2596 * If PUK is null, unlock SIM card with PIN
2597 *
2598 * If PUK is not null, unlock SIM card with PUK and set PIN code
2599 */
Wink Saville9de0f752013-10-22 19:04:03 -07002600 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601
2602 while (mHandler == null) {
2603 try {
2604 wait();
2605 } catch (InterruptedException e) {
2606 Thread.currentThread().interrupt();
2607 }
2608 }
2609 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2610
2611 if (puk == null) {
2612 mSimCard.supplyPin(pin, callback);
2613 } else {
2614 mSimCard.supplyPuk(puk, pin, callback);
2615 }
2616
2617 while (!mDone) {
2618 try {
2619 Log.d(LOG_TAG, "wait for done");
2620 wait();
2621 } catch (InterruptedException e) {
2622 // Restore the interrupted status
2623 Thread.currentThread().interrupt();
2624 }
2625 }
2626 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002627 int[] resultArray = new int[2];
2628 resultArray[0] = mResult;
2629 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002630
2631 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002632 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002633 }
2634
Wink Saville9de0f752013-10-22 19:04:03 -07002635 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636 }
2637 }
2638
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002639 /**
2640 * This method has been removed due to privacy and stability concerns.
2641 */
2642 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002644 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2645 return;
Wink Saville36469e72014-06-11 15:17:00 -07002646 }
2647
Nathan Harold1f889d82020-06-04 17:05:26 -07002648 @Override
2649 public void updateServiceLocationWithPackageName(String callingPackage) {
2650 mApp.getSystemService(AppOpsManager.class)
2651 .checkPackage(Binder.getCallingUid(), callingPackage);
2652
Nathan Haroldf096d982020-11-18 17:18:06 -08002653 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002654 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2655 // Callers targeting S have no business invoking this method.
2656 return;
2657 }
2658
2659 LocationAccessPolicy.LocationPermissionResult locationResult =
2660 LocationAccessPolicy.checkLocationPermission(mApp,
2661 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2662 .setCallingPackage(callingPackage)
2663 .setCallingFeatureId(null)
2664 .setCallingPid(Binder.getCallingPid())
2665 .setCallingUid(Binder.getCallingUid())
2666 .setMethod("updateServiceLocation")
2667 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2668 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2669 .build());
2670 // Apps that lack location permission have no business calling this method;
2671 // however, because no permission was declared in the public API, denials must
2672 // all be "soft".
2673 switch (locationResult) {
2674 case DENIED_HARD: /* fall through */
2675 case DENIED_SOFT:
2676 return;
2677 }
2678
2679 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680 final long identity = Binder.clearCallingIdentity();
2681 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002682 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002684 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 }
2686 } finally {
2687 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 }
2690
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002691 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002692 @Override
2693 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002694 return isRadioOnWithFeature(callingPackage, null);
2695 }
2696
2697
2698 @Override
2699 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2700 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2701 callingFeatureId);
2702 }
2703
2704 @Deprecated
2705 @Override
2706 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2707 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002708 }
2709
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002710 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002711 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2712 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002714 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002715 return false;
2716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717
2718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 return isRadioOnForSubscriber(subId);
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
2723 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002724 }
2725
2726 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 final Phone phone = getPhone(subId);
2730 if (phone != null) {
2731 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2732 } else {
2733 return false;
2734 }
2735 } finally {
2736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 }
2739
2740 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002741 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 }
Wink Saville36469e72014-06-11 15:17:00 -07002743
Wink Savilleb564aae2014-10-23 10:18:09 -07002744 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746
2747 final long identity = Binder.clearCallingIdentity();
2748 try {
2749 final Phone phone = getPhone(subId);
2750 if (phone != null) {
2751 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2752 }
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002755 }
Wink Saville36469e72014-06-11 15:17:00 -07002756 }
2757
2758 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002759 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002760 }
2761
Wink Savilleb564aae2014-10-23 10:18:09 -07002762 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 final Phone phone = getPhone(subId);
2768 if (phone == null) {
2769 return false;
2770 }
2771 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2772 toggleRadioOnOffForSubscriber(subId);
2773 }
2774 return true;
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
Wink Saville36469e72014-06-11 15:17:00 -07002779
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002780 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002781 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002782 /*
2783 * If any of the Radios are available, it will need to be
2784 * shutdown. So return true if any Radio is available.
2785 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2789 Phone phone = PhoneFactory.getPhone(i);
2790 if (phone != null && phone.isRadioAvailable()) return true;
2791 }
2792 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2793 return false;
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002796 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002797 }
2798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002800 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801 enforceModifyPermission();
2802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2806 logv("Shutting down Phone " + i);
2807 shutdownRadioUsingPhoneId(i);
2808 }
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002811 }
2812 }
2813
2814 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002815 Phone phone = PhoneFactory.getPhone(phoneId);
2816 if (phone != null && phone.isRadioAvailable()) {
2817 phone.shutdownRadio();
2818 }
2819 }
2820
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002822 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823
2824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2827 if (defaultPhone != null) {
2828 defaultPhone.setRadioPower(turnOn);
2829 return true;
2830 } else {
2831 loge("There's no default phone.");
2832 return false;
2833 }
2834 } finally {
2835 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002836 }
Wink Saville36469e72014-06-11 15:17:00 -07002837 }
2838
Wink Savilleb564aae2014-10-23 10:18:09 -07002839 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002841
2842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 final Phone phone = getPhone(subId);
2845 if (phone != null) {
2846 phone.setRadioPower(turnOn);
2847 return true;
2848 } else {
2849 return false;
2850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854 }
2855
Wink Saville36469e72014-06-11 15:17:00 -07002856 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002857 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002858 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860
2861 final long identity = Binder.clearCallingIdentity();
2862 try {
2863 int subId = mSubscriptionController.getDefaultDataSubId();
2864 final Phone phone = getPhone(subId);
2865 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002866 phone.getDataSettingsManager().setDataEnabled(
2867 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 return true;
2869 } else {
2870 return false;
2871 }
2872 } finally {
2873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875 }
2876
Wink Saville36469e72014-06-11 15:17:00 -07002877 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002878 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002879 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 int subId = mSubscriptionController.getDefaultDataSubId();
2885 final Phone phone = getPhone(subId);
2886 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002887 phone.getDataSettingsManager().setDataEnabled(
2888 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889 return true;
2890 } else {
2891 return false;
2892 }
2893 } finally {
2894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 }
2897
Sanket Padawe356d7632015-06-22 14:03:32 -07002898 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002899 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 final Phone phone = getPhone(subId);
2903 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002904 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 } else {
2906 return false;
2907 }
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002911 }
2912
2913 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002914 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002915 }
2916
pkanwarae03a6b2016-11-06 20:37:09 -08002917 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918 enforceCallPermission();
2919
2920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2923 return;
2924 }
2925 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2926 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2927 } finally {
2928 Binder.restoreCallingIdentity(identity);
2929 }
pkanwar32d516d2016-10-14 19:37:38 -07002930 };
2931
Wink Savilleb564aae2014-10-23 10:18:09 -07002932 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934
2935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2938 return false;
2939 }
2940 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002943 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002944 }
2945
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002946 /**
2947 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2948 * tag on getCallState Binder call.
2949 */
2950 @Deprecated
2951 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002952 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002953 if (CompatChanges.isChangeEnabled(
2954 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2955 Binder.getCallingUid())) {
2956 // Do not allow this API to be called on API version 31+, it should only be
2957 // called on old apps using this Binder call directly.
2958 throw new SecurityException("This method can only be used for applications "
2959 + "targeting API version 30 or less.");
2960 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002961 final long identity = Binder.clearCallingIdentity();
2962 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002963 Phone phone = getPhone(getDefaultSubscription());
2964 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2965 PhoneConstantConversions.convertCallState(phone.getState());
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 }
2970
2971 @Override
2972 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2973 if (CompatChanges.isChangeEnabled(
2974 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2975 Binder.getCallingUid())) {
2976 // Check READ_PHONE_STATE for API version 31+
2977 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2978 featureId, "getCallStateForSubscription")) {
2979 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2980 + "targeting API level 31+.");
2981 }
2982 }
2983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2987 PhoneConstantConversions.convertCallState(phone.getState());
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 }
2992
Sanket Padawe356d7632015-06-22 14:03:32 -07002993 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002994 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002995 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2996 }
2997
2998 @Override
2999 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 final long identity = Binder.clearCallingIdentity();
3001 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003002 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07003004 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 } else {
3006 return PhoneConstantConversions.convertDataState(
3007 PhoneConstants.DataState.DISCONNECTED);
3008 }
3009 } finally {
3010 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003011 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003012 }
3013
Sanket Padawe356d7632015-06-22 14:03:32 -07003014 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003015 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003016 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3017 }
3018
3019 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003020 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 final long identity = Binder.clearCallingIdentity();
3022 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003023 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003025 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 } else {
3027 return TelephonyManager.DATA_ACTIVITY_NONE;
3028 }
3029 } finally {
3030 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003031 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003032 }
3033
3034 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003035 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003037 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003038
3039 LocationAccessPolicy.LocationPermissionResult locationResult =
3040 LocationAccessPolicy.checkLocationPermission(mApp,
3041 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3042 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003043 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003044 .setCallingPid(Binder.getCallingPid())
3045 .setCallingUid(Binder.getCallingUid())
3046 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003047 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003048 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3049 .build());
3050 switch (locationResult) {
3051 case DENIED_HARD:
3052 throw new SecurityException("Not allowed to access cell location");
3053 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003054 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3055 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003056 }
3057
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003058 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003062 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003063 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064 } finally {
3065 Binder.restoreCallingIdentity(identity);
3066 }
Svetoslav64fad262015-04-14 14:35:21 -07003067 }
3068
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003069 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003070 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003071 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3072 // registered cell info, so return a NULL country instead.
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003075 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3076 // Get default phone in this case.
3077 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3078 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003079 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003081 if (phone == null) return "";
3082 ServiceStateTracker sst = phone.getServiceStateTracker();
3083 if (sst == null) return "";
3084 LocaleTracker lt = sst.getLocaleTracker();
3085 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003086 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003090 }
3091
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003092 /**
3093 * This method was removed due to potential issues caused by performing partial
3094 * updates of service state, and lack of a credible use case.
3095 *
3096 * This has the ability to break the telephony implementation by disabling notification of
3097 * changes in device connectivity. DO NOT USE THIS!
3098 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003099 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003100 public void enableLocationUpdates() {
3101 mApp.enforceCallingOrSelfPermission(
3102 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003103 }
3104
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003105 /**
3106 * This method was removed due to potential issues caused by performing partial
3107 * updates of service state, and lack of a credible use case.
3108 *
3109 * This has the ability to break the telephony implementation by disabling notification of
3110 * changes in device connectivity. DO NOT USE THIS!
3111 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003112 @Override
3113 public void disableLocationUpdates() {
3114 mApp.enforceCallingOrSelfPermission(
3115 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 }
3117
3118 @Override
3119 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003120 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3121 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003122 try {
3123 mApp.getSystemService(AppOpsManager.class)
3124 .checkPackage(Binder.getCallingUid(), callingPackage);
3125 } catch (SecurityException e) {
3126 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3127 throw e;
3128 }
3129
Nathan Haroldf096d982020-11-18 17:18:06 -08003130 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003131 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3132 throw new SecurityException(
3133 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3134 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003135
Jordan Liu1617b712019-07-10 15:06:26 -07003136 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003137 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3138 return null;
3139 }
Svetoslav64fad262015-04-14 14:35:21 -07003140
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003141 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003143 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003144 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003145
Nathan Haroldf180aac2018-06-01 18:43:55 -07003146 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3147 for (CellInfo ci : info) {
3148 if (ci instanceof CellInfoGsm) {
3149 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3150 } else if (ci instanceof CellInfoWcdma) {
3151 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003154 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003155 }
3156
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003157 private List<CellInfo> getCachedCellInfo() {
3158 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3159 for (Phone phone : PhoneFactory.getPhones()) {
3160 List<CellInfo> info = phone.getAllCellInfo();
3161 if (info != null) cellInfos.addAll(info);
3162 }
3163 return cellInfos;
3164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165
3166 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003167 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003168 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003169 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003170
3171 LocationAccessPolicy.LocationPermissionResult locationResult =
3172 LocationAccessPolicy.checkLocationPermission(mApp,
3173 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3174 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003175 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003176 .setCallingPid(Binder.getCallingPid())
3177 .setCallingUid(Binder.getCallingUid())
3178 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003179 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003180 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3181 .build());
3182 switch (locationResult) {
3183 case DENIED_HARD:
3184 throw new SecurityException("Not allowed to access cell info");
3185 case DENIED_SOFT:
3186 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003187 }
3188
Nathan Haroldf096d982020-11-18 17:18:06 -08003189 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003190 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3191 return getCachedCellInfo();
3192 }
3193
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003194 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003195 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3199 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003200 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003201 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 if (info != null) cellInfos.addAll(info);
3203 }
3204 return cellInfos;
3205 } finally {
3206 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 }
3208 }
3209
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003210 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003211 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3212 String callingFeatureId) {
3213 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3214 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003215 }
3216
3217 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003218 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3219 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003220 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003221 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003222 }
3223
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003224 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3225 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003226 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003227 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003228
3229 LocationAccessPolicy.LocationPermissionResult locationResult =
3230 LocationAccessPolicy.checkLocationPermission(mApp,
3231 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3232 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003233 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003234 .setCallingPid(Binder.getCallingPid())
3235 .setCallingUid(Binder.getCallingUid())
3236 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003237 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3238 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003239 .build());
3240 switch (locationResult) {
3241 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003242 if (TelephonyPermissions
3243 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003244 // Safetynet logging for b/154934934
3245 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3246 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003247 throw new SecurityException("Not allowed to access cell info");
3248 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003249 if (TelephonyPermissions
3250 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003251 // Safetynet logging for b/154934934
3252 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3253 }
Nathan Harold5320c422019-05-09 10:26:08 -07003254 try {
3255 cb.onCellInfo(new ArrayList<CellInfo>());
3256 } catch (RemoteException re) {
3257 // Drop without consequences
3258 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003259 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003260 }
3261
Nathan Harolda939a962019-05-09 10:13:47 -07003262
3263 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003264 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3265
3266 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3267 }
3268
3269 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003270 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003271 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003272 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273
3274 final long identity = Binder.clearCallingIdentity();
3275 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003276 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277 } finally {
3278 Binder.restoreCallingIdentity(identity);
3279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 }
3281
Shishir Agrawala9f32182016-04-12 12:00:16 -07003282 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003283 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003284 Phone phone = PhoneFactory.getPhone(slotIndex);
3285 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003286 return null;
3287 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003288 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003289 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003290 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003291 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003292 return null;
3293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294
3295 final long identity = Binder.clearCallingIdentity();
3296 try {
3297 return phone.getImei();
3298 } finally {
3299 Binder.restoreCallingIdentity(identity);
3300 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003301 }
3302
3303 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003304 public String getTypeAllocationCodeForSlot(int slotIndex) {
3305 Phone phone = PhoneFactory.getPhone(slotIndex);
3306 String tac = null;
3307 if (phone != null) {
3308 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003309 try {
3310 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3311 } catch (IndexOutOfBoundsException e) {
3312 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3313 return null;
3314 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003315 }
3316 return tac;
3317 }
3318
3319 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003320 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003321 try {
3322 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3323 } catch (SecurityException se) {
3324 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3325 throw new SecurityException("Package " + callingPackage + " does not belong to "
3326 + Binder.getCallingUid());
3327 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003328 Phone phone = PhoneFactory.getPhone(slotIndex);
3329 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003330 return null;
3331 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003332
Jeff Davidson913390f2018-02-23 17:11:49 -08003333 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003334 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003335 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003336 return null;
3337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338
3339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 return phone.getMeid();
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
3344 }
Jack Yu2af8d712017-03-15 17:14:14 -07003345 }
3346
3347 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003348 public String getManufacturerCodeForSlot(int slotIndex) {
3349 Phone phone = PhoneFactory.getPhone(slotIndex);
3350 String manufacturerCode = null;
3351 if (phone != null) {
3352 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003353 try {
3354 manufacturerCode =
3355 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3356 } catch (IndexOutOfBoundsException e) {
3357 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3358 return null;
3359 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003360 }
3361 return manufacturerCode;
3362 }
3363
3364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003365 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3366 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003367 Phone phone = PhoneFactory.getPhone(slotIndex);
3368 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003369 return null;
3370 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003371 int subId = phone.getSubId();
3372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003373 mApp, subId, callingPackage, callingFeatureId,
3374 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003375 return null;
3376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003377
3378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 return phone.getDeviceSvn();
3381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003384 }
3385
fionaxu43304da2017-11-27 22:51:16 -08003386 @Override
3387 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003388 final long identity = Binder.clearCallingIdentity();
3389 try {
3390 final Phone phone = getPhone(subId);
3391 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3392 } finally {
3393 Binder.restoreCallingIdentity(identity);
3394 }
fionaxu43304da2017-11-27 22:51:16 -08003395 }
3396
3397 @Override
3398 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399 final long identity = Binder.clearCallingIdentity();
3400 try {
3401 final Phone phone = getPhone(subId);
3402 return phone == null ? null : phone.getCarrierName();
3403 } finally {
3404 Binder.restoreCallingIdentity(identity);
3405 }
fionaxu43304da2017-11-27 22:51:16 -08003406 }
3407
calvinpanffe225e2018-11-01 19:43:06 +08003408 @Override
chen xu0026ca62019-03-06 15:28:50 -08003409 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 final Phone phone = getPhone(subId);
3413 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003414 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003415 } finally {
3416 Binder.restoreCallingIdentity(identity);
3417 }
3418 }
3419
3420 @Override
chen xu0026ca62019-03-06 15:28:50 -08003421 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003425 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003426 } finally {
3427 Binder.restoreCallingIdentity(identity);
3428 }
3429 }
3430
chen xu651eec72018-11-11 19:03:44 -08003431 @Override
chen xu864e11c2018-12-06 22:10:03 -08003432 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3433 if (!isSubscriptionMccMnc) {
3434 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3435 }
chen xu651eec72018-11-11 19:03:44 -08003436 final Phone phone = PhoneFactory.getPhone(slotIndex);
3437 if (phone == null) {
3438 return TelephonyManager.UNKNOWN_CARRIER_ID;
3439 }
3440 final long identity = Binder.clearCallingIdentity();
3441 try {
3442 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3443 } finally {
3444 Binder.restoreCallingIdentity(identity);
3445 }
3446 }
3447
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003448 //
3449 // Internal helper methods.
3450 //
3451
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003452 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003453 * Make sure the caller is the calling package itself
3454 *
3455 * @throws SecurityException if the caller is not the calling package
3456 */
3457 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3458 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003459 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3460 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003461 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003462 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003463 } catch (PackageManager.NameNotFoundException e) {
3464 // packageUid is -1
3465 }
3466 if (packageUid != callingUid) {
3467 throw new SecurityException(message + ": Package " + callingPackage
3468 + " does not belong to " + callingUid);
3469 }
3470 }
3471
3472 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003473 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3474 *
3475 * @throws SecurityException if the caller does not have the required permission
3476 */
3477 private void enforceModifyPermission() {
3478 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3479 }
3480
Shuo Qian3b6ee772019-11-13 17:43:31 -08003481 private void enforceActiveEmergencySessionPermission() {
3482 mApp.enforceCallingOrSelfPermission(
3483 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3484 }
3485
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003486 /**
3487 * Make sure the caller has the CALL_PHONE permission.
3488 *
3489 * @throws SecurityException if the caller does not have the required permission
3490 */
3491 private void enforceCallPermission() {
3492 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3493 }
3494
paulhu5a773602019-08-23 19:17:33 +08003495 private void enforceSettingsPermission() {
3496 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003497 }
3498
Michele Berionne5e411512020-11-13 02:36:59 +00003499 private void enforceRebootPermission() {
3500 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3501 }
3502
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503 private String createTelUrl(String number) {
3504 if (TextUtils.isEmpty(number)) {
3505 return null;
3506 }
3507
Jake Hambye994d462014-02-03 13:10:13 -08003508 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003509 }
3510
Ihab Awadf9e92732013-12-05 18:02:52 -08003511 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003512 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3513 }
3514
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003515 private static void logv(String msg) {
3516 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3517 }
3518
Ihab Awadf9e92732013-12-05 18:02:52 -08003519 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003520 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3521 }
3522
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003523 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003525 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003526 }
3527
Sanket Padawe356d7632015-06-22 14:03:32 -07003528 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003529 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 final Phone phone = PhoneFactory.getPhone(slotIndex);
3533 if (phone == null) {
3534 return PhoneConstants.PHONE_TYPE_NONE;
3535 } else {
3536 return phone.getPhoneType();
3537 }
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003541 }
3542
3543 /**
3544 * Returns the CDMA ERI icon index to display
3545 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003546 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003547 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3548 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3549 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003550 }
3551
Sanket Padawe356d7632015-06-22 14:03:32 -07003552 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003553 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3554 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003556 mApp, subId, callingPackage, callingFeatureId,
3557 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003558 return -1;
3559 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003560
3561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 final Phone phone = getPhone(subId);
3564 if (phone != null) {
3565 return phone.getCdmaEriIconIndex();
3566 } else {
3567 return -1;
3568 }
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003572 }
3573
3574 /**
3575 * Returns the CDMA ERI icon mode,
3576 * 0 - ON
3577 * 1 - FLASHING
3578 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003579 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003580 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3581 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3582 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003583 }
3584
Sanket Padawe356d7632015-06-22 14:03:32 -07003585 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003586 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3587 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003589 mApp, subId, callingPackage, callingFeatureId,
3590 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003591 return -1;
3592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003593
3594 final long identity = Binder.clearCallingIdentity();
3595 try {
3596 final Phone phone = getPhone(subId);
3597 if (phone != null) {
3598 return phone.getCdmaEriIconMode();
3599 } else {
3600 return -1;
3601 }
3602 } finally {
3603 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003605 }
3606
3607 /**
3608 * Returns the CDMA ERI text,
3609 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003610 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003611 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3612 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3613 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003614 }
3615
Sanket Padawe356d7632015-06-22 14:03:32 -07003616 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003617 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3618 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003619 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003620 mApp, subId, callingPackage, callingFeatureId,
3621 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003622 return null;
3623 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003624
3625 final long identity = Binder.clearCallingIdentity();
3626 try {
3627 final Phone phone = getPhone(subId);
3628 if (phone != null) {
3629 return phone.getCdmaEriText();
3630 } else {
3631 return null;
3632 }
3633 } finally {
3634 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003636 }
3637
3638 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003639 * Returns the CDMA MDN.
3640 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003641 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003642 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3644 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645
3646 final long identity = Binder.clearCallingIdentity();
3647 try {
3648 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003649 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650 return phone.getLine1Number();
3651 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003652 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 return null;
3654 }
3655 } finally {
3656 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003657 }
3658 }
3659
3660 /**
3661 * Returns the CDMA MIN.
3662 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003663 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003664 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3666 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003667
3668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 final Phone phone = getPhone(subId);
3671 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3672 return phone.getCdmaMin();
3673 } else {
3674 return null;
3675 }
3676 } finally {
3677 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003678 }
3679 }
3680
Hall Liud892bec2018-11-30 14:51:45 -08003681 @Override
3682 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3683 INumberVerificationCallback callback, String callingPackage) {
3684 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3685 != PERMISSION_GRANTED) {
3686 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3687 }
3688 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3689
3690 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3691 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003692 throw new SecurityException("Calling package must be configured in the device config: "
3693 + "calling package: " + callingPackage
3694 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003695 }
3696
3697 if (range == null) {
3698 throw new NullPointerException("Range must be non-null");
3699 }
3700
3701 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003702 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003703
3704 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3705 }
3706
Junda Liuca05d5d2014-08-14 22:36:34 -07003707 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003708 * Returns true if CDMA provisioning needs to run.
3709 */
3710 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711 final long identity = Binder.clearCallingIdentity();
3712 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003713 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003717 }
3718
3719 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003720 * Sets the voice mail number of a given subId.
3721 */
3722 @Override
3723 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003724 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3725 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003726
3727 final long identity = Binder.clearCallingIdentity();
3728 try {
3729 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3730 new Pair<String, String>(alphaTag, number), new Integer(subId));
3731 return success;
3732 } finally {
3733 Binder.restoreCallingIdentity(identity);
3734 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003735 }
3736
Ta-wei Yen87c49842016-05-13 21:19:52 -07003737 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003738 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3739 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003740 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3741 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003742 if (!TextUtils.equals(callingPackage, systemDialer)) {
3743 throw new SecurityException("caller must be system dialer");
3744 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003745
3746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3749 if (phoneAccountHandle == null) {
3750 return null;
3751 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003752 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753 } finally {
3754 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003755 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003756 }
3757
3758 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003759 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3760 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003761 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 mApp, subId, callingPackage, callingFeatureId,
3764 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003765 return null;
3766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003767
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003768 final long identity = Binder.clearCallingIdentity();
3769 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003770 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003771 } finally {
3772 Binder.restoreCallingIdentity(identity);
3773 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003774 }
3775
3776 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003777 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3778 VisualVoicemailSmsFilterSettings settings) {
3779 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003780
3781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003784 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785 } finally {
3786 Binder.restoreCallingIdentity(identity);
3787 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003788 }
3789
3790 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003791 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3792 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793
3794 final long identity = Binder.clearCallingIdentity();
3795 try {
3796 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003797 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798 } finally {
3799 Binder.restoreCallingIdentity(identity);
3800 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003801 }
3802
3803 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003804 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3805 String callingPackage, int subId) {
3806 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003807
3808 final long identity = Binder.clearCallingIdentity();
3809 try {
3810 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003811 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812 } finally {
3813 Binder.restoreCallingIdentity(identity);
3814 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003815 }
3816
3817 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003818 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003819 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820
3821 final long identity = Binder.clearCallingIdentity();
3822 try {
3823 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003824 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825 } finally {
3826 Binder.restoreCallingIdentity(identity);
3827 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003828 }
3829
3830 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003831 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3832 String callingAttributionTag, int subId, String number, int port, String text,
3833 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003834 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003835 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003836 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003837 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003838 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3839 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003840 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003841
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003842 /**
fionaxu0152e512016-11-14 13:36:14 -08003843 * Sets the voice activation state of a given subId.
3844 */
3845 @Override
3846 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3848 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003849
3850 final long identity = Binder.clearCallingIdentity();
3851 try {
3852 final Phone phone = getPhone(subId);
3853 if (phone != null) {
3854 phone.setVoiceActivationState(activationState);
3855 } else {
3856 loge("setVoiceActivationState fails with invalid subId: " + subId);
3857 }
3858 } finally {
3859 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003860 }
3861 }
3862
3863 /**
3864 * Sets the data activation state of a given subId.
3865 */
3866 @Override
3867 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3869 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870
3871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 final Phone phone = getPhone(subId);
3874 if (phone != null) {
3875 phone.setDataActivationState(activationState);
3876 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003877 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003878 }
3879 } finally {
3880 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003881 }
3882 }
3883
3884 /**
3885 * Returns the voice activation state of a given subId.
3886 */
3887 @Override
3888 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890
fionaxu0152e512016-11-14 13:36:14 -08003891 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892 final long identity = Binder.clearCallingIdentity();
3893 try {
3894 if (phone != null) {
3895 return phone.getVoiceActivationState();
3896 } else {
3897 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3898 }
3899 } finally {
3900 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003901 }
3902 }
3903
3904 /**
3905 * Returns the data activation state of a given subId.
3906 */
3907 @Override
3908 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003909 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910
fionaxu0152e512016-11-14 13:36:14 -08003911 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 final long identity = Binder.clearCallingIdentity();
3913 try {
3914 if (phone != null) {
3915 return phone.getDataActivationState();
3916 } else {
3917 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3918 }
3919 } finally {
3920 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003921 }
3922 }
3923
3924 /**
Wink Saville36469e72014-06-11 15:17:00 -07003925 * Returns the unread count of voicemails for a subId
3926 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003927 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003928 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3929 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003931 mApp, subId, callingPackage, callingFeatureId,
3932 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003933 return 0;
3934 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 final Phone phone = getPhone(subId);
3938 if (phone != null) {
3939 return phone.getVoiceMessageCount();
3940 } else {
3941 return 0;
3942 }
3943 } finally {
3944 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003946 }
3947
3948 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003949 * returns true, if the device is in a state where both voice and data
3950 * are supported simultaneously. This can change based on location or network condition.
3951 */
3952 @Override
3953 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 final Phone phone = getPhone(subId);
3957 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3958 } finally {
3959 Binder.restoreCallingIdentity(identity);
3960 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003961 }
3962
3963 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003964 * Send the dialer code if called from the current default dialer or the caller has
3965 * carrier privilege.
3966 * @param inputCode The dialer code to send
3967 */
3968 @Override
3969 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003970 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003971 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003972 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3973 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003974 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003975 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003976 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978
3979 final long identity = Binder.clearCallingIdentity();
3980 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003981 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003982 } finally {
3983 Binder.restoreCallingIdentity(identity);
3984 }
fionaxu235cc5e2017-03-06 22:25:57 -08003985 }
3986
Pengquan Menga1bb6272018-09-06 09:59:22 -07003987 @Override
3988 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003989 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003990 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003991 mApp, subId, "getNetworkSelectionMode");
3992 final long identity = Binder.clearCallingIdentity();
3993 try {
3994 if (!isActiveSubscription(subId)) {
3995 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3996 }
3997 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3998 } finally {
3999 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004000 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004001 }
4002
Brad Ebinger35c841c2018-10-01 10:40:55 -07004003 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004004 public boolean isInEmergencySmsMode() {
4005 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4006 final long identity = Binder.clearCallingIdentity();
4007 try {
4008 for (Phone phone : PhoneFactory.getPhones()) {
4009 if (phone.isInEmergencySmsMode()) {
4010 return true;
4011 }
4012 }
4013 } finally {
4014 Binder.restoreCallingIdentity(identity);
4015 }
4016 return false;
4017 }
4018
shilu366312e2019-12-17 09:28:10 -08004019 /**
4020 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4021 * @param subId The subscription to use to check the configuration.
4022 * @param c The callback that will be used to send the result.
4023 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004024 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004025 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4026 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004027 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004028 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004029
4030 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4031 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4032 "IMS not available on device.");
4033 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 final long token = Binder.clearCallingIdentity();
4035 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004036 int slotId = getSlotIndexOrException(subId);
4037 verifyImsMmTelConfiguredOrThrow(slotId);
4038 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004039 } catch (ImsException e) {
4040 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 } finally {
4042 Binder.restoreCallingIdentity(token);
4043 }
4044 }
4045
shilu366312e2019-12-17 09:28:10 -08004046 /**
4047 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4048 * @param subId The subscription to use to check the configuration.
4049 * @param c The callback that will be used to send the result.
4050 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004051 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004052 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004053 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004054 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004055 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4056 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4057 }
Meng Wangafbc5852019-09-19 17:37:13 -07004058 final long token = Binder.clearCallingIdentity();
4059 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004060 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4061 .removeRegistrationCallbackForSubscription(c, subId);
4062 } catch (ImsException e) {
4063 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4064 + "is inactive, ignoring unregister.");
4065 // If the subscription is no longer active, just return, since the callback
4066 // will already have been removed internally.
4067 } finally {
4068 Binder.restoreCallingIdentity(token);
4069 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 }
4071
Brad Ebingera34a6c22019-10-22 17:36:18 -07004072 /**
4073 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4074 */
4075 @Override
4076 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4077 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4078 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4079 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4080 "IMS not available on device.");
4081 }
4082 final long token = Binder.clearCallingIdentity();
4083 try {
4084 Phone phone = getPhone(subId);
4085 if (phone == null) {
4086 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4087 + subId + "'");
4088 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4089 }
4090 phone.getImsRegistrationState(regState -> {
4091 try {
4092 consumer.accept((regState == null)
4093 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4094 } catch (RemoteException e) {
4095 // Ignore if the remote process is no longer available to call back.
4096 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4097 }
4098 });
4099 } finally {
4100 Binder.restoreCallingIdentity(token);
4101 }
4102 }
4103
4104 /**
4105 * Get the transport type for the IMS service registration state.
4106 */
4107 @Override
4108 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004109 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004110 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004111 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4112 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4113 "IMS not available on device.");
4114 }
4115 final long token = Binder.clearCallingIdentity();
4116 try {
4117 Phone phone = getPhone(subId);
4118 if (phone == null) {
4119 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4120 + subId + "'");
4121 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4122 }
4123 phone.getImsRegistrationTech(regTech -> {
4124 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4125 int regTechConverted = (regTech == null)
4126 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4127 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4128 regTechConverted);
4129 try {
4130 consumer.accept(regTechConverted);
4131 } catch (RemoteException e) {
4132 // Ignore if the remote process is no longer available to call back.
4133 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4134 }
4135 });
4136 } finally {
4137 Binder.restoreCallingIdentity(token);
4138 }
4139 }
4140
shilu366312e2019-12-17 09:28:10 -08004141 /**
4142 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4143 * @param subId The subscription to use to check the configuration.
4144 * @param c The callback that will be used to send the result.
4145 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004147 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4148 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004149 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004150 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004151 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4152 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4153 "IMS not available on device.");
4154 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 final long token = Binder.clearCallingIdentity();
4156 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004157 int slotId = getSlotIndexOrException(subId);
4158 verifyImsMmTelConfiguredOrThrow(slotId);
4159 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004160 } catch (ImsException e) {
4161 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004162 } finally {
4163 Binder.restoreCallingIdentity(token);
4164 }
4165 }
4166
shilu366312e2019-12-17 09:28:10 -08004167 /**
4168 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4169 * @param subId The subscription to use to check the configuration.
4170 * @param c The callback that will be used to send the result.
4171 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004172 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004173 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004174 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004175 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004176 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4177 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4178 }
Meng Wangafbc5852019-09-19 17:37:13 -07004179
4180 final long token = Binder.clearCallingIdentity();
4181 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004182 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004183 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004184 } catch (ImsException e) {
4185 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4186 + "is inactive, ignoring unregister.");
4187 // If the subscription is no longer active, just return, since the callback
4188 // will already have been removed internally.
4189 } finally {
4190 Binder.restoreCallingIdentity(token);
4191 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 }
4193
4194 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004195 public boolean isCapable(int subId, int capability, int regTech) {
4196 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 final long token = Binder.clearCallingIdentity();
4198 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004199 int slotId = getSlotIndexOrException(subId);
4200 verifyImsMmTelConfiguredOrThrow(slotId);
4201 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4202 } catch (com.android.ims.ImsException e) {
4203 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4204 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004205 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004206 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4207 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 } finally {
4209 Binder.restoreCallingIdentity(token);
4210 }
4211 }
4212
4213 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004214 public boolean isAvailable(int subId, int capability, int regTech) {
4215 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 final long token = Binder.clearCallingIdentity();
4217 try {
4218 Phone phone = getPhone(subId);
4219 if (phone == null) return false;
4220 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004221 } catch (com.android.ims.ImsException e) {
4222 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4223 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 } finally {
4225 Binder.restoreCallingIdentity(token);
4226 }
4227 }
4228
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004229 /**
4230 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4231 * subscription.
4232 * @param subId The subscription to use to check the configuration.
4233 * @param callback The callback that will be used to send the result.
4234 * @param capability The MmTelFeature capability that will be used to send the result.
4235 * @param transportType The transport type of the MmTelFeature capability.
4236 */
4237 @Override
4238 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4239 int transportType) {
4240 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004241 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4242 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4243 "IMS not available on device.");
4244 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004245 final long token = Binder.clearCallingIdentity();
4246 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004247 int slotId = getSlotIndex(subId);
4248 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4249 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4250 + subId + "'");
4251 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4252 }
4253 verifyImsMmTelConfiguredOrThrow(slotId);
4254 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4255 transportType, aBoolean -> {
4256 try {
4257 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4258 } catch (RemoteException e) {
4259 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4260 + "running. Ignore");
4261 }
4262 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004263 } catch (ImsException e) {
4264 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004265 } finally {
4266 Binder.restoreCallingIdentity(token);
4267 }
4268 }
4269
shilu366312e2019-12-17 09:28:10 -08004270 /**
4271 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4272 * @param subId The subscription to use to check the configuration.
4273 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004274 @Override
4275 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004276 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004277 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004278
Brad Ebinger35c841c2018-10-01 10:40:55 -07004279 final long token = Binder.clearCallingIdentity();
4280 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004281 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004282 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004283 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004284 } catch (ImsException e) {
4285 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004286 } finally {
4287 Binder.restoreCallingIdentity(token);
4288 }
4289 }
4290
4291 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004292 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004294 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 final long identity = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004298 // This setting doesn't require an active ImsService connection, so do not verify. The
4299 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004300 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004308 /**
4309 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4310 * @param subId The subscription to use to check the configuration.
4311 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004312 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004313 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004314 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004315 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004316 final long identity = Binder.clearCallingIdentity();
4317 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004318 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004319 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004320 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004321 } catch (ImsException e) {
4322 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004323 } finally {
4324 Binder.restoreCallingIdentity(identity);
4325 }
4326 }
4327
4328 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004329 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004331 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 final long identity = Binder.clearCallingIdentity();
4333 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004335 // This setting doesn't require an active ImsService connection, so do not verify. The
4336 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004337 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004338 } catch (ImsException e) {
4339 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004340 } finally {
4341 Binder.restoreCallingIdentity(identity);
4342 }
4343 }
4344
shilu366312e2019-12-17 09:28:10 -08004345 /**
4346 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4347 * @param subId The subscription to use to check the configuration.
4348 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004349 @Override
4350 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004351 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004352 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004353 final long identity = Binder.clearCallingIdentity();
4354 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004355 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004356 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004357 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004358 } catch (ImsException e) {
4359 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004360 } finally {
4361 Binder.restoreCallingIdentity(identity);
4362 }
4363 }
4364
4365 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004366 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004368 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 final long identity = Binder.clearCallingIdentity();
4370 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004371 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004372 // This setting doesn't require an active ImsService connection, so do not verify. The
4373 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004374 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004375 } catch (ImsException e) {
4376 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004377 } finally {
4378 Binder.restoreCallingIdentity(identity);
4379 }
4380 }
4381
shilu366312e2019-12-17 09:28:10 -08004382 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004383 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4384 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4385 * @param subId The subscription to use to check the configuration.
4386 */
4387 @Override
4388 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004389 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004390 mApp, subId, "isCrossSimCallingEnabledByUser");
4391 final long identity = Binder.clearCallingIdentity();
4392 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004393 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004394 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004396 } catch (ImsException e) {
4397 throw new ServiceSpecificException(e.getCode());
4398 } finally {
4399 Binder.restoreCallingIdentity(identity);
4400 }
4401 }
4402
4403 /**
4404 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4405 * Requires MODIFY_PHONE_STATE permission.
4406 * @param subId The subscription to use to check the configuration.
4407 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4408 * false otherwise
4409 */
4410 @Override
4411 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4413 "setCrossSimCallingEnabled");
4414 final long identity = Binder.clearCallingIdentity();
4415 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004416 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004417 // This setting doesn't require an active ImsService connection, so do not verify. The
4418 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004419 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004420 } catch (ImsException e) {
4421 throw new ServiceSpecificException(e.getCode());
4422 } finally {
4423 Binder.restoreCallingIdentity(identity);
4424 }
4425 }
4426
4427 /**
shilu366312e2019-12-17 09:28:10 -08004428 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4429 * @param subId The subscription to use to check the configuration.
4430 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004431 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004432
Brad Ebinger35c841c2018-10-01 10:40:55 -07004433 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004434 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004435 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004436 final long identity = Binder.clearCallingIdentity();
4437 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004438 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004439 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004440 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004441 } catch (ImsException e) {
4442 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004443 } finally {
4444 Binder.restoreCallingIdentity(identity);
4445 }
4446 }
4447
4448 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004449 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004451 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004452 final long identity = Binder.clearCallingIdentity();
4453 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004454 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004455 // This setting doesn't require an active ImsService connection, so do not verify. The
4456 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004457 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004458 } catch (ImsException e) {
4459 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004460 } finally {
4461 Binder.restoreCallingIdentity(identity);
4462 }
4463 }
4464
4465 @Override
4466 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4468 "setVoWiFiNonPersistent");
4469 final long identity = Binder.clearCallingIdentity();
4470 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004471 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004472 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004473 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004474 } catch (ImsException e) {
4475 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004476 } finally {
4477 Binder.restoreCallingIdentity(identity);
4478 }
4479 }
4480
shilu366312e2019-12-17 09:28:10 -08004481 /**
4482 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4483 * @param subId The subscription to use to check the configuration.
4484 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004485 @Override
4486 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004487 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004488 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004489 final long identity = Binder.clearCallingIdentity();
4490 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004491 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004492 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004493 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004494 } catch (ImsException e) {
4495 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004496 } finally {
4497 Binder.restoreCallingIdentity(identity);
4498 }
4499 }
4500
4501 @Override
4502 public void setVoWiFiModeSetting(int subId, int mode) {
4503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4504 "setVoWiFiModeSetting");
4505 final long identity = Binder.clearCallingIdentity();
4506 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004507 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004508 // This setting doesn't require an active ImsService connection, so do not verify. The
4509 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004510 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004511 } catch (ImsException e) {
4512 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
4516 }
4517
4518 @Override
4519 public int getVoWiFiRoamingModeSetting(int subId) {
4520 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4521 final long identity = Binder.clearCallingIdentity();
4522 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004523 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004524 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004525 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004526 } catch (ImsException e) {
4527 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004528 } finally {
4529 Binder.restoreCallingIdentity(identity);
4530 }
4531 }
4532
4533 @Override
4534 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4536 "setVoWiFiRoamingModeSetting");
4537 final long identity = Binder.clearCallingIdentity();
4538 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004539 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004540 // This setting doesn't require an active ImsService connection, so do not verify. The
4541 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004542 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004543 } catch (ImsException e) {
4544 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004545 } finally {
4546 Binder.restoreCallingIdentity(identity);
4547 }
4548 }
4549
4550 @Override
4551 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4553 "setRttCapabilityEnabled");
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004556 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004557 // This setting doesn't require an active ImsService connection, so do not verify. The
4558 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004559 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004560 } catch (ImsException e) {
4561 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004562 } finally {
4563 Binder.restoreCallingIdentity(identity);
4564 }
4565 }
4566
shilu366312e2019-12-17 09:28:10 -08004567 /**
4568 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4569 * @param subId The subscription to use to check the configuration.
4570 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004571 @Override
4572 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004573 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004574 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004575 final long identity = Binder.clearCallingIdentity();
4576 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004577 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004578 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004579 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004580 } catch (ImsException e) {
4581 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
4585 }
4586
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004587 @Override
4588 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4589 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004590
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004591 final long identity = Binder.clearCallingIdentity();
4592 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004593 if (!isImsAvailableOnDevice()) {
4594 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4595 "IMS not available on device.");
4596 }
4597 int slotId = getSlotIndexOrException(subId);
4598 verifyImsMmTelConfiguredOrThrow(slotId);
4599 ImsManager.getInstance(mApp, slotId)
4600 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004601 } catch (ImsException e) {
4602 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004603 } finally {
4604 Binder.restoreCallingIdentity(identity);
4605 }
4606 }
4607
4608 @Override
4609 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4610 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004611
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004612 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004613 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4614 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4615 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004616 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004617 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004618 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004619 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004620 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4621 + "is inactive, ignoring unregister.");
4622 // If the subscription is no longer active, just return, since the callback will already
4623 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004624 } finally {
4625 Binder.restoreCallingIdentity(identity);
4626 }
4627 }
4628
joonhunshincffb7fc2021-11-28 07:32:01 +00004629 @Override
4630 public void registerFeatureProvisioningChangedCallback(int subId,
4631 IFeatureProvisioningCallback callback) {
4632 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4633 mApp, subId, "registerFeatureProvisioningChangedCallback");
4634
4635 final long identity = Binder.clearCallingIdentity();
4636 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4637 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4638 }
4639
joonhunshin91bc1952022-04-29 08:47:15 +00004640 try {
4641 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4642 if (controller == null) {
4643 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4644 "Device does not support IMS");
4645 }
4646 controller.addFeatureProvisioningChangedCallback(subId, callback);
4647 } finally {
4648 Binder.restoreCallingIdentity(identity);
4649 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004650 }
4651
4652 @Override
4653 public void unregisterFeatureProvisioningChangedCallback(int subId,
4654 IFeatureProvisioningCallback callback) {
4655 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4656 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4657
4658 final long identity = Binder.clearCallingIdentity();
4659 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4660 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4661 }
4662
joonhunshin91bc1952022-04-29 08:47:15 +00004663 try {
4664 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4665 if (controller == null) {
4666 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4667 return;
4668 }
4669 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4670 } finally {
4671 Binder.restoreCallingIdentity(identity);
4672 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004673 }
allenwtsu99c623b2020-01-03 18:24:23 +08004674
4675 private void checkModifyPhoneStatePermission(int subId, String message) {
4676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4677 message);
4678 }
4679
allenwtsu99c623b2020-01-03 18:24:23 +08004680 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004681 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004682 boolean isProvisioned) {
4683 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4684
4685 final long identity = Binder.clearCallingIdentity();
4686 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004687 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4688 if (controller == null) {
4689 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4690 return;
4691 }
4692 controller.setRcsProvisioningStatusForCapability(
4693 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004694 } finally {
4695 Binder.restoreCallingIdentity(identity);
4696 }
allenwtsu99c623b2020-01-03 18:24:23 +08004697 }
4698
4699
4700 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004701 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4702 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4703 mApp, subId, "getRcsProvisioningStatusForCapability");
4704
allenwtsu99c623b2020-01-03 18:24:23 +08004705 final long identity = Binder.clearCallingIdentity();
4706 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004707 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4708 if (controller == null) {
4709 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4710
4711 // device does not support IMS, this method will return true always.
4712 return true;
4713 }
4714 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004715 } finally {
4716 Binder.restoreCallingIdentity(identity);
4717 }
4718 }
4719
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004720 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004721 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4722 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004723 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004724
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004725 final long identity = Binder.clearCallingIdentity();
4726 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004727 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4728 if (controller == null) {
4729 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4730 return;
4731 }
4732 controller.setImsProvisioningStatusForCapability(
4733 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 } finally {
4735 Binder.restoreCallingIdentity(identity);
4736 }
4737 }
4738
4739 @Override
4740 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004741 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4742 mApp, subId, "getProvisioningStatusForCapability");
4743
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004744 final long identity = Binder.clearCallingIdentity();
4745 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004746 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4747 if (controller == null) {
4748 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004749
joonhunshin91bc1952022-04-29 08:47:15 +00004750 // device does not support IMS, this method will return true always.
4751 return true;
4752 }
4753 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004754 } finally {
4755 Binder.restoreCallingIdentity(identity);
4756 }
4757 }
4758
4759 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004760 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4761 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4762 mApp, subId, "isProvisioningRequiredForCapability");
4763
4764 final long identity = Binder.clearCallingIdentity();
4765 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004766 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4767 if (controller == null) {
4768 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4769
4770 // device does not support IMS, this method will return false
4771 return false;
4772 }
4773 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004774 } finally {
4775 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004776 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004777 }
4778
4779 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004780 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4781 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4782 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004783
joonhunshincffb7fc2021-11-28 07:32:01 +00004784 final long identity = Binder.clearCallingIdentity();
4785 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004786 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4787 if (controller == null) {
4788 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4789
4790 // device does not support IMS, this method will return false
4791 return false;
4792 }
4793 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004794 } finally {
4795 Binder.restoreCallingIdentity(identity);
4796 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004797 }
4798
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004799 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004800 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004801 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4802 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4803 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004804 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4805 mApp, subId, "getImsProvisioningInt");
4806
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004807 final long identity = Binder.clearCallingIdentity();
4808 try {
4809 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004810 int slotId = getSlotIndex(subId);
4811 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4812 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4813 + subId + "' for key:" + key);
4814 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4815 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004816
joonhunshin91bc1952022-04-29 08:47:15 +00004817 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4818 if (controller == null) {
4819 loge("getImsProvisioningInt: Device does not support IMS");
4820
4821 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4822 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4823 }
4824 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004825 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4826 return retVal;
4827 }
4828
calvinpanb5a34062021-02-08 19:59:36 +08004829 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004830 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004831 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4832 + subId + "' for key:" + key);
4833 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004834 } finally {
4835 Binder.restoreCallingIdentity(identity);
4836 }
4837 }
4838
4839 @Override
4840 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004841 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4842 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4843 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004844 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4845 mApp, subId, "getImsProvisioningString");
4846
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004847 final long identity = Binder.clearCallingIdentity();
4848 try {
4849 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004850 int slotId = getSlotIndex(subId);
4851 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4852 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4853 + subId + "' for key:" + key);
4854 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4855 }
calvinpanb5a34062021-02-08 19:59:36 +08004856 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004857 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004858 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4859 + subId + "' for key:" + key);
4860 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
4864 }
4865
4866 @Override
4867 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004868 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4869 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4870 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4872 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004873
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004874 final long identity = Binder.clearCallingIdentity();
4875 try {
4876 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004877 int slotId = getSlotIndex(subId);
4878 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4879 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4880 + subId + "' for key:" + key);
4881 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4882 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004883
joonhunshin91bc1952022-04-29 08:47:15 +00004884 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4885 if (controller == null) {
4886 loge("setImsProvisioningInt: Device does not support IMS");
4887
4888 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
4889 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4890 }
4891 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00004892 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4893 return retVal;
4894 }
4895
calvinpanb5a34062021-02-08 19:59:36 +08004896 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4897 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004898 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004899 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004900 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
4904 }
4905
4906 @Override
4907 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004908 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4909 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4910 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4912 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004913 final long identity = Binder.clearCallingIdentity();
4914 try {
4915 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004916 int slotId = getSlotIndex(subId);
4917 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4918 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4919 + subId + "' for key:" + key);
4920 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4921 }
calvinpanb5a34062021-02-08 19:59:36 +08004922 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4923 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004924 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004925 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004926 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004927 } finally {
4928 Binder.restoreCallingIdentity(identity);
4929 }
4930 }
4931
Brad Ebinger919631e2021-06-02 17:46:35 -07004932 /**
4933 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4934 * for the given slot ID or no ImsResolver instance has been created.
4935 * @param slotId The slot ID that the IMS service is created for.
4936 * @throws ImsException If there is no ImsService configured for this slot.
4937 */
4938 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4939 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4940 ImsFeature.FEATURE_MMTEL)) {
4941 throw new ImsException("This subscription does not support MMTEL over IMS",
4942 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4943 }
4944 }
4945
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004946 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004947 int slotId = SubscriptionManager.getSlotIndex(subId);
4948 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004949 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4950 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004951 }
4952 return slotId;
4953 }
4954
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004955 private int getSlotIndex(int subId) {
4956 int slotId = SubscriptionManager.getSlotIndex(subId);
4957 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4958 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4959 }
4960 return slotId;
4961 }
4962
Wink Saville36469e72014-06-11 15:17:00 -07004963 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004964 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004965 */
4966 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004967 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4968 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004969 try {
4970 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4971 } catch (SecurityException se) {
4972 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4973 throw new SecurityException("Package " + callingPackage + " does not belong to "
4974 + Binder.getCallingUid());
4975 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004976 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004977 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004978 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004979 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004980 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004981 mApp, subId, callingPackage, callingFeatureId,
4982 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004983 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4984 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986 final long identity = Binder.clearCallingIdentity();
4987 try {
4988 final Phone phone = getPhone(subId);
4989 if (phone != null) {
4990 return phone.getServiceState().getDataNetworkType();
4991 } else {
4992 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4993 }
4994 } finally {
4995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004997 }
4998
4999 /**
5000 * Returns the data network type
5001 */
5002 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005003 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005004 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5005 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005006 }
5007
5008 /**
5009 * Returns the data network type for a subId
5010 */
5011 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005012 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5013 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005014 String functionName = "getDataNetworkTypeForSubscriber";
5015 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5016 mApp, functionName)) {
5017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5018 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5019 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5020 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005021 }
5022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 final long identity = Binder.clearCallingIdentity();
5024 try {
5025 final Phone phone = getPhone(subId);
5026 if (phone != null) {
5027 return phone.getServiceState().getDataNetworkType();
5028 } else {
5029 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5030 }
5031 } finally {
5032 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005033 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005034 }
5035
5036 /**
Wink Saville36469e72014-06-11 15:17:00 -07005037 * Returns the Voice network type for a subId
5038 */
5039 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005040 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5041 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005042 String functionName = "getVoiceNetworkTypeForSubscriber";
5043 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5044 mApp, functionName)) {
5045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5046 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5047 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5048 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005049 }
5050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005051 final long identity = Binder.clearCallingIdentity();
5052 try {
5053 final Phone phone = getPhone(subId);
5054 if (phone != null) {
5055 return phone.getServiceState().getVoiceNetworkType();
5056 } else {
5057 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5058 }
5059 } finally {
5060 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005062 }
5063
5064 /**
5065 * @return true if a ICC card is present
5066 */
5067 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005068 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005069 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5070 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005071 }
5072
5073 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005074 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005075 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005076 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005077 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 final long identity = Binder.clearCallingIdentity();
5079 try {
5080 final Phone phone = PhoneFactory.getPhone(slotIndex);
5081 if (phone != null) {
5082 return phone.getIccCard().hasIccCard();
5083 } else {
5084 return false;
5085 }
5086 } finally {
5087 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005089 }
5090
5091 /**
5092 * Return if the current radio is LTE on CDMA. This
5093 * is a tri-state return value as for a period of time
5094 * the mode may be unknown.
5095 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005096 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005097 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005098 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005099 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005100 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005101 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5102 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5103 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005104 }
5105
Sanket Padawe356d7632015-06-22 14:03:32 -07005106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005107 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5108 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005109 try {
5110 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5111 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005112 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5113 }
5114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 final Phone phone = getPhone(subId);
5118 if (phone == null) {
5119 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5120 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005121 return TelephonyProperties.lte_on_cdma_device()
5122 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123 }
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005126 }
Wink Saville36469e72014-06-11 15:17:00 -07005127 }
5128
Wink Saville36469e72014-06-11 15:17:00 -07005129 /**
5130 * {@hide}
5131 * Returns Default subId, 0 in the case of single standby.
5132 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005133 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005134 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005135 }
5136
Shishir Agrawala9f32182016-04-12 12:00:16 -07005137 private int getSlotForDefaultSubscription() {
5138 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5139 }
5140
Wink Savilleb564aae2014-10-23 10:18:09 -07005141 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005142 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005143 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005144
Pengquan Menge92a50d2018-09-21 15:54:48 -07005145 private boolean isActiveSubscription(int subId) {
5146 return mSubscriptionController.isActiveSubId(subId);
5147 }
5148
Ihab Awadf2177b72013-11-25 13:33:23 -08005149 /**
5150 * @see android.telephony.TelephonyManager.WifiCallingChoices
5151 */
5152 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 final long identity = Binder.clearCallingIdentity();
5154 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005155 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5157 getWhenToMakeWifiCallsDefaultPreference());
5158 } finally {
5159 Binder.restoreCallingIdentity(identity);
5160 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005161 }
5162
5163 /**
5164 * @see android.telephony.TelephonyManager.WifiCallingChoices
5165 */
5166 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167 final long identity = Binder.clearCallingIdentity();
5168 try {
5169 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005170 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005175 }
5176
Sailesh Nepald1e68152013-12-12 19:08:02 -08005177 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005178 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005179 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005180 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005181
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005182 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5183 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5184 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005185 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005186 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5187 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005188 }
5189 return PhoneFactory.getPhone(phoneId);
5190 }
5191
Shishir Agrawal566b7612013-10-28 14:41:00 -07005192 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005193 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005194 @NonNull IccLogicalChannelRequest request) {
5195 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5196 /*message=*/ "iccOpenLogicalChannel");
5197
5198 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5199 // Verify that the callingPackage in the request belongs to the calling UID
5200 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5201
5202 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005203 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005204
Rambo Wanga1782702021-11-10 20:15:19 -08005205 private Phone getPhoneFromValidIccLogicalChannelRequest(
5206 @NonNull IccLogicalChannelRequest request, String message) {
5207 Phone phone;
5208 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5210 mApp, request.subId, message);
5211 phone = getPhoneFromSubId(request.subId);
5212 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5213 enforceModifyPermission();
5214 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5215 } else {
5216 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005217 }
Rambo Wanga1782702021-11-10 20:15:19 -08005218 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005219 }
5220
5221 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005222 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005225 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005227 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5228 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005229 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5230 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 loge("The calling package is not allowed to access ISD-R.");
5232 throw new SecurityException(
5233 "The calling package is not allowed to access ISD-R.");
5234 }
Derek Tan740e1672017-06-27 14:56:27 -07005235 }
Derek Tan740e1672017-06-27 14:56:27 -07005236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005238 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5239 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005240 return response;
5241 } finally {
5242 Binder.restoreCallingIdentity(identity);
5243 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005244 }
5245
5246 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005247 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5248 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5249 /*message=*/"iccCloseLogicalChannel");
5250
5251 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5252
5253 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005254 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005255
Rambo Wanga1782702021-11-10 20:15:19 -08005256 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5257 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005258 // before this feature is enabled, this API should only return false if
5259 // the operation fails instead of throwing runtime exception for
5260 // backward-compatibility.
5261 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5262 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 final long identity = Binder.clearCallingIdentity();
5264 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005265 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005266 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267 }
Chen Xue9d737e2022-01-01 23:41:31 -08005268 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005269 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005270 Boolean success = false;
5271 if (result instanceof RuntimeException) {
5272 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005273 if (shouldThrowExceptionOnFailure) {
5274 throw (RuntimeException) result;
5275 } else {
5276 return false;
5277 }
Chen Xue9d737e2022-01-01 23:41:31 -08005278 } else if (result instanceof Boolean) {
5279 success = (Boolean) result;
5280 } else {
5281 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5282 }
Rambo Wanga1782702021-11-10 20:15:19 -08005283 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 return success;
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005287 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005288 }
5289
5290 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005291 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005292 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5294 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005295 if (DBG) {
5296 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5297 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5298 + p3 + " data=" + data);
5299 }
5300 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5301 command, p1, p2, p3, data);
5302 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005303
Jordan Liu4c733742019-02-28 12:03:40 -08005304 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005305 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5306 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005307 enforceModifyPermission();
5308 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005309 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5310 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5311 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005312 }
5313 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005314 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5315 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005316 }
5317
5318 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5319 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 final long identity = Binder.clearCallingIdentity();
5321 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005322 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 return "";
5324 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005327 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5328 null /* workSource */);
5329 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 // Append the returned status code to the end of the response payload.
5332 String s = Integer.toHexString(
5333 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5334 if (response.payload != null) {
5335 s = IccUtils.bytesToHexString(response.payload) + s;
5336 }
5337 return s;
5338 } finally {
5339 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005340 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005341 }
Jake Hambye994d462014-02-03 13:10:13 -08005342
Evan Charltonc66da362014-05-16 14:06:40 -07005343 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005344 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5345 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5347 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005349 if (DBG) {
5350 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5351 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5352 }
5353 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5354 cla, command, p1, p2, p3, data);
5355 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005356
Jordan Liu4c733742019-02-28 12:03:40 -08005357 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005358 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5359 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005360 enforceModifyPermission();
5361 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5362 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005363 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5364 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5365 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005366 }
5367
5368 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005369 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5370 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005371 }
5372
5373 // open APDU basic channel assuming the caller has sufficient permissions
5374 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5375 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 final long identity = Binder.clearCallingIdentity();
5377 try {
5378 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5379 && TextUtils.equals(ISDR_AID, data)) {
5380 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005381 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5382 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 if (bestComponent == null
5384 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5385 loge("The calling package is not allowed to select ISD-R.");
5386 throw new SecurityException(
5387 "The calling package is not allowed to select ISD-R.");
5388 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005389 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005392 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5393 null /* workSource */);
5394 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 // Append the returned status code to the end of the response payload.
5397 String s = Integer.toHexString(
5398 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5399 if (response.payload != null) {
5400 s = IccUtils.bytesToHexString(response.payload) + s;
5401 }
5402 return s;
5403 } finally {
5404 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005405 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005406 }
5407
5408 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005409 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005410 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5412 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005413
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414 final long identity = Binder.clearCallingIdentity();
5415 try {
5416 if (DBG) {
5417 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5418 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5419 }
5420
5421 IccIoResult response =
5422 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5423 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5424 subId);
5425
5426 if (DBG) {
5427 log("Exchange SIM_IO [R]" + response);
5428 }
5429
5430 byte[] result = null;
5431 int length = 2;
5432 if (response.payload != null) {
5433 length = 2 + response.payload.length;
5434 result = new byte[length];
5435 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5436 } else {
5437 result = new byte[length];
5438 }
5439
5440 result[length - 1] = (byte) response.sw2;
5441 result[length - 2] = (byte) response.sw1;
5442 return result;
5443 } finally {
5444 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005445 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005446 }
5447
Nathan Haroldb3014052017-01-25 15:57:32 -08005448 /**
5449 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5450 * on a particular subscription
5451 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005452 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5453 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005454 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005455 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005456 return null;
5457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458
5459 final long identity = Binder.clearCallingIdentity();
5460 try {
5461 if (appType != TelephonyManager.APPTYPE_USIM
5462 && appType != TelephonyManager.APPTYPE_SIM) {
5463 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5464 return null;
5465 }
5466 Object response = sendRequest(
5467 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5468 if (response instanceof String[]) {
5469 return (String[]) response;
5470 }
yincheng zhao2737e882019-09-06 17:06:54 -07005471 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005473 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 } finally {
5475 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005476 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005477 }
5478
yincheng zhao2737e882019-09-06 17:06:54 -07005479 /**
5480 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5481 * subscription.
5482 *
5483 * @param subId the id of the subscription.
5484 * @param appType the uicc app type, must be USIM or SIM.
5485 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5486 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005487 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005488 * @return number of fplmns that is successfully written to the SIM.
5489 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005490 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5491 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5493 mApp, subId, "setForbiddenPlmns");
5494
yincheng zhao2737e882019-09-06 17:06:54 -07005495 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5496 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5497 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5498 }
5499 if (fplmns == null) {
5500 throw new IllegalArgumentException("Fplmn List provided is null");
5501 }
5502 for (String fplmn : fplmns) {
5503 if (!CellIdentity.isValidPlmn(fplmn)) {
5504 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5505 }
5506 }
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 Object response = sendRequest(
5510 CMD_SET_FORBIDDEN_PLMNS,
5511 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5512 subId);
5513 return (int) response;
5514 } finally {
5515 Binder.restoreCallingIdentity(identity);
5516 }
5517 }
5518
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005519 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005520 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5522 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 final long identity = Binder.clearCallingIdentity();
5525 try {
5526 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5527 if (response.payload == null) {
5528 return "";
5529 }
Evan Charltonc66da362014-05-16 14:06:40 -07005530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 // Append the returned status code to the end of the response payload.
5532 String s = Integer.toHexString(
5533 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5534 s = IccUtils.bytesToHexString(response.payload) + s;
5535 return s;
5536 } finally {
5537 Binder.restoreCallingIdentity(identity);
5538 }
Evan Charltonc66da362014-05-16 14:06:40 -07005539 }
5540
Jake Hambye994d462014-02-03 13:10:13 -08005541 /**
5542 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5543 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5544 *
5545 * @param itemID the ID of the item to read
5546 * @return the NV item as a String, or null on error.
5547 */
5548 @Override
5549 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005550 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5552 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553
5554 final long identity = Binder.clearCallingIdentity();
5555 try {
5556 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005557 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5559 return value;
5560 } finally {
5561 Binder.restoreCallingIdentity(identity);
5562 }
Jake Hambye994d462014-02-03 13:10:13 -08005563 }
5564
5565 /**
5566 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5567 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5568 *
5569 * @param itemID the ID of the item to read
5570 * @param itemValue the value to write, as a String
5571 * @return true on success; false on any failure
5572 */
5573 @Override
5574 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005575 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5577 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578
5579 final long identity = Binder.clearCallingIdentity();
5580 try {
5581 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5582 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005583 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5585 return success;
5586 } finally {
5587 Binder.restoreCallingIdentity(identity);
5588 }
Jake Hambye994d462014-02-03 13:10:13 -08005589 }
5590
5591 /**
5592 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5593 * Used for device configuration by some CDMA operators.
5594 *
5595 * @param preferredRoamingList byte array containing the new PRL
5596 * @return true on success; false on any failure
5597 */
5598 @Override
5599 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5601 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602
5603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5606 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5607 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5608 return success;
5609 } finally {
5610 Binder.restoreCallingIdentity(identity);
5611 }
Jake Hambye994d462014-02-03 13:10:13 -08005612 }
5613
5614 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005615 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005616 * Used for device configuration by some CDMA operators.
5617 *
chen xu6dac5ab2018-10-26 17:39:23 -07005618 * @param slotIndex - device slot.
5619 *
Jake Hambye994d462014-02-03 13:10:13 -08005620 * @return true on success; false on any failure
5621 */
5622 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005623 public boolean resetModemConfig(int slotIndex) {
5624 Phone phone = PhoneFactory.getPhone(slotIndex);
5625 if (phone != null) {
5626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5627 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628
chen xu6dac5ab2018-10-26 17:39:23 -07005629 final long identity = Binder.clearCallingIdentity();
5630 try {
5631 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5632 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5633 return success;
5634 } finally {
5635 Binder.restoreCallingIdentity(identity);
5636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 }
chen xu6dac5ab2018-10-26 17:39:23 -07005638 return false;
5639 }
5640
5641 /**
5642 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5643 *
5644 * @param slotIndex - device slot.
5645 *
5646 * @return true on success; false on any failure
5647 */
5648 @Override
5649 public boolean rebootModem(int slotIndex) {
5650 Phone phone = PhoneFactory.getPhone(slotIndex);
5651 if (phone != null) {
5652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5653 mApp, phone.getSubId(), "rebootModem");
5654
5655 final long identity = Binder.clearCallingIdentity();
5656 try {
5657 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5658 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5659 return success;
5660 } finally {
5661 Binder.restoreCallingIdentity(identity);
5662 }
5663 }
5664 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005665 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005666
Brad Ebinger51f743a2017-01-23 13:50:20 -08005667 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005668 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5669 * {@link #disableIms(int)}.
5670 * @param slotIndex device slot.
5671 */
5672 public void resetIms(int slotIndex) {
5673 enforceModifyPermission();
5674
5675 final long identity = Binder.clearCallingIdentity();
5676 try {
5677 if (mImsResolver == null) {
5678 // may happen if the does not support IMS.
5679 return;
5680 }
5681 mImsResolver.disableIms(slotIndex);
5682 mImsResolver.enableIms(slotIndex);
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
5686 }
5687
5688 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005689 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5690 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005691 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005692 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005693 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694
5695 final long identity = Binder.clearCallingIdentity();
5696 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005697 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005698 // may happen if the device does not support IMS.
5699 return;
5700 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005701 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 } finally {
5703 Binder.restoreCallingIdentity(identity);
5704 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005705 }
5706
5707 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005708 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5709 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005710 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005711 public void disableIms(int slotId) {
5712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713
5714 final long identity = Binder.clearCallingIdentity();
5715 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005716 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005717 // may happen if the device does not support IMS.
5718 return;
5719 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005720 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721 } finally {
5722 Binder.restoreCallingIdentity(identity);
5723 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005724 }
5725
5726 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005727 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5728 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005729 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005730 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005731 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005732 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733
5734 final long identity = Binder.clearCallingIdentity();
5735 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005736 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005737 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5738 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005739 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005740 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005744 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005745 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005746 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5747 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005748 @Override
5749 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005750 enforceModifyPermission();
5751
5752 final long identity = Binder.clearCallingIdentity();
5753 try {
5754 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005755 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005756 } finally {
5757 Binder.restoreCallingIdentity(identity);
5758 }
5759 }
5760
5761 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005762 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005763 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005764 */
5765 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5766 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767
5768 final long identity = Binder.clearCallingIdentity();
5769 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005770 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005771 // may happen if the device does not support IMS.
5772 return null;
5773 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005774 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005778 }
5779
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005780 /**
5781 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005782 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005783 */
5784 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5785 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786
5787 final long identity = Binder.clearCallingIdentity();
5788 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005790 // may happen if the device does not support IMS.
5791 return null;
5792 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005793 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005797 }
5798
Brad Ebinger884c07b2018-02-15 16:17:40 -08005799 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005800 * Sets the ImsService Package Name that Telephony will bind to.
5801 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005802 * @param slotIndex the slot ID that the ImsService should bind for.
5803 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005804 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005805 * @param featureTypes An integer array of feature types associated with a packageName.
5806 * @param packageName The name of the package that the current configuration will be replaced
5807 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005808 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005809 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005810 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5811 int[] featureTypes, String packageName) {
5812 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5813 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5815 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005816 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 final long identity = Binder.clearCallingIdentity();
5819 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005820 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005821 // may happen if the device does not support IMS.
5822 return false;
5823 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005824 Map<Integer, String> featureConfig = new HashMap<>();
5825 for (int featureType : featureTypes) {
5826 featureConfig.put(featureType, packageName);
5827 }
5828 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5829 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830 } finally {
5831 Binder.restoreCallingIdentity(identity);
5832 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005833 }
5834
5835 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005836 * Clears any carrier ImsService overrides for the slot index specified that were previously
5837 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5838 *
5839 * This should only be used for testing.
5840 *
5841 * @param slotIndex the slot ID that the ImsService should bind for.
5842 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5843 */
5844 @Override
5845 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5846 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5847 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5848 "clearCarrierImsServiceOverride");
5849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5850 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5851 "clearCarrierImsServiceOverride");
5852
5853 final long identity = Binder.clearCallingIdentity();
5854 try {
5855 if (mImsResolver == null) {
5856 // may happen if the device does not support IMS.
5857 return false;
5858 }
5859 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
5863 }
5864
5865 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005866 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005867 *
5868 * @param slotId The slot that the ImsService is associated with.
5869 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5870 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005871 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005872 * @return the package name of the ImsService configuration.
5873 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005874 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5875 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005876 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005877 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005878 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005879 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5880 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 final long identity = Binder.clearCallingIdentity();
5883 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005884 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005885 // may happen if the device does not support IMS.
5886 return "";
5887 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005888 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005889 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5890 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 } finally {
5892 Binder.restoreCallingIdentity(identity);
5893 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005894 }
5895
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005896 /**
5897 * Get the MmTelFeature state associated with the requested subscription id.
5898 * @param subId The subscription that the MmTelFeature is associated with.
5899 * @param callback A callback with an integer containing the
5900 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5901 */
5902 @Override
5903 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5904 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005905 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5906 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5907 "IMS not available on device.");
5908 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005909 final long token = Binder.clearCallingIdentity();
5910 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005911 int slotId = getSlotIndex(subId);
5912 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5913 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5914 + subId + "'");
5915 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5916 }
5917 verifyImsMmTelConfiguredOrThrow(slotId);
5918 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5919 try {
5920 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5921 } catch (RemoteException e) {
5922 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5923 + "Ignore");
5924 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005925 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005926 } catch (ImsException e) {
5927 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005928 } finally {
5929 Binder.restoreCallingIdentity(token);
5930 }
5931 }
5932
Daniel Brightbb5840b2021-01-12 15:48:18 -08005933 /**
5934 * Sets the ims registration state on all valid {@link Phone}s.
5935 */
5936 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005937 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938
5939 final long identity = Binder.clearCallingIdentity();
5940 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005941 // NOTE: Before S, this method only set the default phone.
5942 for (final Phone phone : PhoneFactory.getPhones()) {
5943 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5944 phone.setImsRegistrationState(registered);
5945 }
5946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949 }
Wink Saville36469e72014-06-11 15:17:00 -07005950 }
5951
5952 /**
Stuart Scott54788802015-03-30 13:18:01 -07005953 * Set the network selection mode to automatic.
5954 *
5955 */
5956 @Override
5957 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5959 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960
5961 final long identity = Binder.clearCallingIdentity();
5962 try {
shilufc958392020-01-20 11:36:01 -08005963 if (!isActiveSubscription(subId)) {
5964 return;
5965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005967 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5968 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 } finally {
5970 Binder.restoreCallingIdentity(identity);
5971 }
Stuart Scott54788802015-03-30 13:18:01 -07005972 }
5973
Jack Yud10cdd42020-09-28 20:28:01 -07005974 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005975 * Ask the radio to connect to the input network and change selection mode to manual.
5976 *
5977 * @param subId the id of the subscription.
5978 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5979 * the operator to attach to.
5980 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5981 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5982 * normal network selection next time.
5983 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005984 */
5985 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005986 public boolean setNetworkSelectionModeManual(
5987 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5989 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005990
5991 if (!isActiveSubscription(subId)) {
5992 return false;
5993 }
5994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 final long identity = Binder.clearCallingIdentity();
5996 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005997 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005999 if (DBG) {
6000 log("setNetworkSelectionModeManual: subId: " + subId
6001 + " operator: " + operatorInfo);
6002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6004 } finally {
6005 Binder.restoreCallingIdentity(identity);
6006 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006007 }
shilu84f6e8b2019-12-19 13:58:01 -08006008 /**
6009 * Get the manual network selection
6010 *
6011 * @param subId the id of the subscription.
6012 *
6013 * @return the previously saved user selected PLMN
6014 */
6015 @Override
6016 public String getManualNetworkSelectionPlmn(int subId) {
6017 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006018 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006019 mApp, subId, "getManualNetworkSelectionPlmn");
6020
6021 final long identity = Binder.clearCallingIdentity();
6022 try {
6023 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006024 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006025 }
6026
6027 final Phone phone = getPhone(subId);
6028 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006029 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006030 }
6031 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6032 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6033 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6034 } finally {
6035 Binder.restoreCallingIdentity(identity);
6036 }
6037 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006038
6039 /**
6040 * Scans for available networks.
6041 */
6042 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006043 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6044 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6046 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006047 LocationAccessPolicy.LocationPermissionResult locationResult =
6048 LocationAccessPolicy.checkLocationPermission(mApp,
6049 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6050 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006051 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006052 .setCallingPid(Binder.getCallingPid())
6053 .setCallingUid(Binder.getCallingUid())
6054 .setMethod("getCellNetworkScanResults")
6055 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006056 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6057 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006058 .build());
6059 switch (locationResult) {
6060 case DENIED_HARD:
6061 throw new SecurityException("Not allowed to access scan results -- location");
6062 case DENIED_SOFT:
6063 return null;
6064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065
Pengquan Menga1bb6272018-09-06 09:59:22 -07006066 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 try {
6068 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006069 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 } finally {
6072 Binder.restoreCallingIdentity(identity);
6073 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006074 }
6075
6076 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006077 * Get the call forwarding info, given the call forwarding reason.
6078 */
6079 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006080 public void getCallForwarding(int subId, int callForwardingReason,
6081 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006082 enforceReadPrivilegedPermission("getCallForwarding");
6083 long identity = Binder.clearCallingIdentity();
6084 try {
6085 if (DBG) {
6086 log("getCallForwarding: subId " + subId
6087 + " callForwardingReason" + callForwardingReason);
6088 }
Hall Liu27d24262020-09-18 19:04:59 -07006089
6090 Phone phone = getPhone(subId);
6091 if (phone == null) {
6092 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006093 callback.onError(
6094 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006095 } catch (RemoteException e) {
6096 // ignore
6097 }
6098 return;
6099 }
6100
6101 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6102 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6103 @Override
6104 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6105 try {
6106 callback.onCallForwardingInfoAvailable(info);
6107 } catch (RemoteException e) {
6108 // ignore
6109 }
6110 }
6111
6112 @Override
6113 public void onError(int error) {
6114 try {
6115 callback.onError(error);
6116 } catch (RemoteException e) {
6117 // ignore
6118 }
6119 }
6120 });
6121 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006122 } finally {
6123 Binder.restoreCallingIdentity(identity);
6124 }
6125 }
6126
6127 /**
6128 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6129 * reason, the number to forward, and the timeout before the forwarding is attempted.
6130 */
6131 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006132 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6133 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006134 enforceModifyPermission();
6135 long identity = Binder.clearCallingIdentity();
6136 try {
6137 if (DBG) {
6138 log("setCallForwarding: subId " + subId
6139 + " callForwardingInfo" + callForwardingInfo);
6140 }
Hall Liu27d24262020-09-18 19:04:59 -07006141
6142 Phone phone = getPhone(subId);
6143 if (phone == null) {
6144 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006145 callback.accept(
6146 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006147 } catch (RemoteException e) {
6148 // ignore
6149 }
6150 return;
6151 }
6152
6153 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6154 FunctionalUtils.ignoreRemoteException(callback::accept));
6155
6156 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006157 } finally {
6158 Binder.restoreCallingIdentity(identity);
6159 }
6160 }
6161
6162 /**
Hall Liu27d24262020-09-18 19:04:59 -07006163 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006164 */
6165 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006166 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006167 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006168 long identity = Binder.clearCallingIdentity();
6169 try {
Hall Liu27d24262020-09-18 19:04:59 -07006170 Phone phone = getPhone(subId);
6171 if (phone == null) {
6172 try {
6173 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6174 } catch (RemoteException e) {
6175 // ignore
6176 }
6177 return;
6178 }
SongFerngWang0e767992021-03-31 22:08:45 +08006179 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6180 PersistableBundle c = configManager.getConfigForSubId(subId);
6181 boolean requireUssd = c.getBoolean(
6182 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006183
Shuo Qian4a594052020-01-23 11:59:30 -08006184 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006185 if (requireUssd) {
6186 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6187 getSubscriptionCarrierId(subId));
6188 String newUssdCommand = "";
6189 try {
6190 newUssdCommand = carrierXmlParser.getFeature(
6191 CarrierXmlParser.FEATURE_CALL_WAITING)
6192 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6193 } catch (NullPointerException e) {
6194 loge("Failed to generate USSD number" + e);
6195 }
6196 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6197 mMainThreadHandler, callback, carrierXmlParser,
6198 CarrierXmlParser.SsEntry.SSAction.QUERY);
6199 final String ussdCommand = newUssdCommand;
6200 Executors.newSingleThreadExecutor().execute(() -> {
6201 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6202 });
6203 } else {
6204 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6205 callback::accept);
6206 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6207 }
Shuo Qian4a594052020-01-23 11:59:30 -08006208 } finally {
6209 Binder.restoreCallingIdentity(identity);
6210 }
6211 }
6212
6213 /**
Hall Liu27d24262020-09-18 19:04:59 -07006214 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006215 */
6216 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006217 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006218 enforceModifyPermission();
6219 long identity = Binder.clearCallingIdentity();
6220 try {
Hall Liu27d24262020-09-18 19:04:59 -07006221 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6222
6223 Phone phone = getPhone(subId);
6224 if (phone == null) {
6225 try {
6226 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6227 } catch (RemoteException e) {
6228 // ignore
6229 }
6230 return;
6231 }
6232
SongFerngWang0e767992021-03-31 22:08:45 +08006233 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6234 PersistableBundle c = configManager.getConfigForSubId(subId);
6235 boolean requireUssd = c.getBoolean(
6236 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006237
SongFerngWang0e767992021-03-31 22:08:45 +08006238 if (DBG) log("getCallWaitingStatus: subId " + subId);
6239 if (requireUssd) {
6240 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6241 getSubscriptionCarrierId(subId));
6242 CarrierXmlParser.SsEntry.SSAction ssAction =
6243 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6244 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6245 String newUssdCommand = "";
6246 try {
6247 newUssdCommand = carrierXmlParser.getFeature(
6248 CarrierXmlParser.FEATURE_CALL_WAITING)
6249 .makeCommand(ssAction, null);
6250 } catch (NullPointerException e) {
6251 loge("Failed to generate USSD number" + e);
6252 }
6253 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6254 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6255 final String ussdCommand = newUssdCommand;
6256 Executors.newSingleThreadExecutor().execute(() -> {
6257 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6258 });
6259 } else {
6260 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6261 FunctionalUtils.ignoreRemoteException(callback::accept));
6262
6263 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6264 }
Shuo Qian4a594052020-01-23 11:59:30 -08006265 } finally {
6266 Binder.restoreCallingIdentity(identity);
6267 }
6268 }
6269
6270 /**
yinxub1bed742017-04-17 11:45:04 -07006271 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006272 *
yinxub1bed742017-04-17 11:45:04 -07006273 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006274 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6275 * location related information which will be sent if the caller already possess
6276 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006277 * @param request contains the radio access networks with bands/channels to scan
6278 * @param messenger callback messenger for scan results or errors
6279 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006280 * @return the id of the requested scan which can be used to stop the scan.
6281 */
6282 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006283 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6284 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006285 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6287 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006288 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006289 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6290 if (!renounceFineLocationAccess) {
6291 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6292 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6293 .setCallingPackage(callingPackage)
6294 .setCallingFeatureId(callingFeatureId)
6295 .setCallingPid(Binder.getCallingPid())
6296 .setCallingUid(Binder.getCallingUid())
6297 .setMethod("requestNetworkScan")
6298 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6299 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6300 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6301 .build());
6302 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006303 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006304 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6305 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006306 if (e != null) {
6307 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6308 throw e;
6309 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006310 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006311 return TelephonyScanManager.INVALID_SCAN_ID;
6312 }
6313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 }
Hall Liu912dfd32019-04-25 14:02:26 -07006315 int callingUid = Binder.getCallingUid();
6316 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006317 final long identity = Binder.clearCallingIdentity();
6318 try {
6319 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006320 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006321 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006322 } finally {
6323 Binder.restoreCallingIdentity(identity);
6324 }
yinxu504e1392017-04-12 16:03:22 -07006325 }
6326
Hall Liub2ac8ef2019-02-28 15:56:23 -08006327 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006328 NetworkScanRequest request, int subId, String callingPackage) {
6329 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006330 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6331 boolean hasNetworkScanPermission =
6332 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6333 == PERMISSION_GRANTED;
6334
6335 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6336 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6337 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006338 }
6339
6340 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6341 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006342 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6343 return new SecurityException("Specific channels must not be"
6344 + " scanned without location access.");
6345 }
6346 }
6347 }
6348
Hall Liub2ac8ef2019-02-28 15:56:23 -08006349 return null;
6350 }
6351
yinxu504e1392017-04-12 16:03:22 -07006352 /**
6353 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006354 *
6355 * @param subId id of the subscription
6356 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006357 */
6358 @Override
6359 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6361 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006362
Hall Liu912dfd32019-04-25 14:02:26 -07006363 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 final long identity = Binder.clearCallingIdentity();
6365 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006366 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 } finally {
6368 Binder.restoreCallingIdentity(identity);
6369 }
yinxu504e1392017-04-12 16:03:22 -07006370 }
6371
6372 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006373 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006374 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006375 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006376 */
6377 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006378 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006379 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006380 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006381 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382
6383 final long identity = Binder.clearCallingIdentity();
6384 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006385 if (DBG) log("getAllowedNetworkTypesBitmask");
6386 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6387 int networkTypesBitmask = (result != null ? result[0] : -1);
6388 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6389 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390 } finally {
6391 Binder.restoreCallingIdentity(identity);
6392 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006393 }
6394
6395 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006396 * Get the allowed network types for certain reason.
6397 *
6398 * @param subId the id of the subscription.
6399 * @param reason the reason the allowed network type change is taking place
6400 * @return the allowed network types.
6401 */
6402 @Override
6403 public long getAllowedNetworkTypesForReason(int subId,
6404 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006405 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006406 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006407 final long identity = Binder.clearCallingIdentity();
6408 try {
6409 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6410 } finally {
6411 Binder.restoreCallingIdentity(identity);
6412 }
6413 }
6414
6415 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006416 * Enable/Disable E-UTRA-NR Dual Connectivity
6417 * @param subId subscription id of the sim card
6418 * @param nrDualConnectivityState expected NR dual connectivity state
6419 * This can be passed following states
6420 * <ol>
6421 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6422 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6423 * <li>Disable NR dual connectivity and force secondary cell to be released
6424 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6425 * </ol>
6426 * @return operation result.
6427 */
6428 @Override
6429 public int setNrDualConnectivityState(int subId,
6430 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6432 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006433 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006434 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6435 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6436 }
6437
Sooraj Sasindran37444802020-08-11 10:40:43 -07006438 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6439 final long identity = Binder.clearCallingIdentity();
6440 try {
6441 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6442 nrDualConnectivityState, subId,
6443 workSource);
6444 if (DBG) log("enableNRDualConnectivity result: " + result);
6445 return result;
6446 } finally {
6447 Binder.restoreCallingIdentity(identity);
6448 }
6449 }
6450
6451 /**
6452 * Is E-UTRA-NR Dual Connectivity enabled
6453 * @return true if dual connectivity is enabled else false
6454 */
6455 @Override
6456 public boolean isNrDualConnectivityEnabled(int subId) {
6457 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006458 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006459 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006460 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006461 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6462 return false;
6463 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006464 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6465 final long identity = Binder.clearCallingIdentity();
6466 try {
6467 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6468 null, subId, workSource);
6469 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6470 return isEnabled;
6471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
6474 }
6475
6476 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006477 * Set the allowed network types of the device and
6478 * provide the reason triggering the allowed network change.
6479 *
6480 * @param subId the id of the subscription.
6481 * @param reason the reason the allowed network type change is taking place
6482 * @param allowedNetworkTypes the allowed network types.
6483 * @return true on success; false on any failure.
6484 */
6485 @Override
6486 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006487 @TelephonyManager.AllowedNetworkTypesReason int reason,
6488 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6490 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006491 // If the caller only has carrier privileges, then they should not be able to override
6492 // any network types which were set for security reasons.
6493 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6494 != PERMISSION_GRANTED
6495 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6496 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6497 throw new SecurityException(
6498 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6499 + " reason "
6500 + reason);
6501 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006502 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006503 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6504 return false;
6505 }
6506 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6507 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006508 return false;
6509 }
6510
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006511 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6512 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6513
6514
6515 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6516 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6517 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006518 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006519
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006520 final long identity = Binder.clearCallingIdentity();
6521 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006522 Boolean success = (Boolean) sendRequest(
6523 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6524 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6525
6526 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6527 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006528 } finally {
6529 Binder.restoreCallingIdentity(identity);
6530 }
6531 }
6532
6533 /**
Miaoa84611c2019-03-15 09:21:10 +08006534 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006535 *
Miaoa84611c2019-03-15 09:21:10 +08006536 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006537 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006538 * @hide
6539 */
6540 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006541 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006543 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006544 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545 try {
Miaoa84611c2019-03-15 09:21:10 +08006546 if (phone != null) {
6547 return phone.hasMatchedTetherApnSetting();
6548 } else {
6549 return false;
6550 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551 } finally {
6552 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006553 }
Junda Liu475951f2014-11-07 16:45:03 -08006554 }
6555
6556 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006557 * Get the user enabled state of Mobile Data.
6558 *
6559 * TODO: remove and use isUserDataEnabled.
6560 * This can't be removed now because some vendor codes
6561 * calls through ITelephony directly while they should
6562 * use TelephonyManager.
6563 *
6564 * @return true on enabled
6565 */
6566 @Override
6567 public boolean getDataEnabled(int subId) {
6568 return isUserDataEnabled(subId);
6569 }
6570
6571 /**
6572 * Get whether mobile data is enabled per user setting.
6573 *
6574 * There are other factors deciding whether mobile data is actually enabled, but they are
6575 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006576 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006577 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6578 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006579 *
6580 * @return {@code true} if data is enabled else {@code false}
6581 */
6582 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006583 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006584 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006585 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006586 try {
6587 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6588 functionName);
6589 } catch (Exception e) {
6590 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6591 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006592 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006594 mApp, subId, functionName);
6595
Robert Greenwalt646120a2014-05-23 11:54:03 -07006596 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597
6598 final long identity = Binder.clearCallingIdentity();
6599 try {
6600 int phoneId = mSubscriptionController.getPhoneId(subId);
6601 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6602 Phone phone = PhoneFactory.getPhone(phoneId);
6603 if (phone != null) {
6604 boolean retVal = phone.isUserDataEnabled();
6605 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6606 return retVal;
6607 } else {
6608 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6609 return false;
6610 }
6611 } finally {
6612 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006613 }
6614 }
6615
6616 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006617 * Checks if the device is capable of mobile data by considering whether whether the
6618 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6619 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006620 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006621 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006622 */
6623 @Override
6624 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006625 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006626 try {
6627 try {
6628 mApp.enforceCallingOrSelfPermission(
6629 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006630 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006631 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006632 try {
6633 mApp.enforceCallingOrSelfPermission(
6634 android.Manifest.permission.READ_PHONE_STATE,
6635 functionName);
6636 } catch (Exception e2) {
6637 mApp.enforceCallingOrSelfPermission(
6638 permission.READ_BASIC_PHONE_STATE, functionName);
6639 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006640 }
6641 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006642 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006644
6645 final long identity = Binder.clearCallingIdentity();
6646 try {
6647 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006648 Phone phone = PhoneFactory.getPhone(phoneId);
6649 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006650 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006651 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006652 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653 return retVal;
6654 } else {
6655 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6656 return false;
6657 }
6658 } finally {
6659 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006660 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006661 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006662
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006663 /**
6664 * Check if data is enabled for a specific reason
6665 * @param subId Subscription index
6666 * @param reason the reason the data enable change is taking place
6667 * @return {@code true} if the overall data is enabled; {@code false} if not.
6668 */
6669 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006670 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006671 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006672 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006673 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006674 try {
6675 mApp.enforceCallingOrSelfPermission(
6676 android.Manifest.permission.ACCESS_NETWORK_STATE,
6677 functionName);
6678 } catch (Exception e) {
6679 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6680 functionName);
6681 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006682 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006683 try {
6684 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006685 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006686 } catch (Exception e2) {
6687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006688 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006689 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006690 }
6691
6692
6693 final long identity = Binder.clearCallingIdentity();
6694 try {
6695 int phoneId = mSubscriptionController.getPhoneId(subId);
6696 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006697 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006698 + " reason=" + reason);
6699 }
6700 Phone phone = PhoneFactory.getPhone(phoneId);
6701 if (phone != null) {
6702 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006703 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006704 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006705 return retVal;
6706 } else {
6707 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006708 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006709 + subId + " retVal=false");
6710 }
6711 return false;
6712 }
6713 } finally {
6714 Binder.restoreCallingIdentity(identity);
6715 }
6716 }
6717
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006718 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006719 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006720 // No permission needed; this only lets the caller inspect their own status.
6721 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006722 }
Junda Liu29340342014-07-10 15:23:27 -07006723
6724 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006725 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006726 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006727 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6728 }
6729
6730 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6731 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006732 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006733 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006734 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6735 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006736 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6737 if (cpt == null) {
6738 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006739 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6740 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006741 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006742 }
6743
6744 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006745 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006746 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006747 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006748 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006749 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006750 Phone phone = getPhone(subId);
6751 if (phone == null) {
6752 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6753 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6754 }
6755 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6756 if (cpt == null) {
6757 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006758 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6759 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006760 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006761 }
6762
6763 @Override
6764 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006765 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006766 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6767 }
6768
6769 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006770 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006771 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006772 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006773 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006774 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6775 Phone phone = PhoneFactory.getPhone(phoneId);
6776 if (phone == null) {
6777 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006778 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006779 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6780 if (cpt == null) {
6781 continue;
6782 }
6783 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006784 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6785 break;
6786 }
6787 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006788 return result;
Junda Liu29340342014-07-10 15:23:27 -07006789 }
Derek Tan89e89d42014-07-08 17:00:10 -07006790
6791 @Override
Junda Liue64de782015-04-16 17:19:16 -07006792 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006793 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006794 Phone phone = PhoneFactory.getPhone(phoneId);
6795 if (phone == null) {
6796 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006797 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006798 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6799 if (cpt == null) {
6800 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006801 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006802 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006803 }
6804
Amith Yamasani6e118872016-02-19 12:53:51 -08006805 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006806 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006807 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006808 Phone phone = PhoneFactory.getPhone(phoneId);
6809 if (phone == null) {
6810 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006811 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006812 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6813 if (cpt == null) {
6814 return Collections.emptyList();
6815 }
6816 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006817 }
6818
chen xuf7e9fe82019-05-09 19:31:02 -07006819 @Override
6820 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006821 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006822 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006823 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006824 try {
6825 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6826 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6827 }
6828 } finally {
6829 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006830 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006831 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006832 }
6833
Rambo Wang6812ffb2022-03-15 16:54:17 -07006834 @Override
6835 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6836 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6837
6838 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6839 if (phone == null) {
6840 return null;
6841 }
6842 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6843 if (cpt == null) {
6844 return null;
6845 }
6846 return cpt.getCarrierServicePackageName();
6847 }
6848
Wink Savilleb564aae2014-10-23 10:18:09 -07006849 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006850 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006851 UiccPort port = phone == null ? null : phone.getUiccPort();
6852 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006853 return null;
6854 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006855 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006856 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006857 return null;
6858 }
6859 return iccId;
6860 }
6861
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006862 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006863 public void setCallComposerStatus(int subId, int status) {
6864 enforceModifyPermission();
6865
6866 final long identity = Binder.clearCallingIdentity();
6867 try {
6868 Phone phone = getPhone(subId);
6869 if (phone != null) {
6870 Phone defaultPhone = phone.getImsPhone();
6871 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6872 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6873 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006874 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6875 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006876 }
6877 }
Shuo Qian284ae752020-12-22 19:10:14 -08006878 } catch (ImsException e) {
6879 throw new ServiceSpecificException(e.getCode());
6880 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006881 Binder.restoreCallingIdentity(identity);
6882 }
6883 }
6884
6885 @Override
6886 public int getCallComposerStatus(int subId) {
6887 enforceReadPrivilegedPermission("getCallComposerStatus");
6888
6889 final long identity = Binder.clearCallingIdentity();
6890 try {
6891 Phone phone = getPhone(subId);
6892 if (phone != null) {
6893 Phone defaultPhone = phone.getImsPhone();
6894 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6895 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6896 return imsPhone.getCallComposerStatus();
6897 }
6898 }
6899 } finally {
6900 Binder.restoreCallingIdentity(identity);
6901 }
6902 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6903 }
6904
6905 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006906 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6907 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006908 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006909 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911 final long identity = Binder.clearCallingIdentity();
6912 try {
6913 final String iccId = getIccId(subId);
6914 final Phone phone = getPhone(subId);
6915 if (phone == null) {
6916 return false;
6917 }
6918 final String subscriberId = phone.getSubscriberId();
6919
6920 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006921 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006922 + subscriberId + " to " + number);
6923 }
6924
6925 if (TextUtils.isEmpty(iccId)) {
6926 return false;
6927 }
6928
6929 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6930
6931 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6932 if (alphaTag == null) {
6933 editor.remove(alphaTagPrefKey);
6934 } else {
6935 editor.putString(alphaTagPrefKey, alphaTag);
6936 }
6937
6938 // Record both the line number and IMSI for this ICCID, since we need to
6939 // track all merged IMSIs based on line number
6940 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6941 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6942 if (number == null) {
6943 editor.remove(numberPrefKey);
6944 editor.remove(subscriberPrefKey);
6945 } else {
6946 editor.putString(numberPrefKey, number);
6947 editor.putString(subscriberPrefKey, subscriberId);
6948 }
6949
6950 editor.commit();
6951 return true;
6952 } finally {
6953 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006954 }
Derek Tan7226c842014-07-02 17:42:23 -07006955 }
6956
6957 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006958 public String getLine1NumberForDisplay(int subId, String callingPackage,
6959 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006960 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006962 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006963 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006964 return null;
6965 }
Derek Tan97ebb422014-09-05 16:55:38 -07006966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 String iccId = getIccId(subId);
6970 if (iccId != null) {
6971 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6972 if (DBG_MERGE) {
6973 log("getLine1NumberForDisplay returning "
6974 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6975 }
6976 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6979 return null;
6980 } finally {
6981 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006982 }
Derek Tan7226c842014-07-02 17:42:23 -07006983 }
6984
6985 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006986 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6987 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006989 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006990 return null;
6991 }
Derek Tan97ebb422014-09-05 16:55:38 -07006992
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993 final long identity = Binder.clearCallingIdentity();
6994 try {
6995 String iccId = getIccId(subId);
6996 if (iccId != null) {
6997 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6998 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6999 }
7000 return null;
7001 } finally {
7002 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007003 }
Derek Tan7226c842014-07-02 17:42:23 -07007004 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007005
7006 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007007 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7008 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007009 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7010 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007012 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007013 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007014 return null;
7015 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007016
Jordan Liub49b04b2019-05-06 14:45:15 -07007017 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7018 // the process, where TelephonyManager was instantiated.
7019 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007020 final long identity = Binder.clearCallingIdentity();
7021 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007022 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 final TelephonyManager tele = TelephonyManager.from(context);
7024 final SubscriptionManager sub = SubscriptionManager.from(context);
7025
7026 // Figure out what subscribers are currently active
7027 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007028
Jordan Liub49b04b2019-05-06 14:45:15 -07007029 // Only consider subs which match the current subId
7030 // This logic can be simplified. See b/131189269 for progress.
7031 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007032 activeSubscriberIds.add(tele.getSubscriberId(subId));
7033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034
7035 // First pass, find a number override for an active subscriber
7036 String mergeNumber = null;
7037 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7038 for (String key : prefs.keySet()) {
7039 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7040 final String subscriberId = (String) prefs.get(key);
7041 if (activeSubscriberIds.contains(subscriberId)) {
7042 final String iccId = key.substring(
7043 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7044 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7045 mergeNumber = (String) prefs.get(numberKey);
7046 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007047 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 + " for active subscriber " + subscriberId);
7049 }
7050 if (!TextUtils.isEmpty(mergeNumber)) {
7051 break;
7052 }
7053 }
7054 }
7055 }
7056
7057 // Shortcut when no active merged subscribers
7058 if (TextUtils.isEmpty(mergeNumber)) {
7059 return null;
7060 }
7061
7062 // Second pass, find all subscribers under that line override
7063 final ArraySet<String> result = new ArraySet<>();
7064 for (String key : prefs.keySet()) {
7065 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7066 final String number = (String) prefs.get(key);
7067 if (mergeNumber.equals(number)) {
7068 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7069 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7070 final String subscriberId = (String) prefs.get(subscriberKey);
7071 if (!TextUtils.isEmpty(subscriberId)) {
7072 result.add(subscriberId);
7073 }
7074 }
7075 }
7076 }
7077
7078 final String[] resultArray = result.toArray(new String[result.size()]);
7079 Arrays.sort(resultArray);
7080 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007081 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7083 }
7084 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007085 } finally {
7086 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007087 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007088 }
7089
7090 @Override
zoey chen38003472019-12-13 17:16:31 +08007091 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7092 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007093
7094 final long identity = Binder.clearCallingIdentity();
7095 try {
7096 final TelephonyManager telephonyManager = mApp.getSystemService(
7097 TelephonyManager.class);
7098 String subscriberId = telephonyManager.getSubscriberId(subId);
7099 if (subscriberId == null) {
7100 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007101 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007102 + subId);
7103 }
7104 return null;
7105 }
7106
7107 final SubscriptionInfo info = SubscriptionController.getInstance()
7108 .getSubscriptionInfo(subId);
7109 final ParcelUuid groupUuid = info.getGroupUuid();
7110 // If it doesn't belong to any group, return just subscriberId of itself.
7111 if (groupUuid == null) {
7112 return new String[]{subscriberId};
7113 }
7114
7115 // Get all subscriberIds from the group.
7116 final List<String> mergedSubscriberIds = new ArrayList<>();
7117 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007118 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007119 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007120 for (SubscriptionInfo subInfo : groupInfos) {
7121 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7122 if (subscriberId != null) {
7123 mergedSubscriberIds.add(subscriberId);
7124 }
7125 }
7126
7127 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7128 } finally {
7129 Binder.restoreCallingIdentity(identity);
7130
7131 }
7132 }
7133
7134 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007135 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007136 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007137 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138
7139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 final Phone phone = getPhone(subId);
7142 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7143 } finally {
7144 Binder.restoreCallingIdentity(identity);
7145 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007146 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007147
7148 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007149 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007150 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7151 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007152 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7153 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154
7155 final long identity = Binder.clearCallingIdentity();
7156 try {
7157 final Phone phone = getPhone(subId);
7158 if (phone == null) {
7159 return false;
7160 }
7161 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7162 cdmaNonRoamingList);
7163 } finally {
7164 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007165 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007166 }
7167
7168 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007169 @Deprecated
7170 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7171 enforceModifyPermission();
7172
7173 int returnValue = 0;
7174 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007175 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007176 if(result.exception == null) {
7177 if (result.result != null) {
7178 byte[] responseData = (byte[])(result.result);
7179 if(responseData.length > oemResp.length) {
7180 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7181 responseData.length + "bytes. Buffer Size is " +
7182 oemResp.length + "bytes.");
7183 }
7184 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7185 returnValue = responseData.length;
7186 }
7187 } else {
7188 CommandException ex = (CommandException) result.exception;
7189 returnValue = ex.getCommandError().ordinal();
7190 if(returnValue > 0) returnValue *= -1;
7191 }
7192 } catch (RuntimeException e) {
7193 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7194 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7195 if(returnValue > 0) returnValue *= -1;
7196 }
7197
7198 return returnValue;
7199 }
7200
7201 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007202 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007203 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007204 try {
7205 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007206 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007207 mApp, phone.getSubId(), "getRadioAccessFamily");
7208 } catch (SecurityException e) {
7209 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7210 throw e;
7211 }
chen xub97461a2018-10-26 14:17:57 -07007212 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007213 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007214 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007216 final long identity = Binder.clearCallingIdentity();
7217 try {
chen xub97461a2018-10-26 14:17:57 -07007218 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007219 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007220 mApp, phone.getSubId(), "getRadioAccessFamily");
7221 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007222 } finally {
7223 Binder.restoreCallingIdentity(identity);
7224 }
chen xub97461a2018-10-26 14:17:57 -07007225 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007226 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007227
7228 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007229 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007230 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007231 try {
7232 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7233 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007234 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007235 }
7236 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007237 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007238 }
7239 RoleManager rm = mApp.getSystemService(RoleManager.class);
7240 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7241 if (!dialerRoleHolders.contains(callingPackage)) {
7242 throw new SecurityException("App must be the dialer role holder to"
7243 + " upload a call composer pic");
7244 }
7245
7246 Executors.newSingleThreadExecutor().execute(() -> {
7247 ByteArrayOutputStream output = new ByteArrayOutputStream(
7248 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7249 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7250 boolean readUntilEnd = false;
7251 int totalBytesRead = 0;
7252 byte[] buffer = new byte[16 * 1024];
7253 while (true) {
7254 int numRead;
7255 try {
7256 numRead = input.read(buffer);
7257 } catch (IOException e) {
7258 try {
7259 fd.checkError();
7260 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7261 null);
7262 } catch (IOException e1) {
7263 // This means that the other side closed explicitly with an error. If this
7264 // happens, log and ignore.
7265 loge("Remote end of call composer picture pipe closed: " + e1);
7266 }
7267 break;
7268 }
7269 if (numRead == -1) {
7270 readUntilEnd = true;
7271 break;
7272 }
7273 totalBytesRead += numRead;
7274 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7275 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7276 try {
7277 input.close();
7278 } catch (IOException e) {
7279 // ignore
7280 }
7281 break;
7282 }
7283 output.write(buffer, 0, numRead);
7284 }
7285 // Generally, the remote end will close the file descriptors. The only case where we
7286 // close is above, where the picture size is too big.
7287
7288 try {
7289 fd.checkError();
7290 } catch (IOException e) {
7291 loge("Remote end for call composer closed with an error: " + e);
7292 return;
7293 }
7294
Hall Liuaa4211e2021-01-20 15:43:39 -08007295 if (!readUntilEnd) {
7296 loge("Did not finish reading entire image; aborting");
7297 return;
7298 }
Hall Liu82694d52020-12-11 18:22:04 -08007299
Hall Liuaa4211e2021-01-20 15:43:39 -08007300 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7301 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7302 new CallComposerPictureTransfer.Factory() {},
7303 imageData,
7304 (result) -> {
7305 if (result.first != null) {
7306 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7307 Bundle outputResult = new Bundle();
7308 outputResult.putParcelable(
7309 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7310 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7311 outputResult);
7312 } else {
7313 callback.send(result.second, null);
7314 }
7315 }
7316 );
Hall Liu82694d52020-12-11 18:22:04 -08007317 });
7318 }
7319
7320 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007321 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007322 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007323 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324
7325 final long identity = Binder.clearCallingIdentity();
7326 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007327 ImsManager.getInstance(defaultPhone.getContext(),
7328 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007329 } finally {
7330 Binder.restoreCallingIdentity(identity);
7331 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007332 }
7333
7334 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007335 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007336 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7338 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007339 return false;
7340 }
Svet Ganovb320e182015-04-16 12:30:10 -07007341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007342 final long identity = Binder.clearCallingIdentity();
7343 try {
7344 // Check the user preference and the system-level IMS setting. Even if the user has
7345 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7346 // In the long run, we may instead need to check if there exists a connection service
7347 // which can support video calling.
7348 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007349 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 return imsManager.isVtEnabledByPlatform()
7351 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7352 && imsManager.isVtEnabledByUser();
7353 } finally {
7354 Binder.restoreCallingIdentity(identity);
7355 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007356 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007357
Andrew Leea1239f22015-03-02 17:44:07 -08007358 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007359 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7360 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007361 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007362 mApp, subId, callingPackage, callingFeatureId,
7363 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007364 return false;
7365 }
7366
7367 final long identity = Binder.clearCallingIdentity();
7368 try {
7369 CarrierConfigManager configManager =
7370 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007371 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7373 } finally {
7374 Binder.restoreCallingIdentity(identity);
7375 }
Andrew Leea1239f22015-03-02 17:44:07 -08007376 }
7377
7378 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007379 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007381 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 return false;
7383 }
7384
7385 final long identity = Binder.clearCallingIdentity();
7386 try {
7387 CarrierConfigManager configManager =
7388 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007389 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7391 } finally {
7392 Binder.restoreCallingIdentity(identity);
7393 }
Andrew Leea1239f22015-03-02 17:44:07 -08007394 }
7395
Andrew Lee9431b832015-03-09 18:46:45 -07007396 @Override
7397 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007398 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007399 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007400 }
7401
7402 @Override
7403 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007404 final long identity = Binder.clearCallingIdentity();
7405 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007406 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 } finally {
7408 Binder.restoreCallingIdentity(identity);
7409 }
Andrew Lee9431b832015-03-09 18:46:45 -07007410 }
7411
Hall Liuf6668912018-10-31 17:05:23 -07007412 /**
7413 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7414 * support for the feature and device firmware support.
7415 *
7416 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7417 */
7418 @Override
7419 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007421 final Phone phone = getPhone(subscriptionId);
7422 if (phone == null) {
7423 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7424 return false;
7425 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007427 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7429 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007430 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431 return isCarrierSupported && isDeviceSupported;
7432 } finally {
7433 Binder.restoreCallingIdentity(identity);
7434 }
Hall Liu98187582018-01-22 19:15:32 -08007435 }
7436
Hall Liuf6668912018-10-31 17:05:23 -07007437 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007438 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7439 * RTT setting, will return true if the device and carrier both support RTT.
7440 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007441 */
7442 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 final long identity = Binder.clearCallingIdentity();
7444 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007445 boolean isRttSupported = isRttSupported(subscriptionId);
7446 boolean isUserRttSettingOn = Settings.Secure.getInt(
7447 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7448 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7449 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7450 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 } finally {
7452 Binder.restoreCallingIdentity(identity);
7453 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007454 }
7455
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007456 @Deprecated
7457 @Override
7458 public String getDeviceId(String callingPackage) {
7459 return getDeviceIdWithFeature(callingPackage, null);
7460 }
7461
Sanket Padawe7310cc72015-01-14 09:53:20 -08007462 /**
7463 * Returns the unique device ID of phone, for example, the IMEI for
7464 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7465 *
7466 * <p>Requires Permission:
7467 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7468 */
7469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007470 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007471 try {
7472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7473 } catch (SecurityException se) {
7474 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7475 throw new SecurityException("Package " + callingPackage + " does not belong to "
7476 + Binder.getCallingUid());
7477 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007478 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007479 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007480 return null;
7481 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007482 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007483 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007484 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007485 return null;
7486 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487
7488 final long identity = Binder.clearCallingIdentity();
7489 try {
7490 return phone.getDeviceId();
7491 } finally {
7492 Binder.restoreCallingIdentity(identity);
7493 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007494 }
7495
Ping Sunc67b7c22016-03-02 19:16:45 +08007496 /**
7497 * {@hide}
7498 * Returns the IMS Registration Status on a particular subid
7499 *
7500 * @param subId
7501 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007502 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007503 Phone phone = getPhone(subId);
7504 if (phone != null) {
7505 return phone.isImsRegistered();
7506 } else {
7507 return false;
7508 }
7509 }
7510
Santos Cordon7a1885b2015-02-03 11:15:19 -08007511 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007512 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007513 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007515 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007516 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7517 }
7518 final long identity = Binder.clearCallingIdentity();
7519 try {
7520 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7521 } finally {
7522 Binder.restoreCallingIdentity(identity);
7523 }
7524 }
7525
7526 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007527 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007528 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007529 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007530 mApp,
7531 subscriptionId,
7532 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007533 final long identity = Binder.clearCallingIdentity();
7534 try {
7535 Phone phone = getPhone(subscriptionId);
7536 if (phone == null) {
7537 return null;
7538 }
7539 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7540 } finally {
7541 Binder.restoreCallingIdentity(identity);
7542 }
7543 }
7544
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007545 /**
7546 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007547 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007548 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549 final long identity = Binder.clearCallingIdentity();
7550 try {
7551 Phone phone = getPhone(subId);
7552 if (phone != null) {
7553 return phone.isWifiCallingEnabled();
7554 } else {
7555 return false;
7556 }
7557 } finally {
7558 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007559 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007560 }
7561
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007562 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007563 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007564 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007565 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 final long identity = Binder.clearCallingIdentity();
7567 try {
7568 Phone phone = getPhone(subId);
7569 if (phone != null) {
7570 return phone.isVideoEnabled();
7571 } else {
7572 return false;
7573 }
7574 } finally {
7575 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007576 }
7577 }
7578
7579 /**
7580 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7581 * defined in {@link ImsRegistrationImplBase}.
7582 */
7583 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007584 final long identity = Binder.clearCallingIdentity();
7585 try {
7586 Phone phone = getPhone(subId);
7587 if (phone != null) {
7588 return phone.getImsRegistrationTech();
7589 } else {
7590 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7591 }
7592 } finally {
7593 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007594 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007595 }
7596
Stuart Scott8eef64f2015-04-08 15:13:54 -07007597 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007598 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007599 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007600 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7601 return;
7602 }
Kai Shif70f46f2021-03-03 13:59:46 -08007603 Phone defaultPhone = getDefaultPhone();
7604 if (defaultPhone != null) {
7605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7606 mApp, getDefaultPhone().getSubId(), "factoryReset");
7607 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007608 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007609
Svet Ganovcc087f82015-05-12 20:35:54 -07007610 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007611 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7612 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007613 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007614 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007615 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007616 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007617 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007618 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007619 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007620 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007621 // There has been issues when Sms raw table somehow stores orphan
7622 // fragments. They lead to garbled message when new fragments come
7623 // in and combined with those stale ones. In case this happens again,
7624 // user can reset all network settings which will clean up this table.
7625 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007626 // Clean up IMS settings as well here.
7627 int slotId = getSlotIndex(subId);
7628 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7629 ImsManager.getInstance(mApp, slotId).factoryReset();
7630 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007631
Kai Shif70f46f2021-03-03 13:59:46 -08007632 if (defaultPhone == null) {
7633 return;
7634 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007635 // Erase modem config if erase modem on network setting is enabled.
7636 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7637 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7638 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007639 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007640 }
Kai Shif70f46f2021-03-03 13:59:46 -08007641
7642 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007643 } finally {
7644 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007645 }
7646 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007647
SongFerngWangfd89b102021-05-27 22:44:54 +08007648 @VisibleForTesting
7649 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7650 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7651 return;
7652 }
7653 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7654 RILConstants.PREFERRED_NETWORK_MODE);
7655 SubscriptionManager.setSubscriptionProperty(subId,
7656 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7657 "user=" + defaultNetworkType);
7658 phone.loadAllowedNetworksFromSubscriptionDatabase();
7659 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7660 defaultNetworkType, null);
7661 }
7662
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007663 private void cleanUpSmsRawTable(Context context) {
7664 ContentResolver resolver = context.getContentResolver();
7665 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7666 resolver.delete(uri, null, null);
7667 }
7668
Narayan Kamath1c496c22015-04-16 14:40:19 +01007669 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007670 public String getSimLocaleForSubscriber(int subId) {
7671 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7672 final Phone phone = getPhone(subId);
7673 if (phone == null) {
7674 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007675 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677 final long identity = Binder.clearCallingIdentity();
7678 try {
chen xu5d3637b2019-01-21 23:31:38 -08007679 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007680 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007681 if (info == null) {
7682 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7683 return null;
7684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 // Try and fetch the locale from the carrier properties or from the SIM language
7686 // preferences (EF-PL and EF-LI)...
7687 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007689 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7690 if (localeFromDefaultSim != null) {
7691 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7692 if (DBG) log("Using locale from subId: " + subId + " locale: "
7693 + localeFromDefaultSim);
7694 return localeFromDefaultSim.toLanguageTag();
7695 } else {
7696 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007697 }
7698 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700 // The SIM language preferences only store a language (e.g. fr = French), not an
7701 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7702 // the SIM and carrier preferences does not include a country we add the country
7703 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007704 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007705 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007706 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007707 return mccLocale.toLanguageTag();
7708 }
7709
7710 if (DBG) log("No locale found - returning null");
7711 return null;
7712 } finally {
7713 Binder.restoreCallingIdentity(identity);
7714 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007715 }
7716
7717 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007718 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007719 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007720 }
7721
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 /**
7723 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7724 */
7725 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007726 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007727 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007728 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007729
Gary Jian3aa9a762022-01-24 16:41:19 +08007730 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7731 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007732
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007733 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007734 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7735 * representing the state of the modem.
7736 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007737 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7738 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007739 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007740 */
7741 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007742 public void requestModemActivityInfo(ResultReceiver result) {
7743 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007744 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745
7746 final long identity = Binder.clearCallingIdentity();
7747 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007748 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007749 } finally {
7750 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007751 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007752 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007753
Siddharth Rayb8114062018-06-17 15:02:38 -07007754 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7755 // less than total activity duration.
7756 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7757 if (info == null) {
7758 return false;
7759 }
7760 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007761 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7762 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7763
Siddharth Rayb8114062018-06-17 15:02:38 -07007764 return (info.isValid()
7765 && (info.getSleepTimeMillis() <= activityDurationMs)
7766 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007767 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007768 && (totalTxTimeMs <= activityDurationMs));
7769 }
7770
Gary Jian3aa9a762022-01-24 16:41:19 +08007771 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7772 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7773 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7774 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7775
7776 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7777 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7778 }
7779
7780 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7781 mLastModemActivityInfo.setReceiveTimeMillis(
7782 rat,
7783 freq,
7784 info.getReceiveTimeMillis(rat, freq)
7785 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7786 }
7787
7788 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7789 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7790 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7791 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7792
7793 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7794 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7795 }
7796 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7797 mLastModemActivityInfo.setReceiveTimeMillis(
7798 rat,
7799 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7800 }
7801
7802 /**
7803 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7804 * @param info recent ModemActivityInfo
7805 */
7806 private void mergeModemActivityInfo(ModemActivityInfo info) {
7807 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7808 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7809 boolean matched;
7810 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7811 matched = false;
7812 int rat = info.getSpecificInfoRat(i);
7813 int freq = info.getSpecificInfoFrequencyRange(i);
7814 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7815 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7816 //if it already exists
7817 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7818 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7819 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7820 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7821 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7822 updateLastModemActivityInfo(info, rat, freq);
7823 matched = true;
7824 }
7825 } else {
7826 updateLastModemActivityInfo(info, rat);
7827 matched = true;
7828 }
7829 }
7830 }
7831
7832 if (!matched) {
7833 mDeltaSpecificInfo =
7834 new ActivityStatsTechSpecificInfo(
7835 rat,
7836 freq,
7837 info.getTransmitTimeMillis(rat, freq),
7838 (int) info.getReceiveTimeMillis(rat, freq));
7839 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7840 }
7841 }
7842 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7843 mLastModemActivitySpecificInfo =
7844 new ActivityStatsTechSpecificInfo[merged.size()];
7845 merged.toArray(mLastModemActivitySpecificInfo);
7846
7847 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7848 mLastModemActivityInfo.setSleepTimeMillis(
7849 info.getSleepTimeMillis()
7850 + mLastModemActivityInfo.getSleepTimeMillis());
7851 mLastModemActivityInfo.setIdleTimeMillis(
7852 info.getIdleTimeMillis()
7853 + mLastModemActivityInfo.getIdleTimeMillis());
7854 }
7855
Jack Yu85bd38a2015-11-09 11:34:32 -08007856 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007857 * Returns the service state information on specified subscription.
7858 */
7859 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007860 public ServiceState getServiceStateForSubscriber(int subId,
7861 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7862 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007863 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007864 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007865 return null;
7866 }
7867
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007868 boolean hasFinePermission = false;
7869 boolean hasCoarsePermission = false;
7870 if (!renounceFineLocationAccess) {
7871 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7872 LocationAccessPolicy.checkLocationPermission(mApp,
7873 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7874 .setCallingPackage(callingPackage)
7875 .setCallingFeatureId(callingFeatureId)
7876 .setCallingPid(Binder.getCallingPid())
7877 .setCallingUid(Binder.getCallingUid())
7878 .setMethod("getServiceStateForSubscriber")
7879 .setLogAsInfo(true)
7880 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7881 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7882 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7883 .build());
7884 hasFinePermission =
7885 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7886 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007887
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007888 if (!renounceCoarseLocationAccess) {
7889 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7890 LocationAccessPolicy.checkLocationPermission(mApp,
7891 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7892 .setCallingPackage(callingPackage)
7893 .setCallingFeatureId(callingFeatureId)
7894 .setCallingPid(Binder.getCallingPid())
7895 .setCallingUid(Binder.getCallingUid())
7896 .setMethod("getServiceStateForSubscriber")
7897 .setLogAsInfo(true)
7898 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7899 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7900 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7901 .build());
7902 hasCoarsePermission =
7903 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7904 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007905
Jack Yu479f40e2020-10-27 21:29:25 -07007906 final Phone phone = getPhone(subId);
7907 if (phone == null) {
7908 return null;
7909 }
7910
Jordan Liu0f2bc442020-11-18 16:47:37 -08007911 final long identity = Binder.clearCallingIdentity();
7912
Jack Yu479f40e2020-10-27 21:29:25 -07007913 boolean isCallingPackageDataService = phone.getDataServicePackages()
7914 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007916 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7917 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7918 Rlog.d(LOG_TAG,
7919 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7920 return null;
7921 }
7922
Hall Liuf19c44f2018-11-27 14:38:17 -08007923 ServiceState ss = phone.getServiceState();
7924
7925 // Scrub out the location info in ServiceState depending on what level of access
7926 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007927 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007928 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7929 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930 } finally {
7931 Binder.restoreCallingIdentity(identity);
7932 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007933 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007934
7935 /**
7936 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7937 *
7938 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7939 * voicemail ringtone.
7940 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7941 * PhoneAccount.
7942 */
7943 @Override
7944 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007945 final long identity = Binder.clearCallingIdentity();
7946 try {
7947 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7948 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007949 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007950 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7953 } finally {
7954 Binder.restoreCallingIdentity(identity);
7955 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007956 }
7957
7958 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007959 * Sets the per-account voicemail ringtone.
7960 *
7961 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7962 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7963 *
7964 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7965 * voicemail ringtone.
7966 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7967 * PhoneAccount.
7968 */
7969 @Override
7970 public void setVoicemailRingtoneUri(String callingPackage,
7971 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007972 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007974 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7975 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7977 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7978 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007979 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007980
7981 final long identity = Binder.clearCallingIdentity();
7982 try {
7983 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7984 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007985 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007986 }
7987 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7988 } finally {
7989 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007990 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007991 }
7992
7993 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007994 * Returns whether vibration is set for voicemail notification in Phone settings.
7995 *
7996 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7997 * voicemail vibration setting.
7998 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7999 */
8000 @Override
8001 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008002 final long identity = Binder.clearCallingIdentity();
8003 try {
8004 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8005 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008006 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008007 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8010 } finally {
8011 Binder.restoreCallingIdentity(identity);
8012 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008013 }
8014
Youhan Wange64578a2016-05-02 15:32:42 -07008015 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008016 * Sets the per-account voicemail vibration.
8017 *
8018 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8019 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8020 *
8021 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8022 * voicemail vibration setting.
8023 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8024 * specific PhoneAccount.
8025 */
8026 @Override
8027 public void setVoicemailVibrationEnabled(String callingPackage,
8028 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008029 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008031 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8032 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8034 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8035 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008036 }
8037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038 final long identity = Binder.clearCallingIdentity();
8039 try {
8040 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8041 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008042 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008043 }
8044 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8045 } finally {
8046 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008047 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008048 }
8049
8050 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008051 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8052 *
8053 * @throws SecurityException if the caller does not have the required permission
8054 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008055 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008056 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008057 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008058 }
8059
8060 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008061 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8062 * permission.
8063 *
8064 * @throws SecurityException if the caller does not have the required permission
8065 */
8066 private void enforceSendSmsPermission() {
8067 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8068 }
8069
8070 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008071 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008072 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008073 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008074 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008075 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076 final long identity = Binder.clearCallingIdentity();
8077 try {
8078 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008079 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008080 if (componentName == null) {
8081 throw new SecurityException(
8082 "Caller not current active visual voicemail package[null]");
8083 }
8084 String vvmPackage = componentName.getPackageName();
8085 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008086 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087 }
8088 } finally {
8089 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008090 }
8091 }
8092
8093 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008094 * Return the application ID for the app type.
8095 *
8096 * @param subId the subscription ID that this request applies to.
8097 * @param appType the uicc app type.
8098 * @return Application ID for specificied app type, or null if no uicc.
8099 */
8100 @Override
8101 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008102 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008103 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104
8105 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008106 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008107 if (phone == null) {
8108 return null;
8109 }
8110 String aid = null;
8111 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008112 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113 .getApplicationByType(appType).getAid();
8114 } catch (Exception e) {
8115 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8116 }
8117 return aid;
8118 } finally {
8119 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008120 }
Youhan Wange64578a2016-05-02 15:32:42 -07008121 }
8122
Youhan Wang4001d252016-05-11 10:29:41 -07008123 /**
8124 * Return the Electronic Serial Number.
8125 *
8126 * @param subId the subscription ID that this request applies to.
8127 * @return ESN or null if error.
8128 */
8129 @Override
8130 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008131 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008132 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133
8134 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008135 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008136 if (phone == null) {
8137 return null;
8138 }
8139 String esn = null;
8140 try {
8141 esn = phone.getEsn();
8142 } catch (Exception e) {
8143 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8144 }
8145 return esn;
8146 } finally {
8147 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008148 }
Youhan Wang4001d252016-05-11 10:29:41 -07008149 }
8150
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008151 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008152 * Return the Preferred Roaming List Version.
8153 *
8154 * @param subId the subscription ID that this request applies to.
8155 * @return PRLVersion or null if error.
8156 */
8157 @Override
8158 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008159 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008160 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161
8162 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008163 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008164 if (phone == null) {
8165 return null;
8166 }
8167 String cdmaPrlVersion = null;
8168 try {
8169 cdmaPrlVersion = phone.getCdmaPrlVersion();
8170 } catch (Exception e) {
8171 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8172 }
8173 return cdmaPrlVersion;
8174 } finally {
8175 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008176 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008177 }
8178
8179 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008180 * Get snapshot of Telephony histograms
8181 * @return List of Telephony histograms
8182 * @hide
8183 */
8184 @Override
8185 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8187 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008188
8189 final long identity = Binder.clearCallingIdentity();
8190 try {
8191 return RIL.getTelephonyRILTimingHistograms();
8192 } finally {
8193 Binder.restoreCallingIdentity(identity);
8194 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008195 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008196
8197 /**
8198 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008199 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8200 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008201 * Require system privileges. In the future we may add this to carrier APIs.
8202 *
Michele Berionne482f8202018-11-27 18:57:59 -08008203 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008204 */
8205 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008206 @TelephonyManager.SetCarrierRestrictionResult
8207 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008208 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008209 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008210
Michele Berionne482f8202018-11-27 18:57:59 -08008211 if (carrierRestrictionRules == null) {
8212 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008213 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008215 final long identity = Binder.clearCallingIdentity();
8216 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008217 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008218 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008219 } finally {
8220 Binder.restoreCallingIdentity(identity);
8221 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008222 }
8223
8224 /**
8225 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008226 * Get the allowed carrier list and the excluded carrier list, including the priority between
8227 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008228 * Require system privileges. In the future we may add this to carrier APIs.
8229 *
Michele Berionne482f8202018-11-27 18:57:59 -08008230 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008231 */
8232 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008233 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008234 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008235 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236
8237 final long identity = Binder.clearCallingIdentity();
8238 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008239 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8240 if (response instanceof CarrierRestrictionRules) {
8241 return (CarrierRestrictionRules) response;
8242 }
8243 // Response is an Exception of some kind,
8244 // which is signalled to the user as a NULL retval
8245 return null;
8246 } catch (Exception e) {
8247 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8248 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 } finally {
8250 Binder.restoreCallingIdentity(identity);
8251 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008252 }
8253
fionaxu59545b42016-05-25 15:53:37 -07008254 /**
fionaxu59545b42016-05-25 15:53:37 -07008255 * Action set from carrier signalling broadcast receivers to enable/disable radio
8256 * @param subId the subscription ID that this action applies to.
8257 * @param enabled control enable or disable radio.
8258 * {@hide}
8259 */
8260 @Override
8261 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8262 enforceModifyPermission();
8263 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008264
8265 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008266 if (phone == null) {
8267 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8268 return;
8269 }
8270 try {
8271 phone.carrierActionSetRadioEnabled(enabled);
8272 } catch (Exception e) {
8273 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274 } finally {
8275 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008276 }
8277 }
8278
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008279 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008280 * Enable or disable Voice over NR (VoNR)
8281 * @param subId the subscription ID that this action applies to.
8282 * @param enabled enable or disable VoNR.
8283 * @return operation result.
8284 */
8285 @Override
8286 public int setVoNrEnabled(int subId, boolean enabled) {
8287 enforceModifyPermission();
8288 final Phone phone = getPhone(subId);
8289
8290 final long identity = Binder.clearCallingIdentity();
8291 if (phone == null) {
8292 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8293 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8294 }
8295
8296 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8297 try {
8298 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8299 workSource);
8300 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008301
8302 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8303 if (DBG) {
8304 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8305 }
8306 SubscriptionManager.setSubscriptionProperty(
8307 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8308 (enabled ? "1" : "0"));
8309 }
8310
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008311 return result;
8312 } finally {
8313 Binder.restoreCallingIdentity(identity);
8314 }
8315 }
8316
8317 /**
8318 * Is voice over NR enabled
8319 * @return true if VoNR is enabled else false
8320 */
8321 @Override
8322 public boolean isVoNrEnabled(int subId) {
8323 enforceReadPrivilegedPermission("isVoNrEnabled");
8324 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8325 final long identity = Binder.clearCallingIdentity();
8326 try {
8327 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8328 null, subId, workSource);
8329 if (DBG) log("isVoNrEnabled: " + isEnabled);
8330 return isEnabled;
8331 } finally {
8332 Binder.restoreCallingIdentity(identity);
8333 }
8334 }
8335
8336 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008337 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8338 * network status based on which carrier apps could apply actions accordingly,
8339 * enable/disable default url handler for example.
8340 *
8341 * @param subId the subscription ID that this action applies to.
8342 * @param report control start/stop reporting the default network status.
8343 * {@hide}
8344 */
8345 @Override
8346 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8347 enforceModifyPermission();
8348 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008349
8350 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008351 if (phone == null) {
8352 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8353 return;
8354 }
8355 try {
8356 phone.carrierActionReportDefaultNetworkStatus(report);
8357 } catch (Exception e) {
8358 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008359 } finally {
8360 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008361 }
8362 }
8363
8364 /**
fionaxud9622282017-07-17 17:51:30 -07008365 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8366 * @param subId the subscription ID that this action applies to.
8367 * {@hide}
8368 */
8369 @Override
8370 public void carrierActionResetAll(int subId) {
8371 enforceModifyPermission();
8372 final Phone phone = getPhone(subId);
8373 if (phone == null) {
8374 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8375 return;
8376 }
8377 try {
8378 phone.carrierActionResetAll();
8379 } catch (Exception e) {
8380 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8381 }
8382 }
8383
8384 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008385 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8386 * bug report is being generated.
8387 */
8388 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008389 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008390 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8391 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008392 writer.println("Permission Denial: can't dump Phone from pid="
8393 + Binder.getCallingPid()
8394 + ", uid=" + Binder.getCallingUid()
8395 + "without permission "
8396 + android.Manifest.permission.DUMP);
8397 return;
8398 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008399 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008400 }
Jack Yueb89b242016-06-22 13:27:47 -07008401
Brad Ebingerdac2f002018-04-03 15:17:52 -07008402 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008403 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8404 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8405 @NonNull String[] args) {
8406 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8407 this, in.getFileDescriptor(), out.getFileDescriptor(),
8408 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008409 }
8410
Jack Yueb89b242016-06-22 13:27:47 -07008411 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008412 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008413 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008414 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008415 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008416 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008417 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008418 */
8419 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008420 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008421 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008422 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8423 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8424 try {
8425 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008426 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008427 } catch (SecurityException se) {
8428 enforceModifyPermission();
8429 }
8430 } else {
8431 enforceModifyPermission();
8432 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008433
8434 final long identity = Binder.clearCallingIdentity();
8435 try {
8436 Phone phone = getPhone(subId);
8437 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008438 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8439 phone.carrierActionSetMeteredApnsEnabled(enabled);
8440 } else {
Jack Yuabb10902022-07-31 00:43:21 -07008441 phone.getDataSettingsManager().setDataEnabled(
8442 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008444 }
8445 } finally {
8446 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008447 }
8448 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008449
8450 /**
8451 * Get Client request stats
8452 * @return List of Client Request Stats
8453 * @hide
8454 */
8455 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008456 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8457 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008459 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008460 return null;
8461 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008462 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008464 final long identity = Binder.clearCallingIdentity();
8465 try {
8466 if (phone != null) {
8467 return phone.getClientRequestStats();
8468 }
8469
8470 return null;
8471 } finally {
8472 Binder.restoreCallingIdentity(identity);
8473 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008474 }
8475
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008476 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008477 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008478 if (uid == Process.ROOT_UID && packageName == null) {
8479 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8480 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8481 // exception. ROOT_UID seems not to have a valid package name returned by
8482 // PackageManager, so just fake it here to avoid issues when running telephony shell
8483 // commands that plumb through the RIL as root, like so:
8484 // $ adb root
8485 // $ adb shell cmd phone ...
8486 packageName = "root";
8487 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008488 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008489 }
Jack Yueb4124c2017-02-16 15:32:43 -08008490
8491 /**
Grace Chen70990072017-03-24 17:21:30 -07008492 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008493 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008494 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008495 * @param state State of SIM (power down, power up, pass through)
8496 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8497 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8498 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008499 *
8500 **/
8501 @Override
Grace Chen70990072017-03-24 17:21:30 -07008502 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008503 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008504 Phone phone = PhoneFactory.getPhone(slotIndex);
8505
vagdeviaf9a5b92018-08-15 16:01:53 -07008506 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008508 final long identity = Binder.clearCallingIdentity();
8509 try {
8510 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008511 phone.setSimPowerState(state, null, workSource);
8512 }
8513 } finally {
8514 Binder.restoreCallingIdentity(identity);
8515 }
8516 }
8517
8518 /**
8519 * Set SIM card power state.
8520 *
8521 * @param slotIndex SIM slot id.
8522 * @param state State of SIM (power down, power up, pass through)
8523 * @param callback callback to trigger after success or failure
8524 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8525 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8526 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8527 *
8528 **/
8529 @Override
8530 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8531 IIntegerConsumer callback) {
8532 enforceModifyPermission();
8533 Phone phone = PhoneFactory.getPhone(slotIndex);
8534
8535 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8536
8537 final long identity = Binder.clearCallingIdentity();
8538 try {
8539 if (phone != null) {
8540 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8541 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008542 }
8543 } finally {
8544 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008545 }
8546 }
Shuo Qiandd210312017-04-12 22:11:33 +00008547
Tyler Gunn65d45c22017-06-05 11:22:26 -07008548 private boolean isUssdApiAllowed(int subId) {
8549 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008550 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008551 if (configManager == null) {
8552 return false;
8553 }
8554 PersistableBundle pb = configManager.getConfigForSubId(subId);
8555 if (pb == null) {
8556 return false;
8557 }
8558 return pb.getBoolean(
8559 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8560 }
8561
Shuo Qiandd210312017-04-12 22:11:33 +00008562 /**
8563 * Check if phone is in emergency callback mode
8564 * @return true if phone is in emergency callback mode
8565 * @param subId sub id
8566 */
goneil9c5f4872017-12-05 14:07:56 -08008567 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008568 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008569 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008570 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571
8572 final long identity = Binder.clearCallingIdentity();
8573 try {
8574 if (phone != null) {
8575 return phone.isInEcm();
8576 } else {
8577 return false;
8578 }
8579 } finally {
8580 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008581 }
8582 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008583
8584 /**
8585 * Get the current signal strength information for the given subscription.
8586 * Because this information is not updated when the device is in a low power state
8587 * it should not be relied-upon to be current.
8588 * @param subId Subscription index
8589 * @return the most recent cached signal strength info from the modem
8590 */
8591 @Override
8592 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008593 final long identity = Binder.clearCallingIdentity();
8594 try {
8595 Phone p = getPhone(subId);
8596 if (p == null) {
8597 return null;
8598 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008600 return p.getSignalStrength();
8601 } finally {
8602 Binder.restoreCallingIdentity(identity);
8603 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008604 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008605
Pengquan Meng77b7f132018-08-22 14:49:57 -07008606 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008607 * Get the current modem radio state for the given slot.
8608 * @param slotIndex slot index.
8609 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008610 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008611 * @return the current radio power state from the modem
8612 */
8613 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008614 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008615 Phone phone = PhoneFactory.getPhone(slotIndex);
8616 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8618 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008619 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8620 }
8621
8622 final long identity = Binder.clearCallingIdentity();
8623 try {
8624 return phone.getRadioPowerState();
8625 } finally {
8626 Binder.restoreCallingIdentity(identity);
8627 }
8628 }
8629 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8630 }
8631
8632 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008633 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8634 *
8635 * <p>Requires one of the following permissions:
8636 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008637 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008638 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8639 * privileges.
8640 *
8641 * @param subId subscription id
8642 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8643 * {@code false}.
8644 */
8645 @Override
8646 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008647 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008648 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008649 try {
8650 mApp.enforceCallingOrSelfPermission(
8651 android.Manifest.permission.ACCESS_NETWORK_STATE,
8652 functionName);
8653 } catch (Exception e) {
8654 mApp.enforceCallingOrSelfPermission(
8655 permission.READ_BASIC_PHONE_STATE, functionName);
8656 }
Shuo Qian093013d2020-08-13 15:42:55 -07008657 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008658 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008659 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008660 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008661
Pengquan Menga1bb6272018-09-06 09:59:22 -07008662 boolean isEnabled = false;
8663 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008664 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008665 Phone phone = getPhone(subId);
8666 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008667 } finally {
8668 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008669 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008670 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008671 }
8672
8673
8674 /**
8675 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8676 *
8677 * <p> Requires permission:
8678 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8679 * privileges.
8680 *
8681 * @param subId subscription id
8682 * @param isEnabled {@code true} means enable, {@code false} means disable.
8683 */
8684 @Override
8685 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8687 mApp, subId, "setDataRoamingEnabled");
8688
Pengquan Menga1bb6272018-09-06 09:59:22 -07008689 final long identity = Binder.clearCallingIdentity();
8690 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008691 Phone phone = getPhone(subId);
8692 if (phone != null) {
8693 phone.setDataRoamingEnabled(isEnabled);
8694 }
8695 } finally {
8696 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008697 }
8698 }
8699
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008700 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008701 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008702 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008703 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008704 mApp, subId, "isManualNetworkSelectionAllowed");
8705
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008706 boolean isAllowed = true;
8707 final long identity = Binder.clearCallingIdentity();
8708 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008709 Phone phone = getPhone(subId);
8710 if (phone != null) {
8711 isAllowed = phone.isCspPlmnEnabled();
8712 }
8713 } finally {
8714 Binder.restoreCallingIdentity(identity);
8715 }
8716 return isAllowed;
8717 }
8718
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008719 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8720 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008721 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008722 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008723 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008724 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8725 if (phone == null) {
8726 return false;
8727 }
8728 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8729 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8730 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008731 }
8732
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008733 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008734 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008735 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008736 mApp.getSystemService(AppOpsManager.class)
8737 .checkPackage(Binder.getCallingUid(), callingPackage);
8738
Jordan Liu1e142fc2019-04-22 15:10:43 -07008739 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008740 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008741 try {
8742 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008743 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008744 } catch (SecurityException e) {
8745 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8746 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008747 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008748 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008749 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008750 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008751 }
sandeepjsb6c87872021-09-27 15:34:44 +00008752 // checking compatibility, if calling app's target SDK is T and beyond.
8753 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8754 Binder.getCallingUid())) {
8755 isIccIdAccessRestricted = true;
8756 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008757 final long identity = Binder.clearCallingIdentity();
8758 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008759 UiccController uiccController = UiccController.getInstance();
8760 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008761 if (hasReadPermission) {
8762 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008763 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008764
8765 // Remove private info if the caller doesn't have access
8766 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8767 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008768 //setting the value after compatibility check
8769 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008770 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8771 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008772 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008773 if (card == null) {
8774 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008775 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008776 continue;
8777 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008778 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8779 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008780 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008781 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008782 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008783 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8784 for (UiccPortInfo portInfo : portInfos) {
8785 UiccPort port = uiccController.getUiccPortForSlot(
8786 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8787 if (port == null) {
8788 // assume no access if port is null
8789 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8790 continue;
8791 }
8792 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8793 uiccPortInfos.add(portInfo);
8794 } else {
8795 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8796 }
8797 }
8798 filteredInfos.add(new UiccCardInfo(
8799 cardInfo.isEuicc(),
8800 cardInfo.getCardId(),
8801 null,
8802 cardInfo.getPhysicalSlotIndex(),
8803 cardInfo.isRemovable(),
8804 cardInfo.isMultipleEnabledProfilesSupported(),
8805 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008806 }
8807 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008808 } finally {
8809 Binder.restoreCallingIdentity(identity);
8810 }
8811 }
8812
sandeepjsb6c87872021-09-27 15:34:44 +00008813 /**
8814 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8815 * generally private and require carrier privileges to view.
8816 *
8817 * @hide
8818 */
8819 @NonNull
8820 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8821 List<UiccPortInfo> portinfo = new ArrayList<>();
8822 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8823 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8824 }
8825 return new UiccCardInfo(
8826 cardInfo.isEuicc(),
8827 cardInfo.getCardId(),
8828 null,
8829 cardInfo.getPhysicalSlotIndex(),
8830 cardInfo.isRemovable(),
8831 cardInfo.isMultipleEnabledProfilesSupported(),
8832 portinfo
8833 );
8834 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008835
sandeepjsb6c87872021-09-27 15:34:44 +00008836 /**
8837 * @hide
8838 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8839 * These values are generally private and require carrier privileges to view.
8840 */
8841 @NonNull
8842 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8843 return new UiccPortInfo(
8844 UiccPortInfo.ICCID_REDACTED,
8845 portInfo.getPortIndex(),
8846 portInfo.getLogicalSlotIndex(),
8847 portInfo.isActive()
8848 );
8849 }
8850 @Override
8851 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008852 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008853 mApp.getSystemService(AppOpsManager.class)
8854 .checkPackage(Binder.getCallingUid(), callingPackage);
8855
sandeepjsb6c87872021-09-27 15:34:44 +00008856 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008857
Aman Guptaf3c90b32022-03-17 04:54:16 +00008858 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8859 // we are reading iccId which is PII data.
8860 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008861
8862 // checking compatibility, if calling app's target SDK is T and beyond.
8863 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8864 Binder.getCallingUid())) {
8865 isLogicalSlotAccessRestricted = true;
8866 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008867 final long identity = Binder.clearCallingIdentity();
8868 try {
8869 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008870 if (slots == null || slots.length == 0) {
8871 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008872 return null;
8873 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008874 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8875 for (int i = 0; i < slots.length; i++) {
8876 UiccSlot slot = slots[i];
8877 if (slot == null) {
8878 continue;
8879 }
8880
Jordan Liu7be7e652019-05-06 18:55:02 +00008881 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008882 UiccCard card = slot.getUiccCard();
8883 if (card != null) {
8884 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008885 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008886 cardId = slot.getEid();
8887 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008888 // If cardId is null, use iccId of default port as cardId.
8889 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008891 }
8892
Jordan Liu857451f2019-05-09 16:35:35 -07008893 if (cardId != null) {
8894 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8895 // if cardId is an EID, it's all digits so this is fine
8896 cardId = IccUtils.stripTrailingFs(cardId);
8897 }
8898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008899 int cardState = 0;
8900 switch (slot.getCardState()) {
8901 case CARDSTATE_ABSENT:
8902 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8903 break;
8904 case CARDSTATE_PRESENT:
8905 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8906 break;
8907 case CARDSTATE_ERROR:
8908 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8909 break;
8910 case CARDSTATE_RESTRICTED:
8911 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8912 break;
8913 default:
8914 break;
8915
8916 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008917 List<UiccPortInfo> portInfos = new ArrayList<>();
8918 int[] portIndexes = slot.getPortList();
8919 for (int portIdx : portIndexes) {
8920 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00008921 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008922 portInfos.add(new UiccPortInfo(iccId, portIdx,
8923 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008925 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008926 slot.isEuicc(),
8927 cardId,
8928 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008929 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008930 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008931 //setting the value after compatibility check
8932 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008933 }
8934 return infos;
8935 } finally {
8936 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008937 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008938 }
8939
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008940 /* Returns null if doesn't have read permission or carrier privilege access. */
8941 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8942 boolean hasReadPermission) {
8943 String iccId = slot.getIccId(portIndex);
8944 if (hasReadPermission) { // if has read permission
8945 return iccId;
8946 } else {
8947 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8948 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8949 // if no read permission, checking carrier privilege access
8950 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8951 return iccId;
8952 }
8953 }
8954 }
8955 // No read permission or carrier privilege access.
8956 return UiccPortInfo.ICCID_REDACTED;
8957 }
8958
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008959 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008960 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008961 public boolean switchSlots(int[] physicalSlots) {
8962 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008963
8964 final long identity = Binder.clearCallingIdentity();
8965 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008966 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8967 for (int i = 0; i < physicalSlots.length; i++) {
8968 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8969 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8970 physicalSlots[i], i));
8971 }
8972 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008973 } finally {
8974 Binder.restoreCallingIdentity(identity);
8975 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008976 }
Jack Yu4c988042018-02-27 15:30:01 -08008977
8978 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008979 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8980 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8981 enforceModifyPermission();
8982
8983 final long identity = Binder.clearCallingIdentity();
8984 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008985 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00008986 } finally {
8987 Binder.restoreCallingIdentity(identity);
8988 }
8989 }
8990
8991 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008992 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008993 final long identity = Binder.clearCallingIdentity();
8994 try {
8995 return UiccController.getInstance().getCardIdForDefaultEuicc();
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
8999 }
9000
Pengquan Meng85728fb2018-03-12 16:31:21 -07009001 /**
goneil47ffb6e2018-04-06 15:40:58 -07009002 * A test API to reload the UICC profile.
9003 *
9004 * <p>Requires that the calling app has permission
9005 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9006 * @hide
9007 */
9008 @Override
9009 public void refreshUiccProfile(int subId) {
9010 enforceModifyPermission();
9011
9012 final long identity = Binder.clearCallingIdentity();
9013 try {
9014 Phone phone = getPhone(subId);
9015 if (phone == null) {
9016 return;
9017 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009018 UiccPort uiccPort = phone.getUiccPort();
9019 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009020 return;
9021 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009022 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009023 if (uiccProfile == null) {
9024 return;
9025 }
9026 uiccProfile.refresh();
9027 } finally {
9028 Binder.restoreCallingIdentity(identity);
9029 }
9030 }
9031
9032 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009033 * Returns false if the mobile data is disabled by default, otherwise return true.
9034 */
9035 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009036 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009037 }
9038
9039 /**
9040 * Returns true if the data roaming is enabled by default, i.e the system property
9041 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9042 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9043 */
9044 private boolean getDefaultDataRoamingEnabled(int subId) {
9045 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009046 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009047 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009048 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9049 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9050 return isDataRoamingEnabled;
9051 }
9052
9053 /**
9054 * Returns the default network type for the given {@code subId}, if the default network type is
9055 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9056 */
9057 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009058 List<Integer> list = TelephonyProperties.default_network();
9059 int phoneId = mSubscriptionController.getPhoneId(subId);
9060 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9061 return list.get(phoneId);
9062 }
9063 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009064 }
fionaxua13278b2018-03-21 00:08:13 -07009065
9066 @Override
9067 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009068 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009069 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009070
9071 final long identity = Binder.clearCallingIdentity();
9072 try {
9073 final Phone phone = getPhone(subId);
9074 if (phone == null) {
9075 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9076 return;
9077 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009078 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9079 if (cpt != null) {
9080 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9081 }
9082 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009083 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9084 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009085 if (carrierPrivilegeRules == null) {
9086 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9087 } else {
9088 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9089 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009090 } finally {
9091 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009092 }
fionaxua13278b2018-03-21 00:08:13 -07009093 }
9094
9095 @Override
9096 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009097 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009098
9099 final long identity = Binder.clearCallingIdentity();
9100 try {
9101 final Phone phone = getPhone(subId);
9102 if (phone == null) {
9103 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9104 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9105 }
9106 return phone.getCarrierIdListVersion();
9107 } finally {
9108 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009109 }
fionaxua13278b2018-03-21 00:08:13 -07009110 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009111
9112 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009113 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9114 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009115 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009116 mApp, subId, callingPackage, callingFeatureId,
9117 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009118 return -1;
9119 }
9120
9121 final long identity = Binder.clearCallingIdentity();
9122 try {
9123 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9124 } finally {
9125 Binder.restoreCallingIdentity(identity);
9126 }
9127 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009128
9129 @Override
9130 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009131 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009132 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009133 mApp, subId, "getCdmaRoamingMode");
9134
9135 final long identity = Binder.clearCallingIdentity();
9136 try {
9137 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9138 } finally {
9139 Binder.restoreCallingIdentity(identity);
9140 }
9141 }
9142
9143 @Override
9144 public boolean setCdmaRoamingMode(int subId, int mode) {
9145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9146 mApp, subId, "setCdmaRoamingMode");
9147
9148 final long identity = Binder.clearCallingIdentity();
9149 try {
9150 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9151 } finally {
9152 Binder.restoreCallingIdentity(identity);
9153 }
9154 }
9155
9156 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009157 public int getCdmaSubscriptionMode(int subId) {
9158 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009159 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009160 mApp, subId, "getCdmaSubscriptionMode");
9161
9162 final long identity = Binder.clearCallingIdentity();
9163 try {
9164 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9165 } finally {
9166 Binder.restoreCallingIdentity(identity);
9167 }
9168 }
9169
9170 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009171 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9173 mApp, subId, "setCdmaSubscriptionMode");
9174
9175 final long identity = Binder.clearCallingIdentity();
9176 try {
9177 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9178 } finally {
9179 Binder.restoreCallingIdentity(identity);
9180 }
9181 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009182
sqianc5eccab2018-10-19 18:46:41 -07009183 @Override
sqian8c685422019-02-22 15:55:18 -08009184 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009185 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009186 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009187 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9188 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009189 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9190 }
9191 final long identity = Binder.clearCallingIdentity();
9192 try {
sqian854d44b2018-12-12 16:48:18 -08009193 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9194 for (Phone phone: PhoneFactory.getPhones()) {
9195 if (phone.getEmergencyNumberTracker() != null
9196 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9197 emergencyNumberListInternal.put(
9198 phone.getSubId(),
9199 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9200 }
sqian11b7a0e2018-12-05 18:48:28 -08009201 }
sqian854d44b2018-12-12 16:48:18 -08009202 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009203 } finally {
9204 Binder.restoreCallingIdentity(identity);
9205 }
sqianc5eccab2018-10-19 18:46:41 -07009206 }
9207
9208 @Override
sqian8c685422019-02-22 15:55:18 -08009209 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009210 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009211 if (!exactMatch) {
9212 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009213 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009214 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009215 }
9216 final long identity = Binder.clearCallingIdentity();
9217 try {
sqian854d44b2018-12-12 16:48:18 -08009218 for (Phone phone: PhoneFactory.getPhones()) {
9219 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009220 && phone.getEmergencyNumberTracker()
9221 .isEmergencyNumber(number, exactMatch)) {
9222 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009223 }
sqian11b7a0e2018-12-05 18:48:28 -08009224 }
9225 return false;
9226 } finally {
9227 Binder.restoreCallingIdentity(identity);
9228 }
9229 }
9230
sqianf4ca7ed2019-01-15 18:32:07 -08009231 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009232 * Start emergency callback mode for GsmCdmaPhone for testing.
9233 */
9234 @Override
9235 public void startEmergencyCallbackMode() {
9236 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9237 "startEmergencyCallbackMode");
9238 enforceModifyPermission();
9239 final long identity = Binder.clearCallingIdentity();
9240 try {
9241 for (Phone phone : PhoneFactory.getPhones()) {
9242 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9243 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9244 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9245 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9246 gsmCdmaPhone.obtainMessage(
9247 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9248 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9249 }
9250 }
9251 } finally {
9252 Binder.restoreCallingIdentity(identity);
9253 }
9254 }
9255
9256 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009257 * Update emergency number list for test mode.
9258 */
9259 @Override
9260 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9261 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9262 "updateEmergencyNumberListTestMode");
9263
9264 final long identity = Binder.clearCallingIdentity();
9265 try {
9266 for (Phone phone: PhoneFactory.getPhones()) {
9267 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9268 if (tracker != null) {
9269 tracker.executeEmergencyNumberTestModeCommand(action, num);
9270 }
9271 }
9272 } finally {
9273 Binder.restoreCallingIdentity(identity);
9274 }
9275 }
9276
9277 /**
9278 * Get the full emergency number list for test mode.
9279 */
9280 @Override
9281 public List<String> getEmergencyNumberListTestMode() {
9282 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9283 "getEmergencyNumberListTestMode");
9284
9285 final long identity = Binder.clearCallingIdentity();
9286 try {
9287 Set<String> emergencyNumbers = new HashSet<>();
9288 for (Phone phone: PhoneFactory.getPhones()) {
9289 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9290 if (tracker != null) {
9291 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9292 emergencyNumbers.add(num.getNumber());
9293 }
9294 }
9295 }
9296 return new ArrayList<>(emergencyNumbers);
9297 } finally {
9298 Binder.restoreCallingIdentity(identity);
9299 }
9300 }
9301
chen xud6b45bd2018-10-30 22:27:10 -07009302 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009303 public int getEmergencyNumberDbVersion(int subId) {
9304 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9305
9306 final long identity = Binder.clearCallingIdentity();
9307 try {
9308 final Phone phone = getPhone(subId);
9309 if (phone == null) {
9310 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9311 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9312 }
9313 return phone.getEmergencyNumberDbVersion();
9314 } finally {
9315 Binder.restoreCallingIdentity(identity);
9316 }
9317 }
9318
9319 @Override
9320 public void notifyOtaEmergencyNumberDbInstalled() {
9321 enforceModifyPermission();
9322
9323 final long identity = Binder.clearCallingIdentity();
9324 try {
9325 for (Phone phone: PhoneFactory.getPhones()) {
9326 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9327 if (tracker != null) {
9328 tracker.updateOtaEmergencyNumberDatabase();
9329 }
9330 }
9331 } finally {
9332 Binder.restoreCallingIdentity(identity);
9333 }
9334 }
9335
9336 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009337 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009338 enforceActiveEmergencySessionPermission();
9339
9340 final long identity = Binder.clearCallingIdentity();
9341 try {
9342 for (Phone phone: PhoneFactory.getPhones()) {
9343 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9344 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009345 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9346 }
9347 }
9348 } finally {
9349 Binder.restoreCallingIdentity(identity);
9350 }
9351 }
9352
9353 @Override
9354 public void resetOtaEmergencyNumberDbFilePath() {
9355 enforceActiveEmergencySessionPermission();
9356
9357 final long identity = Binder.clearCallingIdentity();
9358 try {
9359 for (Phone phone: PhoneFactory.getPhones()) {
9360 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9361 if (tracker != null) {
9362 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009363 }
9364 }
9365 } finally {
9366 Binder.restoreCallingIdentity(identity);
9367 }
9368 }
9369
9370 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009371 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9372 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9373 Phone phone = getPhone(subId);
9374 if (phone == null) {
9375 return null;
9376 }
9377 final long identity = Binder.clearCallingIdentity();
9378 try {
9379 UiccProfile profile = UiccController.getInstance()
9380 .getUiccProfileForPhone(phone.getPhoneId());
9381 if (profile != null) {
9382 return profile.getCertsFromCarrierPrivilegeAccessRules();
9383 }
9384 } finally {
9385 Binder.restoreCallingIdentity(identity);
9386 }
9387 return null;
9388 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009389
9390 /**
9391 * Enable or disable a modem stack.
9392 */
9393 @Override
9394 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9395 enforceModifyPermission();
9396
9397 final long identity = Binder.clearCallingIdentity();
9398 try {
9399 Phone phone = PhoneFactory.getPhone(slotIndex);
9400 if (phone == null) {
9401 return false;
9402 } else {
9403 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9404 }
9405 } finally {
9406 Binder.restoreCallingIdentity(identity);
9407 }
9408 }
Michelecea4cf22018-12-21 15:00:11 -08009409
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009410 /**
9411 * Whether a modem stack is enabled or not.
9412 */
9413 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009414 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9415 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009416 Phone phone = PhoneFactory.getPhone(slotIndex);
9417 if (phone == null) return false;
9418
9419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009420 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9421 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009422 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9423 }
9424
9425 final long identity = Binder.clearCallingIdentity();
9426 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009427 try {
9428 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9429 } catch (NoSuchElementException ex) {
9430 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9431 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009432 } finally {
9433 Binder.restoreCallingIdentity(identity);
9434 }
9435 }
9436
Michelecea4cf22018-12-21 15:00:11 -08009437 @Override
Michele0ea7d782019-03-19 14:58:42 -07009438 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009439 enforceModifyPermission();
9440
9441 final long identity = Binder.clearCallingIdentity();
9442 try {
9443 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009444 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009445 .commit();
9446 } finally {
9447 Binder.restoreCallingIdentity(identity);
9448 }
9449 }
9450
9451 @Override
Michele0ea7d782019-03-19 14:58:42 -07009452 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009453 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009454 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009455 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9456 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009457 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009458 }
Michelecea4cf22018-12-21 15:00:11 -08009459
9460 final long identity = Binder.clearCallingIdentity();
9461 try {
Michele0ea7d782019-03-19 14:58:42 -07009462 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009463 } finally {
9464 Binder.restoreCallingIdentity(identity);
9465 }
9466 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009467
Michele0ea7d782019-03-19 14:58:42 -07009468 @TelephonyManager.IsMultiSimSupportedResult
9469 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009470 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9471 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9472 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009473 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9474 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009475 }
9476 // Check if the hardware supports multisim functionality. If usage of multisim is not
9477 // supported by the modem, indicate that it is restricted.
9478 PhoneCapability staticCapability =
9479 mPhoneConfigurationManager.getStaticPhoneCapability();
9480 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009481 loge("isMultiSimSupportedInternal: no static configuration available");
9482 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009483 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009484 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009485 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9486 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009487 }
9488 // Check if support of multiple SIMs is restricted by carrier
9489 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009490 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009491 }
9492
Michele0ea7d782019-03-19 14:58:42 -07009493 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009494 }
9495
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009496 /**
9497 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009498 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9499 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9500 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009501 * @param numOfSims number of active sims we want to switch to
9502 */
9503 @Override
9504 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009505 if (numOfSims == 1) {
9506 enforceModifyPermission();
9507 } else {
9508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9509 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9510 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009511 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009512
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009513 try {
Michele30b57b22019-03-01 12:01:14 -08009514 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009515 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009516 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9517 return;
9518 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009519 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9520 } finally {
9521 Binder.restoreCallingIdentity(identity);
9522 }
9523 }
9524
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009525 @Override
9526 public boolean isApplicationOnUicc(int subId, int appType) {
9527 enforceReadPrivilegedPermission("isApplicationOnUicc");
9528 Phone phone = getPhone(subId);
9529 if (phone == null) {
9530 return false;
9531 }
9532 final long identity = Binder.clearCallingIdentity();
9533 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009534 UiccPort uiccPort = phone.getUiccPort();
9535 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009536 return false;
9537 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009538 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009539 if (uiccProfile == null) {
9540 return false;
9541 }
9542 if (TelephonyManager.APPTYPE_SIM <= appType
9543 && appType <= TelephonyManager.APPTYPE_ISIM) {
9544 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9545 }
9546 return false;
9547 } finally {
9548 Binder.restoreCallingIdentity(identity);
9549 }
9550 }
9551
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009552 /**
chen xub4baa772019-04-03 10:23:41 -07009553 * Get whether making changes to modem configurations will trigger reboot.
9554 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009555 */
9556 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009557 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9558 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009560 mApp, subId, callingPackage, callingFeatureId,
9561 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009562 return false;
9563 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009564 final long identity = Binder.clearCallingIdentity();
9565 try {
9566 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9567 } finally {
9568 Binder.restoreCallingIdentity(identity);
9569 }
9570 }
9571
Nathan Harold29f5f052019-02-15 13:41:57 -08009572 private void updateModemStateMetrics() {
9573 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9574 // TODO: check the state for each modem if the api is ready.
9575 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9576 }
9577
Pengquan Meng3889a572019-01-23 11:16:29 -08009578 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009579 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009580 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009581 // Verify that the callingPackage belongs to the calling UID
9582 mApp.getSystemService(AppOpsManager.class)
9583 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009584 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009585 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009586 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009587 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9588 if (slotInfos != null) {
9589 for (int i = 0; i < slotInfos.length; i++) {
9590 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9591 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9592 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9593 portInfo.getLogicalSlotIndex()));
9594 }
9595 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009596 }
9597 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009598 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009599 } finally {
9600 Binder.restoreCallingIdentity(identity);
9601 }
9602 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009603
9604 /**
9605 * Get the IRadio HAL Version
9606 */
9607 @Override
9608 public int getRadioHalVersion() {
9609 Phone phone = getDefaultPhone();
9610 if (phone == null) return -1;
9611 HalVersion hv = phone.getHalVersion();
9612 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9613 return hv.major * 100 + hv.minor;
9614 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009615
9616 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009617 * Get the current calling package name.
9618 * @return the current calling package name
9619 */
9620 @Override
9621 public String getCurrentPackageName() {
9622 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9623 }
9624
9625 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009626 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9627 * corresponding network requests on a subId.
9628 *
9629 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009630 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009631 * 2) APN is un-metered for this subscription, or
9632 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009633 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009634 *
9635 * @return whether data is allowed for a apn type.
9636 *
9637 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009638 */
9639 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009640 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009641 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9642 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009643
9644 // Now that all security checks passes, perform the operation as ourselves.
9645 final long identity = Binder.clearCallingIdentity();
9646 try {
9647 Phone phone = getPhone(subId);
9648 if (phone == null) return false;
9649
Jack Yu27422a52022-03-21 10:38:05 -07009650 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009651 boolean isDataEnabled;
Jack Yuabb10902022-07-31 00:43:21 -07009652 isMetered = phone.getDataNetworkController().getDataConfigManager()
9653 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9654 phone.getServiceState().getDataRoaming());
9655 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009656 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009657 } finally {
9658 Binder.restoreCallingIdentity(identity);
9659 }
9660 }
9661
9662 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009663 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009664 enforceReadPrivilegedPermission("isApnMetered");
9665
9666 // Now that all security checks passes, perform the operation as ourselves.
9667 final long identity = Binder.clearCallingIdentity();
9668 try {
9669 Phone phone = getPhone(subId);
9670 if (phone == null) return true; // By default return true.
Jack Yuabb10902022-07-31 00:43:21 -07009671 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9672 DataUtils.apnTypeToNetworkCapability(apnType),
9673 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009674 } finally {
9675 Binder.restoreCallingIdentity(identity);
9676 }
9677 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009678
9679 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009680 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9681 int subscriptionId, IBooleanConsumer resultCallback) {
9682 enforceModifyPermission();
9683 long token = Binder.clearCallingIdentity();
9684 try {
9685 Phone phone = getPhone(subscriptionId);
9686 if (phone == null) {
9687 try {
9688 if (resultCallback != null) {
9689 resultCallback.accept(false);
9690 }
9691 } catch (RemoteException e) {
9692 // ignore
9693 }
9694 return;
9695 }
9696 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9697 Pair.create(specifiers, (x) -> {
9698 try {
9699 if (resultCallback != null) {
9700 resultCallback.accept(x);
9701 }
9702 } catch (RemoteException e) {
9703 // ignore
9704 }
9705 });
9706 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9707 } finally {
9708 Binder.restoreCallingIdentity(token);
9709 }
9710 }
9711
9712 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009713 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9714 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009715 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009716 mApp, subId, "getSystemSelectionChannels");
9717 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9718 final long identity = Binder.clearCallingIdentity();
9719 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009720 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9721 if (result instanceof IllegalStateException) {
9722 throw (IllegalStateException) result;
9723 }
9724 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009725 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9726 return specifiers;
9727 } finally {
9728 Binder.restoreCallingIdentity(identity);
9729 }
9730 }
9731
9732 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009733 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009734 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009735 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009736 }
9737
9738 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009739 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9740 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009741 if (callingPackage == null) {
9742 callingPackage = getCurrentPackageName();
9743 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009744 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9745 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009746 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9747 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009748 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9749 }
9750 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9751 Intent intent = new Intent();
9752 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9753 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9754 // Bring up choose default SMS subscription dialog right now
9755 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9756 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9757 mApp.startActivity(intent);
9758 }
chen xud5ca2d52019-05-28 15:20:57 -07009759
9760 @Override
9761 public String getMmsUAProfUrl(int subId) {
9762 //TODO investigate if this API should require proper permission check in R b/133791609
9763 final long identity = Binder.clearCallingIdentity();
9764 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009765 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9766 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9767 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9768 return carrierUAProfUrl;
9769 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009770 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9771 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009772 } finally {
9773 Binder.restoreCallingIdentity(identity);
9774 }
9775 }
9776
9777 @Override
9778 public String getMmsUserAgent(int subId) {
9779 //TODO investigate if this API should require proper permission check in R b/133791609
9780 final long identity = Binder.clearCallingIdentity();
9781 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009782 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9783 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9784 if (!TextUtils.isEmpty(carrierUserAgent)) {
9785 return carrierUserAgent;
9786 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009787 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9788 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009789 } finally {
9790 Binder.restoreCallingIdentity(identity);
9791 }
9792 }
Jack Yub07d4972019-05-28 16:12:25 -07009793
9794 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009795 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9796 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009797
Jack Yub07d4972019-05-28 16:12:25 -07009798 final long identity = Binder.clearCallingIdentity();
9799 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009800 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009801 if (phone == null) return false;
9802
Hall Liua62f5da2020-09-25 10:42:19 -07009803 switch (policy) {
9804 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yuabb10902022-07-31 00:43:21 -07009805 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
Hall Liua62f5da2020-09-25 10:42:19 -07009806 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yuabb10902022-07-31 00:43:21 -07009807 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
Hall Liua62f5da2020-09-25 10:42:19 -07009808 default:
9809 throw new IllegalArgumentException(policy + " is not a valid policy");
9810 }
Jack Yub07d4972019-05-28 16:12:25 -07009811 } finally {
9812 Binder.restoreCallingIdentity(identity);
9813 }
9814 }
9815
9816 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009817 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009818 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009819 enforceModifyPermission();
9820
changbettyd5c246e2019-12-24 15:40:37 +08009821 final long identity = Binder.clearCallingIdentity();
9822 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009823 Phone phone = getPhone(subscriptionId);
9824 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009825
Hall Liua62f5da2020-09-25 10:42:19 -07009826 switch (policy) {
9827 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yuabb10902022-07-31 00:43:21 -07009828 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
Hall Liua62f5da2020-09-25 10:42:19 -07009829 break;
9830 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yuabb10902022-07-31 00:43:21 -07009831 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
Hall Liua62f5da2020-09-25 10:42:19 -07009832 break;
9833 default:
9834 throw new IllegalArgumentException(policy + " is not a valid policy");
9835 }
changbettyd5c246e2019-12-24 15:40:37 +08009836 } finally {
9837 Binder.restoreCallingIdentity(identity);
9838 }
9839 }
9840
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009841 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009842 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009843 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9844 * otherwise.
9845 */
9846 @Override
9847 public void setCepEnabled(boolean isCepEnabled) {
9848 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9849
9850 final long identity = Binder.clearCallingIdentity();
9851 try {
9852 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9853 for (Phone phone : PhoneFactory.getPhones()) {
9854 Phone defaultPhone = phone.getImsPhone();
9855 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9856 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9857 ImsPhoneCallTracker imsPhoneCallTracker =
9858 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9859 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9860 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9861 + imsPhone.getMsisdn());
9862 }
9863 }
9864 } finally {
9865 Binder.restoreCallingIdentity(identity);
9866 }
9867 }
allenwtsu46dcc572020-01-08 18:24:03 +08009868
9869 /**
9870 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9871 *
9872 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9873 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9874 * before being read.
9875 */
9876 @Override
9877 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9878 isCompressed) {
9879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9880 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009881 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9882 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9883 }
9884 if (!isImsAvailableOnDevice()) {
9885 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9886 "IMS not available on device.");
9887 }
9888
9889 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009890 try {
Hui Wang761a6682020-10-31 05:12:53 +00009891 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9892 } finally {
9893 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009894 }
9895 }
zoey chene02881a2019-12-30 16:11:23 +08009896
9897 @Override
9898 public boolean isIccLockEnabled(int subId) {
9899 enforceReadPrivilegedPermission("isIccLockEnabled");
9900
9901 // Now that all security checks passes, perform the operation as ourselves.
9902 final long identity = Binder.clearCallingIdentity();
9903 try {
9904 Phone phone = getPhone(subId);
9905 if (phone != null && phone.getIccCard() != null) {
9906 return phone.getIccCard().getIccLockEnabled();
9907 } else {
9908 return false;
9909 }
9910 } finally {
9911 Binder.restoreCallingIdentity(identity);
9912 }
9913 }
9914
9915 /**
9916 * Set the ICC pin lock enabled or disabled.
9917 *
9918 * @return an integer representing the status of IccLock enabled or disabled in the following
9919 * three cases:
9920 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9921 * successfully.
9922 * - Positive number and zero for remaining password attempts.
9923 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9924 *
9925 */
9926 @Override
9927 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9928 enforceModifyPermission();
9929
9930 Phone phone = getPhone(subId);
9931 if (phone == null) {
9932 return 0;
9933 }
9934 // Now that all security checks passes, perform the operation as ourselves.
9935 final long identity = Binder.clearCallingIdentity();
9936 try {
9937 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9938 new Pair<Boolean, String>(enabled, password), phone, null);
9939 return attemptsRemaining;
9940
9941 } catch (Exception e) {
9942 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9943 } finally {
9944 Binder.restoreCallingIdentity(identity);
9945 }
9946 return 0;
9947 }
9948
9949 /**
9950 * Change the ICC password used in ICC pin lock.
9951 *
9952 * @return an integer representing the status of IccLock changed in the following three cases:
9953 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9954 * - Positive number and zero for remaining password attempts.
9955 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9956 *
9957 */
9958 @Override
9959 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9960 enforceModifyPermission();
9961
9962 Phone phone = getPhone(subId);
9963 if (phone == null) {
9964 return 0;
9965 }
9966 // Now that all security checks passes, perform the operation as ourselves.
9967 final long identity = Binder.clearCallingIdentity();
9968 try {
9969 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9970 new Pair<String, String>(oldPassword, newPassword), phone, null);
9971 return attemptsRemaining;
9972
9973 } catch (Exception e) {
9974 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9975 } finally {
9976 Binder.restoreCallingIdentity(identity);
9977 }
9978 return 0;
9979 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009980
9981 /**
9982 * Request for receiving user activity notification
9983 */
9984 @Override
9985 public void requestUserActivityNotification() {
9986 if (!mNotifyUserActivity.get()
9987 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9988 mNotifyUserActivity.set(true);
9989 }
9990 }
9991
9992 /**
9993 * Called when userActivity is signalled in the power manager.
9994 * This is safe to call from any thread, with any window manager locks held or not.
9995 */
9996 @Override
9997 public void userActivity() {
9998 // ***************************************
9999 // * Inherited from PhoneWindowManager *
10000 // ***************************************
10001 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10002 // WITH ITS LOCKS HELD.
10003 //
10004 // This code must be VERY careful about the locks
10005 // it acquires.
10006 // In fact, the current code acquires way too many,
10007 // and probably has lurking deadlocks.
10008
10009 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10010 throw new SecurityException("Only the OS may call notifyUserActivity()");
10011 }
10012
10013 if (mNotifyUserActivity.getAndSet(false)) {
10014 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10015 USER_ACTIVITY_NOTIFICATION_DELAY);
10016 }
10017 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010018
10019 @Override
10020 public boolean canConnectTo5GInDsdsMode() {
10021 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10022 }
Jack Yud10cdd42020-09-28 20:28:01 -070010023
10024 @Override
10025 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10026 String callingFeatureId) {
10027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10028 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10029 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10030 }
10031
10032 Phone phone = getPhone(subId);
10033 if (phone == null) {
10034 throw new RuntimeException("phone is not available");
10035 }
10036 // Now that all security checks passes, perform the operation as ourselves.
10037 final long identity = Binder.clearCallingIdentity();
10038 try {
10039 return phone.getEquivalentHomePlmns();
10040 } finally {
10041 Binder.restoreCallingIdentity(identity);
10042 }
10043 }
Daniel Bright59e67312020-11-13 11:49:37 -080010044
10045 @Override
10046 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010047 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10048 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010049 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010050 if (radioInterfaceCapabilities == null) {
10051 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010052 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010053 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010054 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010055
Hui Wang641e81c2020-10-12 12:14:23 -070010056 @Override
10057 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10058 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010059 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10060 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10061 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10062 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10063 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010064 if (DBG) {
10065 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10066 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10067 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10068 }
10069
10070 if (!SubscriptionManager.isValidSubscriptionId(subId)
10071 || appType < TelephonyManager.APPTYPE_UNKNOWN
10072 || appType > TelephonyManager.APPTYPE_ISIM
10073 || nafUrl == null || securityProtocol == null || callback == null) {
10074 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10075 if (callback != null) {
10076 try {
10077 callback.onAuthenticationFailure(
10078 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10079 } catch (RemoteException exception) {
10080 log("Fail to notify onAuthenticationFailure due to " + exception);
10081 }
10082 return;
10083 }
10084 }
10085
10086 final long token = Binder.clearCallingIdentity();
10087 try {
10088 getGbaManager(subId).bootstrapAuthenticationRequest(
10089 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10090 forceBootStrapping, callback));
10091 } finally {
10092 Binder.restoreCallingIdentity(token);
10093 }
10094 }
10095
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010096 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010097 * Attempts to set the radio power state for all phones for thermal reason.
10098 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010099 * requested radio power state will actually be set. See {@link
10100 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10101 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010102 * @param enable {@code true} if trying to turn radio on.
10103 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10104 * false}.
10105 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010106 private boolean setRadioPowerForThermal(boolean enable) {
10107 boolean isPhoneAvailable = false;
10108 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10109 Phone phone = PhoneFactory.getPhone(i);
10110 if (phone != null) {
10111 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10112 isPhoneAvailable = true;
10113 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010114 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010115
10116 // return true if successfully informed the phone object about the thermal radio power
10117 // request.
10118 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010119 }
10120
10121 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010122 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010123 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10124 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10125 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10126 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10127 throw new IllegalArgumentException("modem does not support data throttling");
10128 }
10129
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010130 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10131 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010132 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010133 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10134 }
10135
Sarah Chinecc78c42022-03-31 21:16:48 -070010136 setDataEnabledForReason(
10137 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010138
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010139 if (isDataThrottlingSupported) {
10140 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010141 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010142 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10143 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10144 } else if (thermalMitigationResult
10145 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010146 log("Modem likely does not support data throttling on secondary carrier. Data " +
10147 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10148 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010149 }
10150 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010151 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010152
10153 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010154 }
10155
Jack Nudelman644b91a2021-03-12 14:09:48 -080010156 private static List<String> getThermalMitigationAllowlist(Context context) {
10157 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10158 for (String pckg : context.getResources()
10159 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10160 sThermalMitigationAllowlistedPackages.add(pckg);
10161 }
10162 }
10163
10164 return sThermalMitigationAllowlistedPackages;
10165 }
10166
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010167 private boolean isAnyPhoneInEmergencyState() {
10168 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10169 if (tm.isInEmergencyCall()) {
10170 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10171 return true;
10172 }
10173 for (Phone phone : PhoneFactory.getPhones()) {
10174 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10175 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10176 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10177 + phone.isInEcm());
10178 return true;
10179 }
10180 }
10181
10182 return false;
10183 }
10184
Jack Nudelman644b91a2021-03-12 14:09:48 -080010185 /**
10186 * Used by shell commands to add an authorized package name for thermal mitigation.
10187 * @param packageName name of package to be allowlisted
10188 * @param context
10189 */
10190 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10191 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10192 sThermalMitigationAllowlistedPackages.add(packageName);
10193 }
10194
10195 /**
10196 * Used by shell commands to remove an authorized package name for thermal mitigation.
10197 * @param packageName name of package to remove from allowlist
10198 * @param context
10199 */
10200 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10201 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10202 sThermalMitigationAllowlistedPackages.remove(packageName);
10203 }
10204
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010205 /**
10206 * Thermal mitigation request to control functionalities at modem.
10207 *
10208 * @param subId the id of the subscription.
10209 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010210 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010211 *
10212 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10213 */
10214 @Override
10215 @ThermalMitigationResult
10216 public int sendThermalMitigationRequest(
10217 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010218 ThermalMitigationRequest thermalMitigationRequest,
10219 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010220 enforceModifyPermission();
10221
Jack Nudelman644b91a2021-03-12 14:09:48 -080010222 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10223 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10224 .contains(callingPackage)) {
10225 throw new SecurityException("Calling package must be configured in the device config. "
10226 + "calling package: " + callingPackage);
10227 }
10228
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010229 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10230 final long identity = Binder.clearCallingIdentity();
10231
10232 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10233 try {
10234 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10235 switch (thermalMitigationAction) {
10236 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10237 thermalMitigationResult =
10238 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010239 thermalMitigationRequest.getDataThrottlingRequest(),
10240 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010241 break;
10242 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10243 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10244 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10245 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10246 }
10247
10248 // Ensure that radio is on. If not able to power on due to phone being
10249 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010250 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010251 thermalMitigationResult =
10252 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10253 break;
10254 }
10255
10256 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010257 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010258 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10259 break;
10260 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10261 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10262 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10263 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10264 }
10265
10266 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10267 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010268 Phone phone = getPhone(subId);
10269 if (phone == null) {
10270 thermalMitigationResult =
10271 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10272 break;
10273 }
10274
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010275 TelephonyConnectionService service =
10276 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010277 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010278 Log.e(LOG_TAG, "An emergency call is pending");
10279 thermalMitigationResult =
10280 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10281 break;
10282 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010283 thermalMitigationResult =
10284 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10285 break;
10286 }
10287 } else {
10288 thermalMitigationResult =
10289 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10290 break;
10291 }
10292
10293 // Turn radio off. If not able to power off due to phone being unavailable,
10294 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010295 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010296 thermalMitigationResult =
10297 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10298 break;
10299 }
10300 thermalMitigationResult =
10301 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10302 break;
10303 default:
10304 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10305 + "not exist. Requested action: " + thermalMitigationAction);
10306 }
10307 } catch (IllegalArgumentException e) {
10308 throw e;
10309 } catch (Exception e) {
10310 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10311 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10312 } finally {
10313 Binder.restoreCallingIdentity(identity);
10314 }
10315
10316 if (DBG) {
10317 log("thermalMitigationRequest returning with thermalMitigationResult: "
10318 + thermalMitigationResult);
10319 }
10320
10321 return thermalMitigationResult;
10322 }
Hui Wang641e81c2020-10-12 12:14:23 -070010323
10324 /**
10325 * Set the GbaService Package Name that Telephony will bind to.
10326 *
10327 * @param subId The sim that the GbaService is associated with.
10328 * @param packageName The name of the package to be replaced with.
10329 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10330 */
10331 @Override
10332 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10333 enforceModifyPermission();
10334
10335 final long identity = Binder.clearCallingIdentity();
10336 try {
10337 return getGbaManager(subId).overrideServicePackage(packageName);
10338 } finally {
10339 Binder.restoreCallingIdentity(identity);
10340 }
10341 }
10342
10343 /**
10344 * Return the package name of the currently bound GbaService.
10345 *
10346 * @param subId The sim that the GbaService is associated with.
10347 * @return the package name of the GbaService configuration, null if GBA is not supported.
10348 */
10349 @Override
10350 public String getBoundGbaService(int subId) {
10351 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10352
10353 final long identity = Binder.clearCallingIdentity();
10354 try {
10355 return getGbaManager(subId).getServicePackage();
10356 } finally {
10357 Binder.restoreCallingIdentity(identity);
10358 }
10359 }
10360
10361 /**
10362 * Set the release time for telephony to unbind GbaService.
10363 *
10364 * @param subId The sim that the GbaService is associated with.
10365 * @param interval The release time to unbind GbaService by millisecond.
10366 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10367 */
10368 @Override
10369 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10370 enforceModifyPermission();
10371
10372 final long identity = Binder.clearCallingIdentity();
10373 try {
10374 return getGbaManager(subId).overrideReleaseTime(interval);
10375 } finally {
10376 Binder.restoreCallingIdentity(identity);
10377 }
10378 }
10379
10380 /**
10381 * Return the release time for telephony to unbind GbaService.
10382 *
10383 * @param subId The sim that the GbaService is associated with.
10384 * @return The release time to unbind GbaService by millisecond.
10385 */
10386 @Override
10387 public int getGbaReleaseTime(int subId) {
10388 enforceReadPrivilegedPermission("getGbaReleaseTime");
10389
10390 final long identity = Binder.clearCallingIdentity();
10391 try {
10392 return getGbaManager(subId).getReleaseTime();
10393 } finally {
10394 Binder.restoreCallingIdentity(identity);
10395 }
10396 }
10397
10398 private GbaManager getGbaManager(int subId) {
10399 GbaManager instance = GbaManager.getInstance(subId);
10400 if (instance == null) {
10401 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10402 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10403 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10404 }
10405 return instance;
10406 }
Hui Wang761a6682020-10-31 05:12:53 +000010407
10408 /**
10409 * indicate whether the device and the carrier can support
10410 * RCS VoLTE single registration.
10411 */
10412 @Override
10413 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010414 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10415 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10416 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10417 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010418
10419 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10420 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10421 }
10422
10423 final long identity = Binder.clearCallingIdentity();
10424 try {
10425 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10426 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010427 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10428 if (isCapable != null) {
10429 return isCapable;
10430 }
Hui Wang761a6682020-10-31 05:12:53 +000010431 }
Hui Wang67af90e2021-06-04 16:57:15 -070010432 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10433 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010434 } finally {
10435 Binder.restoreCallingIdentity(identity);
10436 }
10437 }
10438
10439 /**
10440 * Register RCS provisioning callback.
10441 */
10442 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010443 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010444 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010445 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010446 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010447 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10448 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010449
10450 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10451 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10452 }
10453 if (!isImsAvailableOnDevice()) {
10454 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10455 "IMS not available on device.");
10456 }
10457
10458 final long identity = Binder.clearCallingIdentity();
10459 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010460 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010461 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010462 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10463 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010464 }
Hui Wang761a6682020-10-31 05:12:53 +000010465 } finally {
10466 Binder.restoreCallingIdentity(identity);
10467 }
10468 }
10469
10470 /**
10471 * Unregister RCS provisioning callback.
10472 */
10473 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010474 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010475 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010476 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010477 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010478 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10479 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010480
10481 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10482 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10483 }
10484 if (!isImsAvailableOnDevice()) {
10485 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10486 "IMS not available on device.");
10487 }
10488
10489 final long identity = Binder.clearCallingIdentity();
10490 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010491 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010492 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010493 } finally {
10494 Binder.restoreCallingIdentity(identity);
10495 }
10496 }
10497
10498 /**
10499 * trigger RCS reconfiguration.
10500 */
10501 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010502 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10503 "triggerRcsReconfiguration",
10504 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010505
10506 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10507 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10508 }
10509 if (!isImsAvailableOnDevice()) {
10510 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10511 "IMS not available on device.");
10512 }
10513
10514 final long identity = Binder.clearCallingIdentity();
10515 try {
10516 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10517 } finally {
10518 Binder.restoreCallingIdentity(identity);
10519 }
10520 }
10521
10522 /**
10523 * Provide the client configuration parameters of the RCS application.
10524 */
10525 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010526 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10527 "setRcsClientConfiguration",
10528 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010529
10530 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10531 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10532 }
10533 if (!isImsAvailableOnDevice()) {
10534 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10535 "IMS not available on device.");
10536 }
10537
10538 final long identity = Binder.clearCallingIdentity();
10539
10540 try {
10541 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10542 if (configBinder == null) {
10543 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010544 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10545 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010546 } else {
10547 configBinder.setRcsClientConfiguration(rcc);
10548 }
joonhunshin3e154242021-09-17 06:33:39 +000010549
10550 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10551 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010552 } catch (RemoteException e) {
10553 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010554 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10555 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010556 } finally {
10557 Binder.restoreCallingIdentity(identity);
10558 }
10559 }
10560
10561 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010562 * Enables or disables the test mode for RCS VoLTE single registration.
10563 */
10564 @Override
10565 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10566 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10567 "setRcsSingleRegistrationTestModeEnabled");
10568
10569 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10570 }
10571
10572 /**
10573 * Gets the test mode for RCS VoLTE single registration.
10574 */
10575 @Override
10576 public boolean getRcsSingleRegistrationTestModeEnabled() {
10577 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10578 "getRcsSingleRegistrationTestModeEnabled");
10579
10580 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10581 }
10582
10583 /**
Hui Wang761a6682020-10-31 05:12:53 +000010584 * Overrides the config of RCS VoLTE single registration enabled for the device.
10585 */
10586 @Override
10587 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10588 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10589 "setDeviceSingleRegistrationEnabledOverride");
10590 enforceModifyPermission();
10591
10592 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10593 : Boolean.parseBoolean(enabledStr);
10594 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010595 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010596 }
10597
10598 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010599 * Sends a device to device communication message. Only usable via shell.
10600 * @param message message to send.
10601 * @param value message value.
10602 */
10603 @Override
10604 public void sendDeviceToDeviceMessage(int message, int value) {
10605 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010606 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010607 enforceModifyPermission();
10608
10609 final long identity = Binder.clearCallingIdentity();
10610 try {
10611 TelephonyConnectionService service =
10612 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10613 if (service == null) {
10614 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10615 return;
10616 }
10617 service.sendTestDeviceToDeviceMessage(message, value);
10618 } finally {
10619 Binder.restoreCallingIdentity(identity);
10620 }
10621 }
10622
Tyler Gunnbabbda02021-02-10 11:05:02 -080010623 /**
10624 * Sets the specified device to device transport active.
10625 * @param transport The transport to set active.
10626 */
10627 @Override
10628 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10629 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10630 "setActiveDeviceToDeviceTransport");
10631 enforceModifyPermission();
10632
10633 final long identity = Binder.clearCallingIdentity();
10634 try {
10635 TelephonyConnectionService service =
10636 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10637 if (service == null) {
10638 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10639 return;
10640 }
10641 service.setActiveDeviceToDeviceTransport(transport);
10642 } finally {
10643 Binder.restoreCallingIdentity(identity);
10644 }
10645 }
Tyler Gunn92479152021-01-20 16:30:10 -080010646
Tyler Gunnd4339262021-05-03 14:46:49 -070010647 @Override
10648 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10649 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10650 "setDeviceToDeviceForceEnabled");
10651
10652 final long identity = Binder.clearCallingIdentity();
10653 try {
10654 Arrays.stream(PhoneFactory.getPhones()).forEach(
10655 p -> {
10656 Phone thePhone = p.getImsPhone();
10657 if (thePhone != null && thePhone instanceof ImsPhone) {
10658 ImsPhone imsPhone = (ImsPhone) thePhone;
10659 CallTracker tracker = imsPhone.getCallTracker();
10660 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10661 ImsPhoneCallTracker imsPhoneCallTracker =
10662 (ImsPhoneCallTracker) tracker;
10663 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10664 }
10665 }
10666 }
10667 );
10668 } finally {
10669 Binder.restoreCallingIdentity(identity);
10670 }
10671 }
10672
Tyler Gunn92479152021-01-20 16:30:10 -080010673 /**
Hui Wang761a6682020-10-31 05:12:53 +000010674 * Gets the config of RCS VoLTE single registration enabled for the device.
10675 */
10676 @Override
10677 public boolean getDeviceSingleRegistrationEnabled() {
10678 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10679 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10680 }
10681
10682 /**
10683 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10684 */
10685 @Override
10686 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10687 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10688 "setCarrierSingleRegistrationEnabledOverride");
10689 enforceModifyPermission();
10690
10691 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10692 : Boolean.parseBoolean(enabledStr);
10693 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10694 subId, enabled);
10695 }
10696
10697 /**
10698 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10699 */
10700 @Override
10701 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10702 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10703 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10704 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010705
10706 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010707 * Overrides the ims feature validation result
10708 */
10709 @Override
10710 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10711 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10712 "setImsFeatureValidationOverride");
10713
10714 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10715 : Boolean.parseBoolean(enabledStr);
10716 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10717 subId, enabled);
10718 }
10719
10720 /**
10721 * Gets the ims feature validation override value
10722 */
10723 @Override
10724 public boolean getImsFeatureValidationOverride(int subId) {
10725 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10726 "getImsFeatureValidationOverride");
10727 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10728 }
10729
10730 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010731 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10732 * their mobile plan.
10733 */
10734 @Override
10735 public String getMobileProvisioningUrl() {
10736 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10737 final long identity = Binder.clearCallingIdentity();
10738 try {
10739 return getDefaultPhone().getMobileProvisioningUrl();
10740 } finally {
10741 Binder.restoreCallingIdentity(identity);
10742 }
10743 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010744
James.cf Linbcdf8b32021-01-14 16:44:13 +080010745 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010746 * Get the EAB contact from the EAB database.
10747 */
10748 @Override
10749 public String getContactFromEab(String contact) {
10750 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10751 enforceModifyPermission();
10752 final long identity = Binder.clearCallingIdentity();
10753 try {
10754 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10755 } finally {
10756 Binder.restoreCallingIdentity(identity);
10757 }
10758 }
10759
10760 /**
Calvin Pana1434322021-07-01 19:27:01 +080010761 * Get the EAB capability from the EAB database.
10762 */
10763 @Override
10764 public String getCapabilityFromEab(String contact) {
10765 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10766 enforceModifyPermission();
10767 final long identity = Binder.clearCallingIdentity();
10768 try {
10769 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10770 } finally {
10771 Binder.restoreCallingIdentity(identity);
10772 }
10773 }
10774
10775 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010776 * Remove the EAB contacts from the EAB database.
10777 */
10778 @Override
10779 public int removeContactFromEab(int subId, String contacts) {
10780 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10781 enforceModifyPermission();
10782 final long identity = Binder.clearCallingIdentity();
10783 try {
10784 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10785 } finally {
10786 Binder.restoreCallingIdentity(identity);
10787 }
10788 }
10789
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010790 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010791 public boolean getDeviceUceEnabled() {
10792 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10793 final long identity = Binder.clearCallingIdentity();
10794 try {
10795 return mApp.getDeviceUceEnabled();
10796 } finally {
10797 Binder.restoreCallingIdentity(identity);
10798 }
10799 }
10800
10801 @Override
10802 public void setDeviceUceEnabled(boolean isEnabled) {
10803 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10804 final long identity = Binder.clearCallingIdentity();
10805 try {
10806 mApp.setDeviceUceEnabled(isEnabled);
10807 } finally {
10808 Binder.restoreCallingIdentity(identity);
10809 }
10810 }
10811
Brad Ebinger14d467f2021-02-12 06:18:28 +000010812 /**
10813 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10814 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10815 */
10816 // Used for SHELL command only right now.
10817 @Override
10818 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10819 List<String> featureTags) {
10820 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10821 "addUceRegistrationOverrideShell");
10822 final long identity = Binder.clearCallingIdentity();
10823 try {
10824 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10825 new ArraySet<>(featureTags));
10826 } catch (ImsException e) {
10827 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10828 } finally {
10829 Binder.restoreCallingIdentity(identity);
10830 }
10831 }
10832
10833 /**
10834 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10835 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10836 */
10837 // Used for SHELL command only right now.
10838 @Override
10839 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10840 List<String> featureTags) {
10841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10842 "removeUceRegistrationOverrideShell");
10843 final long identity = Binder.clearCallingIdentity();
10844 try {
10845 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10846 new ArraySet<>(featureTags));
10847 } catch (ImsException e) {
10848 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10849 } finally {
10850 Binder.restoreCallingIdentity(identity);
10851 }
10852 }
10853
10854 /**
10855 * Clear all overrides in 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 clearUceRegistrationOverrideShell(int subId) {
10861 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10862 "clearUceRegistrationOverrideShell");
10863 final long identity = Binder.clearCallingIdentity();
10864 try {
10865 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10866 } catch (ImsException e) {
10867 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10868 } finally {
10869 Binder.restoreCallingIdentity(identity);
10870 }
10871 }
10872
10873 /**
10874 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10875 */
10876 // Used for SHELL command only right now.
10877 @Override
10878 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10879 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10880 "getLatestRcsContactUceCapabilityShell");
10881 final long identity = Binder.clearCallingIdentity();
10882 try {
10883 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10884 } catch (ImsException e) {
10885 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10886 } finally {
10887 Binder.restoreCallingIdentity(identity);
10888 }
10889 }
10890
10891 /**
10892 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10893 * device does not have an active PUBLISH.
10894 */
10895 // Used for SHELL command only right now.
10896 @Override
10897 public String getLastUcePidfXmlShell(int subId) {
10898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10899 final long identity = Binder.clearCallingIdentity();
10900 try {
10901 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10902 } catch (ImsException e) {
10903 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10904 } finally {
10905 Binder.restoreCallingIdentity(identity);
10906 }
10907 }
10908
James.cf Line8713a42021-04-29 16:04:26 +080010909 /**
10910 * Remove UCE requests cannot be sent to the network status.
10911 */
10912 // Used for SHELL command only right now.
10913 @Override
10914 public boolean removeUceRequestDisallowedStatus(int subId) {
10915 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10916 final long identity = Binder.clearCallingIdentity();
10917 try {
10918 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10919 } catch (ImsException e) {
10920 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10921 } finally {
10922 Binder.restoreCallingIdentity(identity);
10923 }
10924 }
10925
James.cf Lin18bb9002021-05-25 01:37:38 +080010926 /**
10927 * Remove UCE requests cannot be sent to the network status.
10928 */
10929 // Used for SHELL command only.
10930 @Override
10931 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10932 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10933 final long identity = Binder.clearCallingIdentity();
10934 try {
10935 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10936 } catch (ImsException e) {
10937 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10938 } finally {
10939 Binder.restoreCallingIdentity(identity);
10940 }
10941 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010942
James.cf Lin4b784aa2021-01-31 03:25:15 +080010943 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010944 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10945 String callingPackage) {
10946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10947 mApp, subId, "setSignalStrengthUpdateRequest");
10948
10949 final int callingUid = Binder.getCallingUid();
10950 // Verify that tha callingPackage belongs to the calling UID
10951 mApp.getSystemService(AppOpsManager.class)
10952 .checkPackage(callingUid, callingPackage);
10953
Rambo Wang3607f502021-02-01 21:51:40 -080010954 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010955
10956 final long identity = Binder.clearCallingIdentity();
10957 try {
10958 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10959 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10960
10961 if (result instanceof IllegalStateException) {
10962 throw (IllegalStateException) result;
10963 }
10964 } finally {
10965 Binder.restoreCallingIdentity(identity);
10966 }
10967 }
10968
10969 @Override
10970 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10971 String callingPackage) {
10972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10973 mApp, subId, "clearSignalStrengthUpdateRequest");
10974
10975 final int callingUid = Binder.getCallingUid();
10976 // Verify that tha callingPackage belongs to the calling UID
10977 mApp.getSystemService(AppOpsManager.class)
10978 .checkPackage(callingUid, callingPackage);
10979
10980 final long identity = Binder.clearCallingIdentity();
10981 try {
10982 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10983 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10984
10985 if (result instanceof IllegalStateException) {
10986 throw (IllegalStateException) result;
10987 }
10988 } finally {
10989 Binder.restoreCallingIdentity(identity);
10990 }
10991 }
10992
Rambo Wang3607f502021-02-01 21:51:40 -080010993 private static void validateSignalStrengthUpdateRequest(Context context,
10994 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010995 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10996 // phone/system process do not have further restriction on request
10997 return;
10998 }
10999
11000 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011001 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011002 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011003 context.enforceCallingOrSelfPermission(
11004 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11005 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011006 }
11007
11008 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11009 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11010 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11011 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11012 || info.isEnabled()) {
11013 throw new IllegalArgumentException(
11014 "Only system can set hide fields in SignalThresholdInfo");
11015 }
11016
11017 // Thresholds length for each RAN need in range. This has been validated in
11018 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11019 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11020 final int[] thresholds = info.getThresholds();
11021 Objects.requireNonNull(thresholds);
11022 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11023 || thresholds.length
11024 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11025 throw new IllegalArgumentException(
11026 "thresholds length is out of range: " + thresholds.length);
11027 }
11028 }
11029 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011030
11031 /**
11032 * Gets the current phone capability.
11033 *
11034 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11035 * @return the PhoneCapability which describes the data connection capability of modem.
11036 * It's used to evaluate possible phone config change, for example from single
11037 * SIM device to multi-SIM device.
11038 */
11039 @Override
11040 public PhoneCapability getPhoneCapability() {
11041 enforceReadPrivilegedPermission("getPhoneCapability");
11042 final long identity = Binder.clearCallingIdentity();
11043 try {
11044 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11045 } finally {
11046 Binder.restoreCallingIdentity(identity);
11047 }
11048 }
Michele Berionne5e411512020-11-13 02:36:59 +000011049
11050 /**
11051 * Prepare TelephonyManager for an unattended reboot. The reboot is
11052 * required to be done shortly after the API is invoked.
11053 */
11054 @Override
11055 @TelephonyManager.PrepareUnattendedRebootResult
11056 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011057 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011058 enforceRebootPermission();
11059
11060 final long identity = Binder.clearCallingIdentity();
11061 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011062 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011063 } finally {
11064 Binder.restoreCallingIdentity(identity);
11065 }
11066 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011067
11068 /**
11069 * Request to get the current slicing configuration including URSP rules and
11070 * NSSAIs (configured, allowed and rejected).
11071 *
11072 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11073 */
11074 @Override
11075 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011076 TelephonyPermissions
11077 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11078 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011079
11080 final long identity = Binder.clearCallingIdentity();
11081 try {
11082 Phone phone = getDefaultPhone();
11083 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11084 } finally {
11085 Binder.restoreCallingIdentity(identity);
11086 }
11087 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011088
11089 /**
11090 * Register an IMS connection state callback
11091 */
11092 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011093 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11094 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011095 if (feature == ImsFeature.FEATURE_MMTEL) {
11096 // ImsMmTelManager
11097 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11098 TelephonyPermissions
11099 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11100 mApp, subId, "registerImsStateCallback");
11101 } else if (feature == ImsFeature.FEATURE_RCS) {
11102 // ImsRcsManager or SipDelegateManager
11103 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11104 Binder.getCallingUid(), "registerImsStateCallback",
11105 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11106 Manifest.permission.READ_PRECISE_PHONE_STATE,
11107 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11108 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11109 }
11110
11111 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11112 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11113 "IMS not available on device.");
11114 }
11115
11116 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11117 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11118 }
11119
11120 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11121 if (controller == null) {
11122 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11123 "IMS not available on device.");
11124 }
11125
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011126 if (callingPackage == null) {
11127 callingPackage = getCurrentPackageName();
11128 }
11129
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011130 final long token = Binder.clearCallingIdentity();
11131 try {
11132 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011133 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011134 } catch (ImsException e) {
11135 throw new ServiceSpecificException(e.getCode());
11136 } finally {
11137 Binder.restoreCallingIdentity(token);
11138 }
11139 }
11140
11141 /**
11142 * Unregister an IMS connection state callback
11143 */
11144 @Override
11145 public void unregisterImsStateCallback(IImsStateCallback cb) {
11146 final long token = Binder.clearCallingIdentity();
11147 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11148 if (controller == null) {
11149 return;
11150 }
11151 try {
11152 controller.unregisterImsStateCallback(cb);
11153 } finally {
11154 Binder.restoreCallingIdentity(token);
11155 }
11156 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011157
11158 /**
11159 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11160 *
11161 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11162 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11163 * SecurityException.
11164 * If there is current registered network this value will be same as the registered cell
11165 * identity. If the device goes out of service the previous cell identity is cached and
11166 * will be returned. If the cache age of the Cell identity is more than 24 hours
11167 * it will be cleared and null will be returned.
11168 *
11169 */
11170 @Override
11171 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11172 String callingFeatureId) {
11173 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11174 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11175 LocationAccessPolicy.checkLocationPermission(mApp,
11176 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11177 .setCallingPackage(callingPackage)
11178 .setCallingFeatureId(callingFeatureId)
11179 .setCallingPid(Binder.getCallingPid())
11180 .setCallingUid(Binder.getCallingUid())
11181 .setMethod("getLastKnownCellIdentity")
11182 .setLogAsInfo(true)
11183 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11184 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11185 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11186 .build());
11187
11188 boolean hasFinePermission =
11189 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11190 if (!hasFinePermission
11191 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11192 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011193 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011194 }
11195
11196 final long identity = Binder.clearCallingIdentity();
11197 try {
11198 Phone phone = getPhone(subId);
11199 if (phone == null) return null;
11200 ServiceStateTracker sst = phone.getServiceStateTracker();
11201 if (sst == null) return null;
11202 return sst.getLastKnownCellIdentity();
11203 } finally {
11204 Binder.restoreCallingIdentity(identity);
11205 }
11206 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011207
jimsun3b9ccac2021-10-26 15:01:23 +080011208 /**
11209 * Sets the modem service class Name that Telephony will bind to.
11210 *
11211 * @param serviceName The class name of the modem service.
11212 * @return true if the operation is succeed, otherwise false.
11213 */
11214 public boolean setModemService(String serviceName) {
11215 Log.d(LOG_TAG, "setModemService - " + serviceName);
11216 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11218 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11219 "setModemService");
11220 return mPhoneConfigurationManager.setModemService(serviceName);
11221 }
11222
11223 /**
11224 * Return the class name of the currently bounded modem service.
11225 *
11226 * @return the class name of the modem service.
11227 */
11228 public String getModemService() {
11229 String result;
11230 Log.d(LOG_TAG, "getModemService");
11231 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11232 TelephonyPermissions
11233 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11234 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11235 "getModemService");
11236 result = mPhoneConfigurationManager.getModemService();
11237 Log.d(LOG_TAG, "result = " + result);
11238 return result;
11239 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011240
11241 @Override
11242 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11243 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11244 mApp.enforceCallingOrSelfPermission(
11245 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11246 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11247
11248 final long identity = Binder.clearCallingIdentity();
11249 try {
11250 Phone phone = getPhone(subId);
11251 if (phone == null) return;
11252 phone.setVoiceServiceStateOverride(hasService);
11253 } finally {
11254 Binder.restoreCallingIdentity(identity);
11255 }
11256 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011257
11258 /**
11259 * set removable eSIM as default eUICC.
11260 *
11261 * @hide
11262 */
11263 @Override
11264 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11265 enforceModifyPermission();
11266 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11267
11268 final long identity = Binder.clearCallingIdentity();
11269 try {
11270 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11271 } finally {
11272 Binder.restoreCallingIdentity(identity);
11273 }
11274 }
11275
11276 /**
11277 * Returns whether the removable eSIM is default eUICC or not.
11278 *
11279 * @hide
11280 */
11281 @Override
11282 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11283 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11284 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11285
11286 final long identity = Binder.clearCallingIdentity();
11287 try {
11288 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11289 } finally {
11290 Binder.restoreCallingIdentity(identity);
11291 }
11292 }
11293
11294
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011295}