blob: 83eafd5df702a1bd7c2476ea50be83a3034a0ebd [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Peter Wangdafb9ac2020-01-15 14:13:38 -0800383 /** User Activity */
384 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800385 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
386
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700387 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
388
Derek Tan97ebb422014-09-05 16:55:38 -0700389 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
390 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800391 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800392 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700393
Michelecea4cf22018-12-21 15:00:11 -0800394 // String to store multi SIM allowed
395 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
396
Derek Tan740e1672017-06-27 14:56:27 -0700397 // The AID of ISD-R.
398 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
399
yinxub1bed742017-04-17 11:45:04 -0700400 private NetworkScanRequestTracker mNetworkScanRequestTracker;
401
David Kelly5e06a7f2018-03-12 14:10:59 +0000402 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
403 private static final int MANUFACTURER_CODE_LENGTH = 8;
404
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800405 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800406 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800407
Derek Tan89e89d42014-07-08 17:00:10 -0700408 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700409 * Experiment flag to enable erase modem config on reset network, default value is false
410 */
411 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
412 "reset_network_erase_modem_config_enabled";
413
Rambo Wang0f050d82021-02-12 11:43:36 -0800414 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800415
sandeepjsb6c87872021-09-27 15:34:44 +0000416 /**
417 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
418 * one ICCID active at the same time.
419 * Apps should use below API signatures if targeting SDK is T and beyond.
420 *
421 * @hide
422 */
423 @ChangeId
424 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
425 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800426
Naina Nallurid63128d2019-09-17 14:10:30 -0700427 /**
Chen Xu540470b2021-12-14 17:15:47 -0800428 * Apps targeting on Android T and beyond will get exception whenever icc close channel
429 * operation fails.
430 */
431 @ChangeId
432 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
433 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
434
435 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 * A request object to use for transmitting data to an ICC.
437 */
438 private static final class IccAPDUArgument {
439 public int channel, cla, command, p1, p2, p3;
440 public String data;
441
442 public IccAPDUArgument(int channel, int cla, int command,
443 int p1, int p2, int p3, String data) {
444 this.channel = channel;
445 this.cla = cla;
446 this.command = command;
447 this.p1 = p1;
448 this.p2 = p2;
449 this.p3 = p3;
450 this.data = data;
451 }
452 }
453
454 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700455 * A request object to use for transmitting data to an ICC.
456 */
457 private static final class ManualNetworkSelectionArgument {
458 public OperatorInfo operatorInfo;
459 public boolean persistSelection;
460
461 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
462 this.operatorInfo = operatorInfo;
463 this.persistSelection = persistSelection;
464 }
465 }
466
467 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
469 * request after sending. The main thread will notify the request when it is complete.
470 */
471 private static final class MainThreadRequest {
472 /** The argument to use for the request */
473 public Object argument;
474 /** The result of the request that is run on the main thread */
475 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800476 // The subscriber id that this request applies to. Defaults to
477 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
478 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479
Nathan Harold92bed182018-10-12 18:16:49 -0700480 // In cases where subId is unavailable, the caller needs to specify the phone.
481 public Phone phone;
482
vagdeviaf9a5b92018-08-15 16:01:53 -0700483 public WorkSource workSource;
484
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485 public MainThreadRequest(Object argument) {
486 this.argument = argument;
487 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800488
Nathan Harold92bed182018-10-12 18:16:49 -0700489 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
490 this.argument = argument;
491 if (phone != null) {
492 this.phone = phone;
493 }
494 this.workSource = workSource;
495 }
496
vagdeviaf9a5b92018-08-15 16:01:53 -0700497 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800498 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800499 if (subId != null) {
500 this.subId = subId;
501 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700502 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504 }
505
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800506 private static final class IncomingThirdPartyCallArgs {
507 public final ComponentName component;
508 public final String callId;
509 public final String callerDisplayName;
510
511 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
512 String callerDisplayName) {
513 this.component = component;
514 this.callId = callId;
515 this.callerDisplayName = callerDisplayName;
516 }
517 }
518
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 /**
520 * A handler that processes messages on the main thread in the phone process. Since many
521 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
522 * inbound binder threads to the main thread in the phone process. The Binder thread
523 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
524 * on, which will be notified when the operation completes and will contain the result of the
525 * request.
526 *
527 * <p>If a MainThreadRequest object is provided in the msg.obj field,
528 * note that request.result must be set to something non-null for the calling thread to
529 * unblock.
530 */
531 private final class MainThreadHandler extends Handler {
532 @Override
533 public void handleMessage(Message msg) {
534 MainThreadRequest request;
535 Message onCompleted;
536 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000537 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800539 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540
541 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 case CMD_HANDLE_USSD_REQUEST: {
543 request = (MainThreadRequest) msg.obj;
544 final Phone phone = getPhoneFromRequest(request);
545 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800546 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700548
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 if (!isUssdApiAllowed(request.subId)) {
550 // Carrier does not support use of this API, return failure.
551 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
552 UssdResponse response = new UssdResponse(ussdRequest, null);
553 Bundle returnData = new Bundle();
554 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
555 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700556
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 request.result = true;
558 notifyRequester(request);
559 return;
560 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700561
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 try {
563 request.result = phone != null
564 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
565 } catch (CallStateException cse) {
566 request.result = false;
567 }
568 // Wake up the requesting thread
569 notifyRequester(request);
570 break;
pkanwar32d516d2016-10-14 19:37:38 -0700571 }
572
Yorke Lee716f67e2015-06-17 15:39:16 -0700573 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700574 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700575 final Phone phone = getPhoneFromRequest(request);
576 request.result = phone != null ?
577 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
578 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700579 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000587 uiccPort = getUiccPortFromRequest(request);
588 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800590 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800594 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000595 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800596 iccArgument.channel, iccArgument.cla, iccArgument.command,
597 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
598 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 break;
601
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
605 if (ar.exception == null && ar.result != null) {
606 request.result = ar.result;
607 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800608 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 if (ar.result == null) {
610 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800611 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800613 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 } else {
615 loge("iccTransmitApduLogicalChannel: Unknown exception");
616 }
617 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 break;
620
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
622 request = (MainThreadRequest) msg.obj;
623 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000624 uiccPort = getUiccPortFromRequest(request);
625 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800627 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800631 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000632 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800633 iccArgument.cla, iccArgument.command, iccArgument.p1,
634 iccArgument.p2,
635 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700636 }
637 break;
638
639 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
640 ar = (AsyncResult) msg.obj;
641 request = (MainThreadRequest) ar.userObj;
642 if (ar.exception == null && ar.result != null) {
643 request.result = ar.result;
644 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800645 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700646 if (ar.result == null) {
647 loge("iccTransmitApduBasicChannel: Empty response");
648 } else if (ar.exception instanceof CommandException) {
649 loge("iccTransmitApduBasicChannel: CommandException: " +
650 ar.exception);
651 } else {
652 loge("iccTransmitApduBasicChannel: Unknown exception");
653 }
654 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 break;
657
658 case CMD_EXCHANGE_SIM_IO:
659 request = (MainThreadRequest) msg.obj;
660 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000661 uiccPort = getUiccPortFromRequest(request);
662 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800664 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700665 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 } else {
667 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
668 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000669 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
671 iccArgument.data, onCompleted);
672 }
673 break;
674
675 case EVENT_EXCHANGE_SIM_IO_DONE:
676 ar = (AsyncResult) msg.obj;
677 request = (MainThreadRequest) ar.userObj;
678 if (ar.exception == null && ar.result != null) {
679 request.result = ar.result;
680 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800681 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700682 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 break;
685
Derek Tan4d5e5c12014-02-04 11:54:58 -0800686 case CMD_SEND_ENVELOPE:
687 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000688 uiccPort = getUiccPortFromRequest(request);
689 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700690 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800691 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700692 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700693 } else {
694 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800695 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700696 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800697 break;
698
699 case EVENT_SEND_ENVELOPE_DONE:
700 ar = (AsyncResult) msg.obj;
701 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700702 if (ar.exception == null && ar.result != null) {
703 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800704 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800705 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700706 if (ar.result == null) {
707 loge("sendEnvelopeWithStatus: Empty response");
708 } else if (ar.exception instanceof CommandException) {
709 loge("sendEnvelopeWithStatus: CommandException: " +
710 ar.exception);
711 } else {
712 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
713 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800714 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800716 break;
717
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 case CMD_OPEN_CHANNEL:
719 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000720 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800721 IccLogicalChannelRequest openChannelRequest =
722 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000723 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700724 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800725 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800726 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700727 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700728 } else {
729 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800730 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
731 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700732 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700733 break;
734
735 case EVENT_OPEN_CHANNEL_DONE:
736 ar = (AsyncResult) msg.obj;
737 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700738 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 int[] result = (int[]) ar.result;
741 int channelId = result[0];
742 byte[] selectResponse = null;
743 if (result.length > 1) {
744 selectResponse = new byte[result.length - 1];
745 for (int i = 1; i < result.length; ++i) {
746 selectResponse[i - 1] = (byte) result[i];
747 }
748 }
749 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800750 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800751
752 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700753 if (uiccPort == null) {
754 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
755 } else {
756 IccLogicalChannelRequest channelRequest =
757 (IccLogicalChannelRequest) request.argument;
758 channelRequest.channel = channelId;
759 uiccPort.onLogicalChannelOpened(channelRequest);
760 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 if (ar.result == null) {
763 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700765 if (ar.exception != null) {
766 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
767 }
768
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700769 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700770 if (ar.exception instanceof CommandException) {
771 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800772 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700773 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700774 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700775 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700776 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700777 }
778 }
779 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800780 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700782 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700783 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 break;
785
786 case CMD_CLOSE_CHANNEL:
787 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000788 uiccPort = getUiccPortFromRequest(request);
789 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700790 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800791 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800792 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800793 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700794 } else {
795 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000796 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700797 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 break;
799
800 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800801 ar = (AsyncResult) msg.obj;
802 request = (MainThreadRequest) ar.userObj;
803 if (ar.exception == null) {
804 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800805 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700806 if (uiccPort == null) {
807 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
808 } else {
809 final int channelId = (Integer) request.argument;
810 uiccPort.onLogicalChannelClosed(channelId);
811 }
Chen Xu540470b2021-12-14 17:15:47 -0800812 } else {
813 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800814 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800815 if (ar.exception instanceof CommandException) {
816 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
817 CommandException.Error error =
818 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800819 if (error == CommandException.Error.INVALID_ARGUMENTS) {
820 // should only throw exceptions from the binder threads.
821 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800822 "iccCloseLogicalChannel: invalid argument ");
823 }
824 } else {
825 loge("iccCloseLogicalChannel: Unknown exception");
826 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800827 request.result = (exception != null) ? exception :
828 new IllegalStateException(
829 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800830 }
831 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800832 break;
833
834 case CMD_NV_READ_ITEM:
835 request = (MainThreadRequest) msg.obj;
836 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800837 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
838 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800839 break;
840
841 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700842 ar = (AsyncResult) msg.obj;
843 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800844 if (ar.exception == null && ar.result != null) {
845 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700846 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800847 request.result = "";
848 if (ar.result == null) {
849 loge("nvReadItem: Empty response");
850 } else if (ar.exception instanceof CommandException) {
851 loge("nvReadItem: CommandException: " +
852 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700853 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800854 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700855 }
856 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700857 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700858 break;
859
Jake Hambye994d462014-02-03 13:10:13 -0800860 case CMD_NV_WRITE_ITEM:
861 request = (MainThreadRequest) msg.obj;
862 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
863 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800864 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700865 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800866 break;
867
868 case EVENT_NV_WRITE_ITEM_DONE:
869 handleNullReturnEvent(msg, "nvWriteItem");
870 break;
871
872 case CMD_NV_WRITE_CDMA_PRL:
873 request = (MainThreadRequest) msg.obj;
874 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800875 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800876 break;
877
878 case EVENT_NV_WRITE_CDMA_PRL_DONE:
879 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
880 break;
881
chen xu6dac5ab2018-10-26 17:39:23 -0700882 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800883 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700884 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800885 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800886 break;
887
chen xu6dac5ab2018-10-26 17:39:23 -0700888 case EVENT_RESET_MODEM_CONFIG_DONE:
889 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800890 break;
891
Sooraj Sasindran37444802020-08-11 10:40:43 -0700892 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
893 request = (MainThreadRequest) msg.obj;
894 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
895 request);
896 Phone phone = getPhoneFromRequest(request);
897 if (phone != null) {
898 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
899 } else {
900 loge("isNRDualConnectivityEnabled: No phone object");
901 request.result = false;
902 notifyRequester(request);
903 }
904 break;
905 }
906
907 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
908 ar = (AsyncResult) msg.obj;
909 request = (MainThreadRequest) ar.userObj;
910 if (ar.exception == null && ar.result != null) {
911 request.result = ar.result;
912 } else {
913 // request.result must be set to something non-null
914 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700915 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700916 request.result = ar.result;
917 } else {
918 request.result = false;
919 }
920 if (ar.result == null) {
921 loge("isNRDualConnectivityEnabled: Empty response");
922 } else if (ar.exception instanceof CommandException) {
923 loge("isNRDualConnectivityEnabled: CommandException: "
924 + ar.exception);
925 } else {
926 loge("isNRDualConnectivityEnabled: Unknown exception");
927 }
928 }
929 notifyRequester(request);
930 break;
931
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700932 case CMD_IS_VONR_ENABLED: {
933 request = (MainThreadRequest) msg.obj;
934 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
935 request);
936 Phone phone = getPhoneFromRequest(request);
937 if (phone != null) {
938 phone.isVoNrEnabled(onCompleted, request.workSource);
939 } else {
940 loge("isVoNrEnabled: No phone object");
941 request.result = false;
942 notifyRequester(request);
943 }
944 break;
945 }
946
947 case EVENT_IS_VONR_ENABLED_DONE:
948 ar = (AsyncResult) msg.obj;
949 request = (MainThreadRequest) ar.userObj;
950 if (ar.exception == null && ar.result != null) {
951 request.result = ar.result;
952 } else {
953 // request.result must be set to something non-null
954 // for the calling thread to unblock
955 if (ar.result != null) {
956 request.result = ar.result;
957 } else {
958 request.result = false;
959 }
960 if (ar.result == null) {
961 loge("isVoNrEnabled: Empty response");
962 } else if (ar.exception instanceof CommandException) {
963 loge("isVoNrEnabled: CommandException: "
964 + ar.exception);
965 } else {
966 loge("isVoNrEnabled: Unknown exception");
967 }
968 }
969 notifyRequester(request);
970 break;
971
Sooraj Sasindran37444802020-08-11 10:40:43 -0700972 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
973 request = (MainThreadRequest) msg.obj;
974 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
975 Phone phone = getPhoneFromRequest(request);
976 if (phone != null) {
977 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
978 request.workSource);
979 } else {
980 loge("enableNrDualConnectivity: No phone object");
981 request.result =
982 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
983 notifyRequester(request);
984 }
985 break;
986 }
987
988 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
989 ar = (AsyncResult) msg.obj;
990 request = (MainThreadRequest) ar.userObj;
991 if (ar.exception == null) {
992 request.result =
993 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
994 } else {
995 request.result =
996 TelephonyManager
997 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
998 if (ar.exception instanceof CommandException) {
999 CommandException.Error error =
1000 ((CommandException) (ar.exception)).getCommandError();
1001 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1002 request.result =
1003 TelephonyManager
1004 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001005 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1006 request.result =
1007 TelephonyManager
1008 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001009 }
1010 loge("enableNrDualConnectivity" + ": CommandException: "
1011 + ar.exception);
1012 } else {
1013 loge("enableNrDualConnectivity" + ": Unknown exception");
1014 }
1015 }
1016 notifyRequester(request);
1017 break;
1018 }
1019
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001020 case CMD_ENABLE_VONR: {
1021 request = (MainThreadRequest) msg.obj;
1022 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1023 Phone phone = getPhoneFromRequest(request);
1024 if (phone != null) {
1025 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1026 request.workSource);
1027 } else {
1028 loge("setVoNrEnabled: No phone object");
1029 request.result =
1030 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1031 notifyRequester(request);
1032 }
1033 break;
1034 }
1035
1036 case EVENT_ENABLE_VONR_DONE: {
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
1039 if (ar.exception == null) {
1040 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1041 } else {
1042 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1043 if (ar.exception instanceof CommandException) {
1044 CommandException.Error error =
1045 ((CommandException) (ar.exception)).getCommandError();
1046 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1047 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1048 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1049 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1050 } else {
1051 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1052 }
1053 loge("setVoNrEnabled" + ": CommandException: "
1054 + ar.exception);
1055 } else {
1056 loge("setVoNrEnabled" + ": Unknown exception");
1057 }
1058 }
1059 notifyRequester(request);
1060 break;
1061 }
1062
SongFerngWang3ef3e072020-12-21 16:41:52 +08001063 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001064 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001065 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1066 request);
1067 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001068 break;
1069
SongFerngWang3ef3e072020-12-21 16:41:52 +08001070 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001071 ar = (AsyncResult) msg.obj;
1072 request = (MainThreadRequest) ar.userObj;
1073 if (ar.exception == null && ar.result != null) {
1074 request.result = ar.result; // Integer
1075 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301076 // request.result must be set to something non-null
1077 // for the calling thread to unblock
1078 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001079 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001080 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001081 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001082 loge("getAllowedNetworkTypesBitmask: CommandException: "
1083 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001084 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001085 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001086 }
1087 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001088 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001089 break;
1090
SongFerngWang3ef3e072020-12-21 16:41:52 +08001091 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001092 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001093 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1094 request);
1095 Pair<Integer, Long> reasonWithNetworkTypes =
1096 (Pair<Integer, Long>) request.argument;
1097 getPhoneFromRequest(request).setAllowedNetworkTypes(
1098 reasonWithNetworkTypes.first,
1099 reasonWithNetworkTypes.second,
1100 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001101 break;
1102
SongFerngWang3ef3e072020-12-21 16:41:52 +08001103 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1104 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001105 break;
1106
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001107 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1108 request = (MainThreadRequest)msg.obj;
1109 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001110 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001111 break;
1112
1113 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1114 ar = (AsyncResult)msg.obj;
1115 request = (MainThreadRequest)ar.userObj;
1116 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001117 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001118 break;
1119
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001120 case CMD_SET_VOICEMAIL_NUMBER:
1121 request = (MainThreadRequest) msg.obj;
1122 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1123 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001124 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1125 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001126 break;
1127
1128 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1129 handleNullReturnEvent(msg, "setVoicemailNumber");
1130 break;
1131
Stuart Scott54788802015-03-30 13:18:01 -07001132 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1133 request = (MainThreadRequest) msg.obj;
1134 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1135 request);
1136 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1137 break;
1138
1139 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1140 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1141 break;
1142
Shishir Agrawal302c8692015-06-19 13:49:39 -07001143 case CMD_PERFORM_NETWORK_SCAN:
1144 request = (MainThreadRequest) msg.obj;
1145 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1146 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1147 break;
1148
Hall Liu27d24262020-09-18 19:04:59 -07001149 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001150 request = (MainThreadRequest) msg.obj;
1151 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001152 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1153 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1154 request.argument;
1155 int callForwardingReason = args.first;
1156 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001157 break;
Hall Liu27d24262020-09-18 19:04:59 -07001158 }
1159 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001160 ar = (AsyncResult) msg.obj;
1161 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001162 TelephonyManager.CallForwardingInfoCallback callback =
1163 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1164 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001165 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001166 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001167 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1168 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1169 // Service Class is a bit mask per 3gpp 27.007. Search for
1170 // any service for voice call.
1171 if ((callForwardInfo.serviceClass
1172 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001173 callForwardingInfo = new CallForwardingInfo(
1174 callForwardInfo.status
1175 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001176 callForwardInfo.reason,
1177 callForwardInfo.number,
1178 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001179 break;
1180 }
1181 }
1182 // Didn't find a call forward info for voice call.
1183 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001184 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1185 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001186 }
Hall Liu27d24262020-09-18 19:04:59 -07001187 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001188 } else {
1189 if (ar.result == null) {
1190 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1191 }
1192 if (ar.exception != null) {
1193 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1194 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001195 int errorCode = TelephonyManager
1196 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001197 if (ar.exception instanceof CommandException) {
1198 CommandException.Error error =
1199 ((CommandException) (ar.exception)).getCommandError();
1200 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001201 errorCode = TelephonyManager
1202 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001203 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001204 errorCode = TelephonyManager
1205 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001206 }
1207 }
Hall Liu27d24262020-09-18 19:04:59 -07001208 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001209 }
Shuo Qian4a594052020-01-23 11:59:30 -08001210 break;
Hall Liu27d24262020-09-18 19:04:59 -07001211 }
Shuo Qian4a594052020-01-23 11:59:30 -08001212
Hall Liu27d24262020-09-18 19:04:59 -07001213 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001214 request = (MainThreadRequest) msg.obj;
1215 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001216 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001217 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001218 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1219 request.argument).first;
1220 request.phone.setCallForwardingOption(
1221 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001222 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001223 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001224 callForwardingInfoToSet.getReason(),
1225 callForwardingInfoToSet.getNumber(),
1226 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1227 break;
Hall Liu27d24262020-09-18 19:04:59 -07001228 }
Shuo Qian4a594052020-01-23 11:59:30 -08001229
Hall Liu27d24262020-09-18 19:04:59 -07001230 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001231 ar = (AsyncResult) msg.obj;
1232 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001233 Consumer<Integer> callback =
1234 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1235 request.argument).second;
1236 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001237 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001238 int errorCode = TelephonyManager.CallForwardingInfoCallback
1239 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001240 if (ar.exception instanceof CommandException) {
1241 CommandException.Error error =
1242 ((CommandException) (ar.exception)).getCommandError();
1243 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001244 errorCode = TelephonyManager.CallForwardingInfoCallback
1245 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001246 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001247 errorCode = TelephonyManager.CallForwardingInfoCallback
1248 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001249 }
1250 }
1251 callback.accept(errorCode);
1252 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001253 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001254 }
Shuo Qian4a594052020-01-23 11:59:30 -08001255 break;
Hall Liu27d24262020-09-18 19:04:59 -07001256 }
Shuo Qian4a594052020-01-23 11:59:30 -08001257
Hall Liu27d24262020-09-18 19:04:59 -07001258 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001259 request = (MainThreadRequest) msg.obj;
1260 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1261 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1262 break;
Hall Liu27d24262020-09-18 19:04:59 -07001263 }
Shuo Qian4a594052020-01-23 11:59:30 -08001264
Hall Liu27d24262020-09-18 19:04:59 -07001265 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001266 ar = (AsyncResult) msg.obj;
1267 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001268 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001269 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001270 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001271 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001272 // Service Class is a bit mask per 3gpp 27.007.
1273 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001274 if (callForwardResults.length > 1
1275 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001276 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001277 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001278 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1279 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001280 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001281 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001282 }
1283 } else {
1284 if (ar.result == null) {
1285 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1286 }
1287 if (ar.exception != null) {
1288 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1289 }
1290 if (ar.exception instanceof CommandException) {
1291 CommandException.Error error =
1292 ((CommandException) (ar.exception)).getCommandError();
1293 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001294 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001295 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001296 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1297 callWaitingStatus =
1298 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001299 }
1300 }
1301 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001302 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001303 break;
Hall Liu27d24262020-09-18 19:04:59 -07001304 }
Shuo Qian4a594052020-01-23 11:59:30 -08001305
Hall Liu27d24262020-09-18 19:04:59 -07001306 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001307 request = (MainThreadRequest) msg.obj;
1308 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001309 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1310 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001311 break;
Hall Liu27d24262020-09-18 19:04:59 -07001312 }
Shuo Qian4a594052020-01-23 11:59:30 -08001313
Hall Liu27d24262020-09-18 19:04:59 -07001314 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001315 ar = (AsyncResult) msg.obj;
1316 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001317 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1318 Consumer<Integer> callback =
1319 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1320 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001321 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001322 if (ar.exception instanceof CommandException) {
1323 CommandException.Error error =
1324 ((CommandException) (ar.exception)).getCommandError();
1325 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1326 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001327 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1328 callback.accept(
1329 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001330 } else {
1331 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1332 }
1333 } else {
1334 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1335 }
1336 } else {
1337 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1338 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001339 }
Shuo Qian4a594052020-01-23 11:59:30 -08001340 break;
Hall Liu27d24262020-09-18 19:04:59 -07001341 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001342 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1343 ar = (AsyncResult) msg.obj;
1344 request = (MainThreadRequest) ar.userObj;
1345 CellNetworkScanResult cellScanResult;
1346 if (ar.exception == null && ar.result != null) {
1347 cellScanResult = new CellNetworkScanResult(
1348 CellNetworkScanResult.STATUS_SUCCESS,
1349 (List<OperatorInfo>) ar.result);
1350 } else {
1351 if (ar.result == null) {
1352 loge("getCellNetworkScanResults: Empty response");
1353 }
1354 if (ar.exception != null) {
1355 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1356 }
1357 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1358 if (ar.exception instanceof CommandException) {
1359 CommandException.Error error =
1360 ((CommandException) (ar.exception)).getCommandError();
1361 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1362 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1363 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1364 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1365 }
1366 }
1367 cellScanResult = new CellNetworkScanResult(errorCode, null);
1368 }
1369 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001370 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001371 break;
1372
1373 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1374 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001375 ManualNetworkSelectionArgument selArg =
1376 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001377 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1378 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001379 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1380 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001381 break;
1382
1383 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001384 ar = (AsyncResult) msg.obj;
1385 request = (MainThreadRequest) ar.userObj;
1386 if (ar.exception == null) {
1387 request.result = true;
1388 } else {
1389 request.result = false;
1390 loge("setNetworkSelectionModeManual " + ar.exception);
1391 }
1392 notifyRequester(request);
1393 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001394 break;
1395
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001396 case CMD_GET_MODEM_ACTIVITY_INFO:
1397 request = (MainThreadRequest) msg.obj;
1398 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001399 if (defaultPhone != null) {
1400 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001401 } else {
1402 ResultReceiver result = (ResultReceiver) request.argument;
1403 Bundle bundle = new Bundle();
1404 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001405 new ModemActivityInfo(0, 0, 0,
1406 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001407 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001408 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001409 break;
1410
Hall Liud0f208c2020-10-14 16:54:44 -07001411 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001412 ar = (AsyncResult) msg.obj;
1413 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001414 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001415 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001416 if (mLastModemActivityInfo == null) {
1417 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1418 mLastModemActivitySpecificInfo[0] =
1419 new ActivityStatsTechSpecificInfo(
1420 0,
1421 0,
1422 new int[ModemActivityInfo.getNumTxPowerLevels()],
1423 0);
1424 mLastModemActivityInfo =
1425 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1426 }
1427
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001428 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001429 // Update the last modem activity info and the result of the request.
1430 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1431 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001432 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001433 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001434 mLastModemActivityInfo =
1435 new ModemActivityInfo(
1436 mLastModemActivityInfo.getTimestampMillis(),
1437 mLastModemActivityInfo.getSleepTimeMillis(),
1438 mLastModemActivityInfo.getIdleTimeMillis(),
1439 mLastModemActivitySpecificInfo);
1440
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001441 } else {
1442 if (ar.result == null) {
1443 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001444 error = TelephonyManager.ModemActivityInfoException
1445 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001446 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001447 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001448 error = TelephonyManager.ModemActivityInfoException
1449 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001450 } else {
1451 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001452 error = TelephonyManager.ModemActivityInfoException
1453 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001454 }
1455 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001456 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001457 if (mLastModemActivityInfo != null) {
1458 bundle.putParcelable(
1459 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1460 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001461 } else {
1462 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1463 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001464 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001465 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001466 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001467 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468
Meng Wang1a7c35a2016-05-05 20:56:15 -07001469 case CMD_SET_ALLOWED_CARRIERS:
1470 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001471 CarrierRestrictionRules argument =
1472 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001473 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001474 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001475 break;
1476
1477 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1478 ar = (AsyncResult) msg.obj;
1479 request = (MainThreadRequest) ar.userObj;
1480 if (ar.exception == null && ar.result != null) {
1481 request.result = ar.result;
1482 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001483 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1484 if (ar.exception instanceof CommandException) {
1485 loge("setAllowedCarriers: CommandException: " + ar.exception);
1486 CommandException.Error error =
1487 ((CommandException) (ar.exception)).getCommandError();
1488 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1489 request.result =
1490 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1491 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001492 } else {
1493 loge("setAllowedCarriers: Unknown exception");
1494 }
1495 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001496 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001497 break;
1498
1499 case CMD_GET_ALLOWED_CARRIERS:
1500 request = (MainThreadRequest) msg.obj;
1501 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001502 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001503 break;
1504
1505 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1506 ar = (AsyncResult) msg.obj;
1507 request = (MainThreadRequest) ar.userObj;
1508 if (ar.exception == null && ar.result != null) {
1509 request.result = ar.result;
1510 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001511 request.result = new IllegalStateException(
1512 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001513 if (ar.result == null) {
1514 loge("getAllowedCarriers: Empty response");
1515 } else if (ar.exception instanceof CommandException) {
1516 loge("getAllowedCarriers: CommandException: " +
1517 ar.exception);
1518 } else {
1519 loge("getAllowedCarriers: Unknown exception");
1520 }
1521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001522 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001523 break;
1524
Nathan Haroldb3014052017-01-25 15:57:32 -08001525 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1526 ar = (AsyncResult) msg.obj;
1527 request = (MainThreadRequest) ar.userObj;
1528 if (ar.exception == null && ar.result != null) {
1529 request.result = ar.result;
1530 } else {
1531 request.result = new IllegalArgumentException(
1532 "Failed to retrieve Forbidden Plmns");
1533 if (ar.result == null) {
1534 loge("getForbiddenPlmns: Empty response");
1535 } else {
1536 loge("getForbiddenPlmns: Unknown exception");
1537 }
1538 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001539 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001540 break;
1541
1542 case CMD_GET_FORBIDDEN_PLMNS:
1543 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001544 uiccPort = getUiccPortFromRequest(request);
1545 if (uiccPort == null) {
1546 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001547 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001548 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001549 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001550 break;
1551 }
1552 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001553 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001554 if (uiccApp == null) {
1555 loge("getForbiddenPlmns() no app with specified type -- "
1556 + appType);
1557 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001558 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001559 break;
1560 } else {
1561 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1562 + " specified type -- " + appType);
1563 }
1564 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1565 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1566 onCompleted);
1567 break;
1568
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001569 case CMD_SWITCH_SLOTS:
1570 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001571 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001572 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001573 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001574 break;
1575
1576 case EVENT_SWITCH_SLOTS_DONE:
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001580 notifyRequester(request);
1581 break;
1582 case CMD_GET_NETWORK_SELECTION_MODE:
1583 request = (MainThreadRequest) msg.obj;
1584 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1585 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1586 break;
1587
1588 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1589 ar = (AsyncResult) msg.obj;
1590 request = (MainThreadRequest) ar.userObj;
1591 if (ar.exception != null) {
1592 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1593 } else {
1594 int mode = ((int[]) ar.result)[0];
1595 if (mode == 0) {
1596 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1597 } else {
1598 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1599 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001600 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001601 notifyRequester(request);
1602 break;
1603 case CMD_GET_CDMA_ROAMING_MODE:
1604 request = (MainThreadRequest) msg.obj;
1605 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1606 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1607 break;
1608 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1609 ar = (AsyncResult) msg.obj;
1610 request = (MainThreadRequest) ar.userObj;
1611 if (ar.exception != null) {
1612 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1613 } else {
1614 request.result = ((int[]) ar.result)[0];
1615 }
1616 notifyRequester(request);
1617 break;
1618 case CMD_SET_CDMA_ROAMING_MODE:
1619 request = (MainThreadRequest) msg.obj;
1620 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1621 int mode = (int) request.argument;
1622 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1623 break;
1624 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1625 ar = (AsyncResult) msg.obj;
1626 request = (MainThreadRequest) ar.userObj;
1627 request.result = ar.exception == null;
1628 notifyRequester(request);
1629 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001630 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1631 request = (MainThreadRequest) msg.obj;
1632 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1633 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1634 break;
1635 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1636 ar = (AsyncResult) msg.obj;
1637 request = (MainThreadRequest) ar.userObj;
1638 if (ar.exception != null) {
1639 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1640 } else {
1641 request.result = ((int[]) ar.result)[0];
1642 }
1643 notifyRequester(request);
1644 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001645 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1646 request = (MainThreadRequest) msg.obj;
1647 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1648 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001649 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1650 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001651 break;
1652 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1653 ar = (AsyncResult) msg.obj;
1654 request = (MainThreadRequest) ar.userObj;
1655 request.result = ar.exception == null;
1656 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001657 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 case CMD_GET_ALL_CELL_INFO:
1659 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001660 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001661 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001662 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001663 case EVENT_GET_ALL_CELL_INFO_DONE:
1664 ar = (AsyncResult) msg.obj;
1665 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001666 // If a timeout occurs, the response will be null
1667 request.result = (ar.exception == null && ar.result != null)
1668 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001669 synchronized (request) {
1670 request.notifyAll();
1671 }
1672 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001673 case CMD_REQUEST_CELL_INFO_UPDATE:
1674 request = (MainThreadRequest) msg.obj;
1675 request.phone.requestCellInfoUpdate(request.workSource,
1676 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1677 break;
1678 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1679 ar = (AsyncResult) msg.obj;
1680 request = (MainThreadRequest) ar.userObj;
1681 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1682 try {
1683 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001684 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001685 cb.onError(
1686 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1687 ar.exception.getClass().getName(),
1688 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001689 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001690 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001691 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001692 } else {
1693 // use the result as returned
1694 cb.onCellInfo((List<CellInfo>) ar.result);
1695 }
1696 } catch (RemoteException re) {
1697 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1698 }
1699 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001700 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001701 request = (MainThreadRequest) msg.obj;
1702 WorkSource ws = (WorkSource) request.argument;
1703 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001704 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001705 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001706 }
1707 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001708 ar = (AsyncResult) msg.obj;
1709 request = (MainThreadRequest) ar.userObj;
1710 if (ar.exception == null) {
1711 request.result = ar.result;
1712 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001713 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001714 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001715 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001716 }
1717
1718 synchronized (request) {
1719 request.notifyAll();
1720 }
1721 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001722 }
chen xu6dac5ab2018-10-26 17:39:23 -07001723 case CMD_MODEM_REBOOT:
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001726 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001727 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001728 case EVENT_CMD_MODEM_REBOOT_DONE:
1729 handleNullReturnEvent(msg, "rebootModem");
1730 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001731 case CMD_REQUEST_ENABLE_MODEM:
1732 request = (MainThreadRequest) msg.obj;
1733 boolean enable = (boolean) request.argument;
1734 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001735 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001736 PhoneConfigurationManager.getInstance()
1737 .enablePhone(request.phone, enable, onCompleted);
1738 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001739 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001740 ar = (AsyncResult) msg.obj;
1741 request = (MainThreadRequest) ar.userObj;
1742 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001743 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001744 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001745 if ((boolean) request.result) {
1746 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1747 updateModemStateMetrics();
1748 } else {
1749 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1750 + ar.exception);
1751 }
1752 notifyRequester(request);
1753 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001754 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001755 case CMD_GET_MODEM_STATUS:
1756 request = (MainThreadRequest) msg.obj;
1757 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1758 PhoneConfigurationManager.getInstance()
1759 .getPhoneStatusFromModem(request.phone, onCompleted);
1760 break;
1761 case EVENT_GET_MODEM_STATUS_DONE:
1762 ar = (AsyncResult) msg.obj;
1763 request = (MainThreadRequest) ar.userObj;
1764 int id = request.phone.getPhoneId();
1765 if (ar.exception == null && ar.result != null) {
1766 request.result = ar.result;
1767 //update the cache as modem status has changed
1768 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1769 (boolean) request.result);
1770 } else {
1771 // Return true if modem status cannot be retrieved. For most cases,
1772 // modem status is on. And for older version modems, GET_MODEM_STATUS
1773 // and disable modem are not supported. Modem is always on.
1774 // TODO: this should be fixed in R to support a third
1775 // status UNKNOWN b/131631629
1776 request.result = true;
1777 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1778 + ar.exception);
1779 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001780 notifyRequester(request);
1781 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001782 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1783 request = (MainThreadRequest) msg.obj;
1784 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1785 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1786 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1787 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1788 break;
1789 }
1790 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1791 ar = (AsyncResult) msg.obj;
1792 request = (MainThreadRequest) ar.userObj;
1793 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1794 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1795 args.second.accept(ar.exception == null);
1796 notifyRequester(request);
1797 break;
1798 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001799 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1800 request = (MainThreadRequest) msg.obj;
1801 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1802 Phone phone = getPhoneFromRequest(request);
1803 if (phone != null) {
1804 phone.getSystemSelectionChannels(onCompleted);
1805 } else {
1806 loge("getSystemSelectionChannels: No phone object");
1807 request.result = new ArrayList<RadioAccessSpecifier>();
1808 notifyRequester(request);
1809 }
1810 break;
1811 }
1812 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1813 ar = (AsyncResult) msg.obj;
1814 request = (MainThreadRequest) ar.userObj;
1815 if (ar.exception == null && ar.result != null) {
1816 request.result = ar.result;
1817 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001818 request.result = new IllegalStateException(
1819 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001820 if (ar.result == null) {
1821 loge("getSystemSelectionChannels: Empty response");
1822 } else {
1823 loge("getSystemSelectionChannels: Unknown exception");
1824 }
1825 }
1826 notifyRequester(request);
1827 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001828 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1829 ar = (AsyncResult) msg.obj;
1830 request = (MainThreadRequest) ar.userObj;
1831 if (ar.exception == null && ar.result != null) {
1832 request.result = ar.result;
1833 } else {
1834 request.result = -1;
1835 loge("Failed to set Forbidden Plmns");
1836 if (ar.result == null) {
1837 loge("setForbidenPlmns: Empty response");
1838 } else if (ar.exception != null) {
1839 loge("setForbiddenPlmns: Exception: " + ar.exception);
1840 request.result = -1;
1841 } else {
1842 loge("setForbiddenPlmns: Unknown exception");
1843 }
1844 }
1845 notifyRequester(request);
1846 break;
1847 case CMD_SET_FORBIDDEN_PLMNS:
1848 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001849 uiccPort = getUiccPortFromRequest(request);
1850 if (uiccPort == null) {
1851 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001852 request.result = -1;
1853 notifyRequester(request);
1854 break;
1855 }
1856 Pair<Integer, List<String>> setFplmnsArgs =
1857 (Pair<Integer, List<String>>) request.argument;
1858 appType = setFplmnsArgs.first;
1859 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001860 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001861 if (uiccApp == null) {
1862 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1863 request.result = -1;
1864 loge("Failed to get UICC App");
1865 notifyRequester(request);
1866 } else {
1867 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1868 ((SIMRecords) uiccApp.getIccRecords())
1869 .setForbiddenPlmns(onCompleted, fplmns);
1870 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001871 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001872 case CMD_ERASE_MODEM_CONFIG:
1873 request = (MainThreadRequest) msg.obj;
1874 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1875 defaultPhone.eraseModemConfig(onCompleted);
1876 break;
1877 case EVENT_ERASE_MODEM_CONFIG_DONE:
1878 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001879 break;
zoey chene02881a2019-12-30 16:11:23 +08001880
Kai Shif70f46f2021-03-03 13:59:46 -08001881 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1882 request = (MainThreadRequest) msg.obj;
1883 request.result = defaultPhone.eraseDataInSharedPreferences();
1884 notifyRequester(request);
1885 break;
1886
zoey chene02881a2019-12-30 16:11:23 +08001887 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1888 request = (MainThreadRequest) msg.obj;
1889 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1890 Pair<String, String> changed = (Pair<String, String>) request.argument;
1891 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1892 changed.first, changed.second, onCompleted);
1893 break;
1894 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1895 ar = (AsyncResult) msg.obj;
1896 request = (MainThreadRequest) ar.userObj;
1897 if (ar.exception == null) {
1898 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001899 // If the operation is successful, update the PIN storage
1900 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1901 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001902 UiccController.getInstance().getPinStorage()
1903 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001904 } else {
1905 request.result = msg.arg1;
1906 }
1907 notifyRequester(request);
1908 break;
1909
Michele Berionne5e411512020-11-13 02:36:59 +00001910 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001911 request = (MainThreadRequest) msg.obj;
1912 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1913 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1914 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1915 enabled.first, enabled.second, onCompleted);
1916 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001917 }
zoey chene02881a2019-12-30 16:11:23 +08001918 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1919 ar = (AsyncResult) msg.obj;
1920 request = (MainThreadRequest) ar.userObj;
1921 if (ar.exception == null) {
1922 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001923 // If the operation is successful, update the PIN storage
1924 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1925 int phoneId = getPhoneFromRequest(request).getPhoneId();
1926 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001927 UiccController.getInstance().getPinStorage()
1928 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001929 } else {
1930 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1931 }
zoey chene02881a2019-12-30 16:11:23 +08001932 } else {
1933 request.result = msg.arg1;
1934 }
Michele Berionne5e411512020-11-13 02:36:59 +00001935
1936
zoey chene02881a2019-12-30 16:11:23 +08001937 notifyRequester(request);
1938 break;
1939
Peter Wangdafb9ac2020-01-15 14:13:38 -08001940 case MSG_NOTIFY_USER_ACTIVITY:
1941 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001942 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001943 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1944 getDefaultPhone().getContext().sendBroadcastAsUser(
1945 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1946 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001947
1948 case CMD_SET_DATA_THROTTLING: {
1949 request = (MainThreadRequest) msg.obj;
1950 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1951 DataThrottlingRequest dataThrottlingRequest =
1952 (DataThrottlingRequest) request.argument;
1953 Phone phone = getPhoneFromRequest(request);
1954 if (phone != null) {
1955 phone.setDataThrottling(onCompleted,
1956 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1957 dataThrottlingRequest.getCompletionDurationMillis());
1958 } else {
1959 loge("setDataThrottling: No phone object");
1960 request.result =
1961 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1962 notifyRequester(request);
1963 }
1964
1965 break;
1966 }
1967 case EVENT_SET_DATA_THROTTLING_DONE:
1968 ar = (AsyncResult) msg.obj;
1969 request = (MainThreadRequest) ar.userObj;
1970
1971 if (ar.exception == null) {
1972 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1973 } else if (ar.exception instanceof CommandException) {
1974 loge("setDataThrottling: CommandException: " + ar.exception);
1975 CommandException.Error error =
1976 ((CommandException) (ar.exception)).getCommandError();
1977
1978 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1979 request.result = TelephonyManager
1980 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1981 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1982 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001983 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1984 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001985 } else {
1986 request.result =
1987 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1988 }
1989 } else {
1990 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1991 }
1992 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1993 notifyRequester(request);
1994 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001995
1996 case CMD_SET_SIM_POWER: {
1997 request = (MainThreadRequest) msg.obj;
1998 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1999 request = (MainThreadRequest) msg.obj;
2000 int stateToSet =
2001 ((Pair<Integer, IIntegerConsumer>)
2002 request.argument).first;
2003 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2004 break;
2005 }
2006 case EVENT_SET_SIM_POWER_DONE: {
2007 ar = (AsyncResult) msg.obj;
2008 request = (MainThreadRequest) ar.userObj;
2009 IIntegerConsumer callback =
2010 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2011 if (ar.exception != null) {
2012 loge("setSimPower exception: " + ar.exception);
2013 int errorCode = TelephonyManager.CallForwardingInfoCallback
2014 .RESULT_ERROR_UNKNOWN;
2015 if (ar.exception instanceof CommandException) {
2016 CommandException.Error error =
2017 ((CommandException) (ar.exception)).getCommandError();
2018 if (error == CommandException.Error.SIM_ERR) {
2019 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2020 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2021 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2022 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2023 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2024 } else {
2025 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2026 }
2027 }
2028 try {
2029 callback.accept(errorCode);
2030 } catch (RemoteException e) {
2031 // Ignore if the remote process is no longer available to call back.
2032 Log.w(LOG_TAG, "setSimPower: callback not available.");
2033 }
2034 } else {
2035 try {
2036 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2037 } catch (RemoteException e) {
2038 // Ignore if the remote process is no longer available to call back.
2039 Log.w(LOG_TAG, "setSimPower: callback not available.");
2040 }
2041 }
2042 break;
2043 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002044 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2045 request = (MainThreadRequest) msg.obj;
2046
2047 final Phone phone = getPhoneFromRequest(request);
2048 if (phone == null || phone.getServiceStateTracker() == null) {
2049 request.result = new IllegalStateException("Phone or SST is null");
2050 notifyRequester(request);
2051 break;
2052 }
2053
2054 Pair<Integer, SignalStrengthUpdateRequest> pair =
2055 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2056 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2057 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002058 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002059 request.subId, pair.first /*callingUid*/,
2060 pair.second /*request*/, onCompleted);
2061 break;
2062 }
2063 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2064 ar = (AsyncResult) msg.obj;
2065 request = (MainThreadRequest) ar.userObj;
2066 // request.result will be the exception of ar if present, true otherwise.
2067 // Be cautious not to leave result null which will wait() forever
2068 request.result = ar.exception != null ? ar.exception : true;
2069 notifyRequester(request);
2070 break;
2071 }
2072 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2073 request = (MainThreadRequest) msg.obj;
2074
2075 Phone phone = getPhoneFromRequest(request);
2076 if (phone == null || phone.getServiceStateTracker() == null) {
2077 request.result = new IllegalStateException("Phone or SST is null");
2078 notifyRequester(request);
2079 break;
2080 }
2081
2082 Pair<Integer, SignalStrengthUpdateRequest> pair =
2083 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2084 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2085 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002086 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002087 request.subId, pair.first /*callingUid*/,
2088 pair.second /*request*/, onCompleted);
2089 break;
2090 }
2091 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2092 ar = (AsyncResult) msg.obj;
2093 request = (MainThreadRequest) ar.userObj;
2094 request.result = ar.exception != null ? ar.exception : true;
2095 notifyRequester(request);
2096 break;
2097 }
Jordan Liu109698e2020-11-24 14:50:34 -08002098
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002099 case CMD_GET_SLICING_CONFIG: {
2100 request = (MainThreadRequest) msg.obj;
2101 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2102 request.phone.getSlicingConfig(onCompleted);
2103 break;
2104 }
2105 case EVENT_GET_SLICING_CONFIG_DONE: {
2106 ar = (AsyncResult) msg.obj;
2107 request = (MainThreadRequest) ar.userObj;
2108 ResultReceiver result = (ResultReceiver) request.argument;
2109
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002110 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002111 Bundle bundle = new Bundle();
2112 int resultCode = 0;
2113 if (ar.exception != null) {
2114 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2115 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002116 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002117 } else if (ar.result == null) {
2118 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002119 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002120 } else {
2121 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002122 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2123 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002124 }
2125
2126 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002127 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002128 }
2129 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2130 result.send(resultCode, bundle);
2131 notifyRequester(request);
2132 break;
2133 }
2134
Michele Berionne5e411512020-11-13 02:36:59 +00002135 case CMD_PREPARE_UNATTENDED_REBOOT:
2136 request = (MainThreadRequest) msg.obj;
2137 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002138 UiccController.getInstance().getPinStorage()
2139 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002140 notifyRequester(request);
2141 break;
2142
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 default:
2144 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2145 break;
2146 }
2147 }
Jake Hambye994d462014-02-03 13:10:13 -08002148
Pengquan Menga1bb6272018-09-06 09:59:22 -07002149 private void notifyRequester(MainThreadRequest request) {
2150 synchronized (request) {
2151 request.notifyAll();
2152 }
2153 }
2154
Jake Hambye994d462014-02-03 13:10:13 -08002155 private void handleNullReturnEvent(Message msg, String command) {
2156 AsyncResult ar = (AsyncResult) msg.obj;
2157 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2158 if (ar.exception == null) {
2159 request.result = true;
2160 } else {
2161 request.result = false;
2162 if (ar.exception instanceof CommandException) {
2163 loge(command + ": CommandException: " + ar.exception);
2164 } else {
2165 loge(command + ": Unknown exception");
2166 }
2167 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002168 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 }
2171
2172 /**
2173 * Posts the specified command to be executed on the main thread,
2174 * waits for the request to complete, and returns the result.
2175 * @see #sendRequestAsync
2176 */
2177 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002178 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2179 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002180 }
2181
2182 /**
2183 * Posts the specified command to be executed on the main thread,
2184 * waits for the request to complete, and returns the result.
2185 * @see #sendRequestAsync
2186 */
2187 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2188 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002189 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002190 }
2191
2192 /**
2193 * Posts the specified command to be executed on the main thread,
2194 * waits for the request to complete, and returns the result.
2195 * @see #sendRequestAsync
2196 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002197 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002198 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2199 }
2200
2201 /**
2202 * Posts the specified command to be executed on the main thread,
2203 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2204 * if not timeout or null otherwise.
2205 * @see #sendRequestAsync
2206 */
2207 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2208 long timeoutInMs) {
2209 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002210 }
2211
2212 /**
2213 * Posts the specified command to be executed on the main thread,
2214 * waits for the request to complete, and returns the result.
2215 * @see #sendRequestAsync
2216 */
Nathan Harold92bed182018-10-12 18:16:49 -07002217 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002218 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002219 }
2220
2221 /**
2222 * Posts the specified command to be executed on the main thread,
2223 * waits for the request to complete, and returns the result.
2224 * @see #sendRequestAsync
2225 */
2226 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002227 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2228 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002229 }
2230
2231 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002232 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2233 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2234 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002235 * @see #sendRequestAsync
2236 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002237 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2238 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2240 throw new RuntimeException("This method will deadlock if called from the main thread.");
2241 }
2242
Nathan Harold92bed182018-10-12 18:16:49 -07002243 MainThreadRequest request = null;
2244 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2245 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2246 } else if (phone != null) {
2247 request = new MainThreadRequest(argument, phone, workSource);
2248 } else {
2249 request = new MainThreadRequest(argument, subId, workSource);
2250 }
2251
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 Message msg = mMainThreadHandler.obtainMessage(command, request);
2253 msg.sendToTarget();
2254
Rambo Wang0f050d82021-02-12 11:43:36 -08002255
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002257 if (timeoutInMs >= 0) {
2258 // Wait for at least timeoutInMs before returning null request result
2259 long now = SystemClock.elapsedRealtime();
2260 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002261 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002262 try {
2263 request.wait(deadline - now);
2264 } catch (InterruptedException e) {
2265 // Do nothing, go back and check if request is completed or timeout
2266 } finally {
2267 now = SystemClock.elapsedRealtime();
2268 }
2269 }
2270 } else {
2271 // Wait for the request to complete
2272 while (request.result == null) {
2273 try {
2274 request.wait();
2275 } catch (InterruptedException e) {
2276 // Do nothing, go back and wait until the request is complete
2277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 }
2279 }
2280 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002281 if (request.result == null) {
2282 Log.wtf(LOG_TAG,
2283 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 return request.result;
2286 }
2287
2288 /**
2289 * Asynchronous ("fire and forget") version of sendRequest():
2290 * Posts the specified command to be executed on the main thread, and
2291 * returns immediately.
2292 * @see #sendRequest
2293 */
2294 private void sendRequestAsync(int command) {
2295 mMainThreadHandler.sendEmptyMessage(command);
2296 }
2297
2298 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002299 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002300 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002301 */
2302 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002303 sendRequestAsync(command, argument, null, null);
2304 }
2305
2306 /**
2307 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2308 * @see {@link #sendRequest(int,Object)}
2309 */
2310 private void sendRequestAsync(
2311 int command, Object argument, Phone phone, WorkSource workSource) {
2312 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002313 Message msg = mMainThreadHandler.obtainMessage(command, request);
2314 msg.sendToTarget();
2315 }
2316
2317 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 * Initialize the singleton PhoneInterfaceManager instance.
2319 * This is only done once, at startup, from PhoneApp.onCreate().
2320 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002321 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002322 synchronized (PhoneInterfaceManager.class) {
2323 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002324 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 } else {
2326 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2327 }
2328 return sInstance;
2329 }
2330 }
2331
2332 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002333 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002336 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002337 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002339 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002341 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002342 mTelephonySharedPreferences =
2343 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002344 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002345 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002346 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002347 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002348 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 publish();
2350 }
2351
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002352 private Phone getDefaultPhone() {
2353 Phone thePhone = getPhone(getDefaultSubscription());
2354 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2355 }
2356
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 private void publish() {
2358 if (DBG) log("publish: " + this);
2359
Peter Wangc035ce42020-01-08 21:00:22 -08002360 TelephonyFrameworkInitializer
2361 .getTelephonyServiceManager()
2362 .getTelephonyServiceRegisterer()
2363 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 }
2365
Stuart Scott584921c2015-01-15 17:10:34 -08002366 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002367 if (request.phone != null) {
2368 return request.phone;
2369 } else {
2370 return getPhoneFromSubId(request.subId);
2371 }
2372 }
2373
2374 private Phone getPhoneFromSubId(int subId) {
2375 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2376 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002377 }
2378
Rambo Wange53e07d2022-05-10 13:01:13 -07002379 @Nullable
2380 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002381 Phone phone = getPhoneFromRequest(request);
2382 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002383 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002384 }
2385
Wink Saville36469e72014-06-11 15:17:00 -07002386 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002387 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002388 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390
Kai Shif70f46f2021-03-03 13:59:46 -08002391 private void sendEraseModemConfig(@NonNull Phone phone) {
2392 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2393 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2394 }
2395
2396 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2397 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2398 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002399 }
2400
Peter Wang44b186e2020-01-13 23:33:09 -08002401 private boolean isImsAvailableOnDevice() {
2402 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2403 if (pm == null) {
2404 // For some reason package manger is not available.. This will fail internally anyway,
2405 // so do not throw error and allow.
2406 return true;
2407 }
2408 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2409 }
2410
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002412 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002413 }
2414
Wink Savilleb564aae2014-10-23 10:18:09 -07002415 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 if (DBG) log("dial: " + number);
2417 // No permission check needed here: This is just a wrapper around the
2418 // ACTION_DIAL intent, which is available to any app since it puts up
2419 // the UI before it does anything.
2420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002421 final long identity = Binder.clearCallingIdentity();
2422 try {
2423 String url = createTelUrl(number);
2424 if (url == null) {
2425 return;
2426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002428 // PENDING: should we just silently fail if phone is offhook or ringing?
2429 PhoneConstants.State state = mCM.getState(subId);
2430 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2431 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2432 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2433 mApp.startActivity(intent);
2434 }
2435 } finally {
2436 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 }
2438 }
2439
2440 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002441 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002442 }
2443
Wink Savilleb564aae2014-10-23 10:18:09 -07002444 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 if (DBG) log("call: " + number);
2446
2447 // This is just a wrapper around the ACTION_CALL intent, but we still
2448 // need to do a permission check since we're calling startActivity()
2449 // from the context of the phone app.
2450 enforceCallPermission();
2451
Jordan Liu1617b712019-07-10 15:06:26 -07002452 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 != AppOpsManager.MODE_ALLOWED) {
2454 return;
2455 }
2456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457 final long identity = Binder.clearCallingIdentity();
2458 try {
2459 String url = createTelUrl(number);
2460 if (url == null) {
2461 return;
2462 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464 boolean isValid = false;
2465 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2466 if (slist != null) {
2467 for (SubscriptionInfo subInfoRecord : slist) {
2468 if (subInfoRecord.getSubscriptionId() == subId) {
2469 isValid = true;
2470 break;
2471 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002472 }
Wink Saville08874612014-08-31 19:19:58 -07002473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002474 if (!isValid) {
2475 return;
2476 }
Wink Saville08874612014-08-31 19:19:58 -07002477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2479 intent.putExtra(SUBSCRIPTION_KEY, subId);
2480 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2481 mApp.startActivity(intent);
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
2484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
Wink Savilleb564aae2014-10-23 10:18:09 -07002487 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002488 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002489 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2490 }
2491
Wink Savilleb564aae2014-10-23 10:18:09 -07002492 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002493 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002494 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2495 }
2496
Wink Savilleb564aae2014-10-23 10:18:09 -07002497 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002502 Phone phone = getPhone(subId);
2503 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504 checkSimPin.start();
2505 return checkSimPin.unlockSim(null, pin);
2506 } finally {
2507 Binder.restoreCallingIdentity(identity);
2508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 }
2510
Wink Savilleb564aae2014-10-23 10:18:09 -07002511 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513
2514 final long identity = Binder.clearCallingIdentity();
2515 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002516 Phone phone = getPhone(subId);
2517 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002518 checkSimPuk.start();
2519 return checkSimPuk.unlockSim(puk, pin);
2520 } finally {
2521 Binder.restoreCallingIdentity(identity);
2522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 }
2524
2525 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002526 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 * a synchronous one.
2528 */
2529 private static class UnlockSim extends Thread {
2530
2531 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002532 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533
2534 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002535 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2536 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537
2538 // For replies from SimCard interface
2539 private Handler mHandler;
2540
2541 // For async handler to identify request type
2542 private static final int SUPPLY_PIN_COMPLETE = 100;
2543
Michele Berionne5e411512020-11-13 02:36:59 +00002544 UnlockSim(int phoneId, IccCard simCard) {
2545 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 mSimCard = simCard;
2547 }
2548
2549 @Override
2550 public void run() {
2551 Looper.prepare();
2552 synchronized (UnlockSim.this) {
2553 mHandler = new Handler() {
2554 @Override
2555 public void handleMessage(Message msg) {
2556 AsyncResult ar = (AsyncResult) msg.obj;
2557 switch (msg.what) {
2558 case SUPPLY_PIN_COMPLETE:
2559 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2560 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002561 mRetryCount = msg.arg1;
2562 if (ar.exception != null) {
2563 if (ar.exception instanceof CommandException &&
2564 ((CommandException)(ar.exception)).getCommandError()
2565 == CommandException.Error.PASSWORD_INCORRECT) {
2566 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002567 } //When UiccCardApp dispose,handle message and return exception
2568 else if (ar.exception instanceof CommandException &&
2569 ((CommandException) (ar.exception)).getCommandError()
2570 == CommandException.Error.ABORTED) {
2571 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002572 } else {
2573 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2574 }
2575 } else {
2576 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 mDone = true;
2579 UnlockSim.this.notifyAll();
2580 }
2581 break;
2582 }
2583 }
2584 };
2585 UnlockSim.this.notifyAll();
2586 }
2587 Looper.loop();
2588 }
2589
2590 /*
2591 * Use PIN or PUK to unlock SIM card
2592 *
2593 * If PUK is null, unlock SIM card with PIN
2594 *
2595 * If PUK is not null, unlock SIM card with PUK and set PIN code
2596 */
Wink Saville9de0f752013-10-22 19:04:03 -07002597 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598
2599 while (mHandler == null) {
2600 try {
2601 wait();
2602 } catch (InterruptedException e) {
2603 Thread.currentThread().interrupt();
2604 }
2605 }
2606 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2607
2608 if (puk == null) {
2609 mSimCard.supplyPin(pin, callback);
2610 } else {
2611 mSimCard.supplyPuk(puk, pin, callback);
2612 }
2613
2614 while (!mDone) {
2615 try {
2616 Log.d(LOG_TAG, "wait for done");
2617 wait();
2618 } catch (InterruptedException e) {
2619 // Restore the interrupted status
2620 Thread.currentThread().interrupt();
2621 }
2622 }
2623 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002624 int[] resultArray = new int[2];
2625 resultArray[0] = mResult;
2626 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002627
2628 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002629 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002630 }
2631
Wink Saville9de0f752013-10-22 19:04:03 -07002632 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 }
2634 }
2635
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002636 /**
2637 * This method has been removed due to privacy and stability concerns.
2638 */
2639 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002640 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002641 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2642 return;
Wink Saville36469e72014-06-11 15:17:00 -07002643 }
2644
Nathan Harold1f889d82020-06-04 17:05:26 -07002645 @Override
2646 public void updateServiceLocationWithPackageName(String callingPackage) {
2647 mApp.getSystemService(AppOpsManager.class)
2648 .checkPackage(Binder.getCallingUid(), callingPackage);
2649
Nathan Haroldf096d982020-11-18 17:18:06 -08002650 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002651 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2652 // Callers targeting S have no business invoking this method.
2653 return;
2654 }
2655
2656 LocationAccessPolicy.LocationPermissionResult locationResult =
2657 LocationAccessPolicy.checkLocationPermission(mApp,
2658 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2659 .setCallingPackage(callingPackage)
2660 .setCallingFeatureId(null)
2661 .setCallingPid(Binder.getCallingPid())
2662 .setCallingUid(Binder.getCallingUid())
2663 .setMethod("updateServiceLocation")
2664 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2665 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2666 .build());
2667 // Apps that lack location permission have no business calling this method;
2668 // however, because no permission was declared in the public API, denials must
2669 // all be "soft".
2670 switch (locationResult) {
2671 case DENIED_HARD: /* fall through */
2672 case DENIED_SOFT:
2673 return;
2674 }
2675
2676 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002677 final long identity = Binder.clearCallingIdentity();
2678 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002679 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002681 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682 }
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 }
2687
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002688 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002689 @Override
2690 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002691 return isRadioOnWithFeature(callingPackage, null);
2692 }
2693
2694
2695 @Override
2696 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2697 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2698 callingFeatureId);
2699 }
2700
2701 @Deprecated
2702 @Override
2703 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2704 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002705 }
2706
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002707 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002708 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2709 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002710 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002711 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002712 return false;
2713 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714
2715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 return isRadioOnForSubscriber(subId);
2718 } finally {
2719 Binder.restoreCallingIdentity(identity);
2720 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002721 }
2722
2723 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 final Phone phone = getPhone(subId);
2727 if (phone != null) {
2728 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2729 } else {
2730 return false;
2731 }
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 }
2736
2737 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002738 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 }
Wink Saville36469e72014-06-11 15:17:00 -07002740
Wink Savilleb564aae2014-10-23 10:18:09 -07002741 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743
2744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 final Phone phone = getPhone(subId);
2747 if (phone != null) {
2748 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2749 }
2750 } finally {
2751 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002752 }
Wink Saville36469e72014-06-11 15:17:00 -07002753 }
2754
2755 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002756 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002757 }
2758
Wink Savilleb564aae2014-10-23 10:18:09 -07002759 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761
2762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 final Phone phone = getPhone(subId);
2765 if (phone == null) {
2766 return false;
2767 }
2768 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2769 toggleRadioOnOffForSubscriber(subId);
2770 }
2771 return true;
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 }
Wink Saville36469e72014-06-11 15:17:00 -07002776
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002777 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002778 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002779 /*
2780 * If any of the Radios are available, it will need to be
2781 * shutdown. So return true if any Radio is available.
2782 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2786 Phone phone = PhoneFactory.getPhone(i);
2787 if (phone != null && phone.isRadioAvailable()) return true;
2788 }
2789 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2790 return false;
2791 } finally {
2792 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002793 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002794 }
2795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002797 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798 enforceModifyPermission();
2799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2803 logv("Shutting down Phone " + i);
2804 shutdownRadioUsingPhoneId(i);
2805 }
2806 } finally {
2807 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002808 }
2809 }
2810
2811 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002812 Phone phone = PhoneFactory.getPhone(phoneId);
2813 if (phone != null && phone.isRadioAvailable()) {
2814 phone.shutdownRadio();
2815 }
2816 }
2817
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2824 if (defaultPhone != null) {
2825 defaultPhone.setRadioPower(turnOn);
2826 return true;
2827 } else {
2828 loge("There's no default phone.");
2829 return false;
2830 }
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002833 }
Wink Saville36469e72014-06-11 15:17:00 -07002834 }
2835
Wink Savilleb564aae2014-10-23 10:18:09 -07002836 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002837 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838
2839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 final Phone phone = getPhone(subId);
2842 if (phone != null) {
2843 phone.setRadioPower(turnOn);
2844 return true;
2845 } else {
2846 return false;
2847 }
2848 } finally {
2849 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002850 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 }
2852
Wink Saville36469e72014-06-11 15:17:00 -07002853 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002854 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002855 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002856 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857
2858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 int subId = mSubscriptionController.getDefaultDataSubId();
2861 final Phone phone = getPhone(subId);
2862 if (phone != null) {
Jack Yuf86fb842022-07-31 00:43:21 -07002863 phone.getDataSettingsManager().setDataEnabled(
2864 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 return true;
2866 } else {
2867 return false;
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 }
2873
Wink Saville36469e72014-06-11 15:17:00 -07002874 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002875 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002876 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002877 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878
2879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 int subId = mSubscriptionController.getDefaultDataSubId();
2882 final Phone phone = getPhone(subId);
2883 if (phone != null) {
Jack Yuf86fb842022-07-31 00:43:21 -07002884 phone.getDataSettingsManager().setDataEnabled(
2885 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002886 return true;
2887 } else {
2888 return false;
2889 }
2890 } finally {
2891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002892 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002893 }
2894
Sanket Padawe356d7632015-06-22 14:03:32 -07002895 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002896 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897 final long identity = Binder.clearCallingIdentity();
2898 try {
2899 final Phone phone = getPhone(subId);
2900 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002901 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902 } else {
2903 return false;
2904 }
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002908 }
2909
2910 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002911 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002912 }
2913
pkanwarae03a6b2016-11-06 20:37:09 -08002914 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002915 enforceCallPermission();
2916
2917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2920 return;
2921 }
2922 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2923 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
2926 }
pkanwar32d516d2016-10-14 19:37:38 -07002927 };
2928
Wink Savilleb564aae2014-10-23 10:18:09 -07002929 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002931
2932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2935 return false;
2936 }
2937 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002941 }
2942
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002943 /**
2944 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2945 * tag on getCallState Binder call.
2946 */
2947 @Deprecated
2948 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002949 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002950 if (CompatChanges.isChangeEnabled(
2951 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2952 Binder.getCallingUid())) {
2953 // Do not allow this API to be called on API version 31+, it should only be
2954 // called on old apps using this Binder call directly.
2955 throw new SecurityException("This method can only be used for applications "
2956 + "targeting API version 30 or less.");
2957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002958 final long identity = Binder.clearCallingIdentity();
2959 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002960 Phone phone = getPhone(getDefaultSubscription());
2961 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2962 PhoneConstantConversions.convertCallState(phone.getState());
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
2965 }
2966 }
2967
2968 @Override
2969 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2970 if (CompatChanges.isChangeEnabled(
2971 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2972 Binder.getCallingUid())) {
2973 // Check READ_PHONE_STATE for API version 31+
2974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2975 featureId, "getCallStateForSubscription")) {
2976 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2977 + "targeting API level 31+.");
2978 }
2979 }
2980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2984 PhoneConstantConversions.convertCallState(phone.getState());
2985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002988 }
2989
Sanket Padawe356d7632015-06-22 14:03:32 -07002990 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002991 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002992 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2993 }
2994
2995 @Override
2996 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 final long identity = Binder.clearCallingIdentity();
2998 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002999 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 if (phone != null) {
Jack Yuf86fb842022-07-31 00:43:21 -07003001 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 } else {
3003 return PhoneConstantConversions.convertDataState(
3004 PhoneConstants.DataState.DISCONNECTED);
3005 }
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003009 }
3010
Sanket Padawe356d7632015-06-22 14:03:32 -07003011 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003012 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003013 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3014 }
3015
3016 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003017 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 final long identity = Binder.clearCallingIdentity();
3019 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003020 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003022 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 } else {
3024 return TelephonyManager.DATA_ACTIVITY_NONE;
3025 }
3026 } finally {
3027 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003028 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003029 }
3030
3031 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003032 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003033 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003034 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003035
3036 LocationAccessPolicy.LocationPermissionResult locationResult =
3037 LocationAccessPolicy.checkLocationPermission(mApp,
3038 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3039 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003040 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003041 .setCallingPid(Binder.getCallingPid())
3042 .setCallingUid(Binder.getCallingUid())
3043 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003044 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003045 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3046 .build());
3047 switch (locationResult) {
3048 case DENIED_HARD:
3049 throw new SecurityException("Not allowed to access cell location");
3050 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003051 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3052 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003053 }
3054
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003055 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003056 final long identity = Binder.clearCallingIdentity();
3057 try {
3058 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003059 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003060 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061 } finally {
3062 Binder.restoreCallingIdentity(identity);
3063 }
Svetoslav64fad262015-04-14 14:35:21 -07003064 }
3065
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003066 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003067 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003068 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3069 // registered cell info, so return a NULL country instead.
3070 final long identity = Binder.clearCallingIdentity();
3071 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003072 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3073 // Get default phone in this case.
3074 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3075 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003076 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003077 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003078 if (phone == null) return "";
3079 ServiceStateTracker sst = phone.getServiceStateTracker();
3080 if (sst == null) return "";
3081 LocaleTracker lt = sst.getLocaleTracker();
3082 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003083 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003084 } finally {
3085 Binder.restoreCallingIdentity(identity);
3086 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003087 }
3088
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003089 /**
3090 * This method was removed due to potential issues caused by performing partial
3091 * updates of service state, and lack of a credible use case.
3092 *
3093 * This has the ability to break the telephony implementation by disabling notification of
3094 * changes in device connectivity. DO NOT USE THIS!
3095 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003096 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003097 public void enableLocationUpdates() {
3098 mApp.enforceCallingOrSelfPermission(
3099 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003100 }
3101
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003102 /**
3103 * This method was removed due to potential issues caused by performing partial
3104 * updates of service state, and lack of a credible use case.
3105 *
3106 * This has the ability to break the telephony implementation by disabling notification of
3107 * changes in device connectivity. DO NOT USE THIS!
3108 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003109 @Override
3110 public void disableLocationUpdates() {
3111 mApp.enforceCallingOrSelfPermission(
3112 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003113 }
3114
3115 @Override
3116 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003117 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3118 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003119 try {
3120 mApp.getSystemService(AppOpsManager.class)
3121 .checkPackage(Binder.getCallingUid(), callingPackage);
3122 } catch (SecurityException e) {
3123 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3124 throw e;
3125 }
3126
Nathan Haroldf096d982020-11-18 17:18:06 -08003127 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003128 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3129 throw new SecurityException(
3130 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3131 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003132
Jordan Liu1617b712019-07-10 15:06:26 -07003133 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003134 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3135 return null;
3136 }
Svetoslav64fad262015-04-14 14:35:21 -07003137
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003138 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003139
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003140 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003141 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142
Nathan Haroldf180aac2018-06-01 18:43:55 -07003143 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3144 for (CellInfo ci : info) {
3145 if (ci instanceof CellInfoGsm) {
3146 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3147 } else if (ci instanceof CellInfoWcdma) {
3148 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003151 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003152 }
3153
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003154 private List<CellInfo> getCachedCellInfo() {
3155 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3156 for (Phone phone : PhoneFactory.getPhones()) {
3157 List<CellInfo> info = phone.getAllCellInfo();
3158 if (info != null) cellInfos.addAll(info);
3159 }
3160 return cellInfos;
3161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003162
3163 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003164 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003165 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003166 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003167
3168 LocationAccessPolicy.LocationPermissionResult locationResult =
3169 LocationAccessPolicy.checkLocationPermission(mApp,
3170 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3171 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003172 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003173 .setCallingPid(Binder.getCallingPid())
3174 .setCallingUid(Binder.getCallingUid())
3175 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003176 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003177 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3178 .build());
3179 switch (locationResult) {
3180 case DENIED_HARD:
3181 throw new SecurityException("Not allowed to access cell info");
3182 case DENIED_SOFT:
3183 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003184 }
3185
Nathan Haroldf096d982020-11-18 17:18:06 -08003186 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003187 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3188 return getCachedCellInfo();
3189 }
3190
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003191 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003192 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193 final long identity = Binder.clearCallingIdentity();
3194 try {
3195 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3196 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003197 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003198 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199 if (info != null) cellInfos.addAll(info);
3200 }
3201 return cellInfos;
3202 } finally {
3203 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 }
3205 }
3206
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003207 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003208 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3209 String callingFeatureId) {
3210 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3211 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003212 }
3213
3214 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003215 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3216 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003217 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003218 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003219 }
3220
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003221 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3222 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003223 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003224 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003225
3226 LocationAccessPolicy.LocationPermissionResult locationResult =
3227 LocationAccessPolicy.checkLocationPermission(mApp,
3228 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3229 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003230 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003231 .setCallingPid(Binder.getCallingPid())
3232 .setCallingUid(Binder.getCallingUid())
3233 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003234 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3235 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003236 .build());
3237 switch (locationResult) {
3238 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003239 if (TelephonyPermissions
3240 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003241 // Safetynet logging for b/154934934
3242 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3243 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003244 throw new SecurityException("Not allowed to access cell info");
3245 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003246 if (TelephonyPermissions
3247 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003248 // Safetynet logging for b/154934934
3249 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3250 }
Nathan Harold5320c422019-05-09 10:26:08 -07003251 try {
3252 cb.onCellInfo(new ArrayList<CellInfo>());
3253 } catch (RemoteException re) {
3254 // Drop without consequences
3255 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003256 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003257 }
3258
Nathan Harolda939a962019-05-09 10:13:47 -07003259
3260 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003261 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3262
3263 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3264 }
3265
3266 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003267 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003268 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003269 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270
3271 final long identity = Binder.clearCallingIdentity();
3272 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003273 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274 } finally {
3275 Binder.restoreCallingIdentity(identity);
3276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003277 }
3278
Shishir Agrawala9f32182016-04-12 12:00:16 -07003279 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003280 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003281 Phone phone = PhoneFactory.getPhone(slotIndex);
3282 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003283 return null;
3284 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003285 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003286 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003287 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003288 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003289 return null;
3290 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003291
3292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 return phone.getImei();
3295 } finally {
3296 Binder.restoreCallingIdentity(identity);
3297 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003298 }
3299
3300 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003301 public String getTypeAllocationCodeForSlot(int slotIndex) {
3302 Phone phone = PhoneFactory.getPhone(slotIndex);
3303 String tac = null;
3304 if (phone != null) {
3305 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003306 try {
3307 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3308 } catch (IndexOutOfBoundsException e) {
3309 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3310 return null;
3311 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003312 }
3313 return tac;
3314 }
3315
3316 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003317 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003318 try {
3319 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3320 } catch (SecurityException se) {
3321 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3322 throw new SecurityException("Package " + callingPackage + " does not belong to "
3323 + Binder.getCallingUid());
3324 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003325 Phone phone = PhoneFactory.getPhone(slotIndex);
3326 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003327 return null;
3328 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003329
Jeff Davidson913390f2018-02-23 17:11:49 -08003330 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003331 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003332 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003333 return null;
3334 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335
3336 final long identity = Binder.clearCallingIdentity();
3337 try {
3338 return phone.getMeid();
3339 } finally {
3340 Binder.restoreCallingIdentity(identity);
3341 }
Jack Yu2af8d712017-03-15 17:14:14 -07003342 }
3343
3344 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003345 public String getManufacturerCodeForSlot(int slotIndex) {
3346 Phone phone = PhoneFactory.getPhone(slotIndex);
3347 String manufacturerCode = null;
3348 if (phone != null) {
3349 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003350 try {
3351 manufacturerCode =
3352 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3353 } catch (IndexOutOfBoundsException e) {
3354 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3355 return null;
3356 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003357 }
3358 return manufacturerCode;
3359 }
3360
3361 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003362 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3363 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003364 Phone phone = PhoneFactory.getPhone(slotIndex);
3365 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003366 return null;
3367 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003368 int subId = phone.getSubId();
3369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003370 mApp, subId, callingPackage, callingFeatureId,
3371 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003372 return null;
3373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003374
3375 final long identity = Binder.clearCallingIdentity();
3376 try {
3377 return phone.getDeviceSvn();
3378 } finally {
3379 Binder.restoreCallingIdentity(identity);
3380 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003381 }
3382
fionaxu43304da2017-11-27 22:51:16 -08003383 @Override
3384 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 final Phone phone = getPhone(subId);
3388 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3389 } finally {
3390 Binder.restoreCallingIdentity(identity);
3391 }
fionaxu43304da2017-11-27 22:51:16 -08003392 }
3393
3394 @Override
3395 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003396 final long identity = Binder.clearCallingIdentity();
3397 try {
3398 final Phone phone = getPhone(subId);
3399 return phone == null ? null : phone.getCarrierName();
3400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
fionaxu43304da2017-11-27 22:51:16 -08003403 }
3404
calvinpanffe225e2018-11-01 19:43:06 +08003405 @Override
chen xu0026ca62019-03-06 15:28:50 -08003406 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003407 final long identity = Binder.clearCallingIdentity();
3408 try {
3409 final Phone phone = getPhone(subId);
3410 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003411 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003412 } finally {
3413 Binder.restoreCallingIdentity(identity);
3414 }
3415 }
3416
3417 @Override
chen xu0026ca62019-03-06 15:28:50 -08003418 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003422 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
3426 }
3427
chen xu651eec72018-11-11 19:03:44 -08003428 @Override
chen xu864e11c2018-12-06 22:10:03 -08003429 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3430 if (!isSubscriptionMccMnc) {
3431 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3432 }
chen xu651eec72018-11-11 19:03:44 -08003433 final Phone phone = PhoneFactory.getPhone(slotIndex);
3434 if (phone == null) {
3435 return TelephonyManager.UNKNOWN_CARRIER_ID;
3436 }
3437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3440 } finally {
3441 Binder.restoreCallingIdentity(identity);
3442 }
3443 }
3444
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 //
3446 // Internal helper methods.
3447 //
3448
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003449 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003450 * Make sure the caller is the calling package itself
3451 *
3452 * @throws SecurityException if the caller is not the calling package
3453 */
3454 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3455 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003456 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3457 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003458 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003459 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003460 } catch (PackageManager.NameNotFoundException e) {
3461 // packageUid is -1
3462 }
3463 if (packageUid != callingUid) {
3464 throw new SecurityException(message + ": Package " + callingPackage
3465 + " does not belong to " + callingUid);
3466 }
3467 }
3468
3469 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003470 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3471 *
3472 * @throws SecurityException if the caller does not have the required permission
3473 */
3474 private void enforceModifyPermission() {
3475 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3476 }
3477
Shuo Qian3b6ee772019-11-13 17:43:31 -08003478 private void enforceActiveEmergencySessionPermission() {
3479 mApp.enforceCallingOrSelfPermission(
3480 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3481 }
3482
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003483 /**
3484 * Make sure the caller has the CALL_PHONE permission.
3485 *
3486 * @throws SecurityException if the caller does not have the required permission
3487 */
3488 private void enforceCallPermission() {
3489 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3490 }
3491
paulhu5a773602019-08-23 19:17:33 +08003492 private void enforceSettingsPermission() {
3493 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003494 }
3495
Michele Berionne5e411512020-11-13 02:36:59 +00003496 private void enforceRebootPermission() {
3497 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3498 }
3499
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003500 private String createTelUrl(String number) {
3501 if (TextUtils.isEmpty(number)) {
3502 return null;
3503 }
3504
Jake Hambye994d462014-02-03 13:10:13 -08003505 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003506 }
3507
Ihab Awadf9e92732013-12-05 18:02:52 -08003508 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003509 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3510 }
3511
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003512 private static void logv(String msg) {
3513 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3514 }
3515
Ihab Awadf9e92732013-12-05 18:02:52 -08003516 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003517 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3518 }
3519
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003520 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003522 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003523 }
3524
Sanket Padawe356d7632015-06-22 14:03:32 -07003525 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003526 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003527 final long identity = Binder.clearCallingIdentity();
3528 try {
3529 final Phone phone = PhoneFactory.getPhone(slotIndex);
3530 if (phone == null) {
3531 return PhoneConstants.PHONE_TYPE_NONE;
3532 } else {
3533 return phone.getPhoneType();
3534 }
3535 } finally {
3536 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003537 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003538 }
3539
3540 /**
3541 * Returns the CDMA ERI icon index to display
3542 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003543 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003544 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3545 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3546 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003547 }
3548
Sanket Padawe356d7632015-06-22 14:03:32 -07003549 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003550 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3551 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003552 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003553 mApp, subId, callingPackage, callingFeatureId,
3554 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003555 return -1;
3556 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557
3558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 final Phone phone = getPhone(subId);
3561 if (phone != null) {
3562 return phone.getCdmaEriIconIndex();
3563 } else {
3564 return -1;
3565 }
3566 } finally {
3567 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003569 }
3570
3571 /**
3572 * Returns the CDMA ERI icon mode,
3573 * 0 - ON
3574 * 1 - FLASHING
3575 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003576 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003577 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3578 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3579 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003580 }
3581
Sanket Padawe356d7632015-06-22 14:03:32 -07003582 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003583 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3584 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003585 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003586 mApp, subId, callingPackage, callingFeatureId,
3587 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003588 return -1;
3589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003590
3591 final long identity = Binder.clearCallingIdentity();
3592 try {
3593 final Phone phone = getPhone(subId);
3594 if (phone != null) {
3595 return phone.getCdmaEriIconMode();
3596 } else {
3597 return -1;
3598 }
3599 } finally {
3600 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003602 }
3603
3604 /**
3605 * Returns the CDMA ERI text,
3606 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003607 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003608 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3609 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3610 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003611 }
3612
Sanket Padawe356d7632015-06-22 14:03:32 -07003613 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003614 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3615 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003617 mApp, subId, callingPackage, callingFeatureId,
3618 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003619 return null;
3620 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003621
3622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 final Phone phone = getPhone(subId);
3625 if (phone != null) {
3626 return phone.getCdmaEriText();
3627 } else {
3628 return null;
3629 }
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003633 }
3634
3635 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003636 * Returns the CDMA MDN.
3637 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003638 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003639 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3641 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003642
3643 final long identity = Binder.clearCallingIdentity();
3644 try {
3645 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003646 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003647 return phone.getLine1Number();
3648 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003649 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650 return null;
3651 }
3652 } finally {
3653 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003654 }
3655 }
3656
3657 /**
3658 * Returns the CDMA MIN.
3659 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003660 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003661 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3663 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664
3665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 final Phone phone = getPhone(subId);
3668 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3669 return phone.getCdmaMin();
3670 } else {
3671 return null;
3672 }
3673 } finally {
3674 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003675 }
3676 }
3677
Hall Liud892bec2018-11-30 14:51:45 -08003678 @Override
3679 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3680 INumberVerificationCallback callback, String callingPackage) {
3681 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3682 != PERMISSION_GRANTED) {
3683 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3684 }
3685 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3686
3687 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3688 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003689 throw new SecurityException("Calling package must be configured in the device config: "
3690 + "calling package: " + callingPackage
3691 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003692 }
3693
3694 if (range == null) {
3695 throw new NullPointerException("Range must be non-null");
3696 }
3697
3698 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003699 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003700
3701 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3702 }
3703
Junda Liuca05d5d2014-08-14 22:36:34 -07003704 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003705 * Returns true if CDMA provisioning needs to run.
3706 */
3707 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708 final long identity = Binder.clearCallingIdentity();
3709 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003710 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003714 }
3715
3716 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003717 * Sets the voice mail number of a given subId.
3718 */
3719 @Override
3720 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003721 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3722 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723
3724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3727 new Pair<String, String>(alphaTag, number), new Integer(subId));
3728 return success;
3729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003732 }
3733
Ta-wei Yen87c49842016-05-13 21:19:52 -07003734 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003735 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003737 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3738 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003739 if (!TextUtils.equals(callingPackage, systemDialer)) {
3740 throw new SecurityException("caller must be system dialer");
3741 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742
3743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3746 if (phoneAccountHandle == null) {
3747 return null;
3748 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003749 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750 } finally {
3751 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003752 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003753 }
3754
3755 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003756 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3757 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003758 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003759 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003760 mApp, subId, callingPackage, callingFeatureId,
3761 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003762 return null;
3763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003764
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003765 final long identity = Binder.clearCallingIdentity();
3766 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003767 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003768 } finally {
3769 Binder.restoreCallingIdentity(identity);
3770 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003771 }
3772
3773 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003774 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3775 VisualVoicemailSmsFilterSettings settings) {
3776 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003777
3778 final long identity = Binder.clearCallingIdentity();
3779 try {
3780 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003781 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782 } finally {
3783 Binder.restoreCallingIdentity(identity);
3784 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003785 }
3786
3787 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003788 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3789 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790
3791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003794 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795 } finally {
3796 Binder.restoreCallingIdentity(identity);
3797 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003798 }
3799
3800 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003801 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3802 String callingPackage, int subId) {
3803 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804
3805 final long identity = Binder.clearCallingIdentity();
3806 try {
3807 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003808 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809 } finally {
3810 Binder.restoreCallingIdentity(identity);
3811 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003812 }
3813
3814 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003815 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003816 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817
3818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003821 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003822 } finally {
3823 Binder.restoreCallingIdentity(identity);
3824 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003825 }
3826
3827 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003828 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3829 String callingAttributionTag, int subId, String number, int port, String text,
3830 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003831 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003832 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003833 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003834 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003835 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3836 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003837 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003838
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003839 /**
fionaxu0152e512016-11-14 13:36:14 -08003840 * Sets the voice activation state of a given subId.
3841 */
3842 @Override
3843 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3845 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003846
3847 final long identity = Binder.clearCallingIdentity();
3848 try {
3849 final Phone phone = getPhone(subId);
3850 if (phone != null) {
3851 phone.setVoiceActivationState(activationState);
3852 } else {
3853 loge("setVoiceActivationState fails with invalid subId: " + subId);
3854 }
3855 } finally {
3856 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003857 }
3858 }
3859
3860 /**
3861 * Sets the data activation state of a given subId.
3862 */
3863 @Override
3864 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3866 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003867
3868 final long identity = Binder.clearCallingIdentity();
3869 try {
3870 final Phone phone = getPhone(subId);
3871 if (phone != null) {
3872 phone.setDataActivationState(activationState);
3873 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003874 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003875 }
3876 } finally {
3877 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003878 }
3879 }
3880
3881 /**
3882 * Returns the voice activation state of a given subId.
3883 */
3884 @Override
3885 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003886 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003887
fionaxu0152e512016-11-14 13:36:14 -08003888 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889 final long identity = Binder.clearCallingIdentity();
3890 try {
3891 if (phone != null) {
3892 return phone.getVoiceActivationState();
3893 } else {
3894 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3895 }
3896 } finally {
3897 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003898 }
3899 }
3900
3901 /**
3902 * Returns the data activation state of a given subId.
3903 */
3904 @Override
3905 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003906 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003907
fionaxu0152e512016-11-14 13:36:14 -08003908 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909 final long identity = Binder.clearCallingIdentity();
3910 try {
3911 if (phone != null) {
3912 return phone.getDataActivationState();
3913 } else {
3914 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3915 }
3916 } finally {
3917 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003918 }
3919 }
3920
3921 /**
Wink Saville36469e72014-06-11 15:17:00 -07003922 * Returns the unread count of voicemails for a subId
3923 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003924 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003925 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3926 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003927 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003928 mApp, subId, callingPackage, callingFeatureId,
3929 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003930 return 0;
3931 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003932 final long identity = Binder.clearCallingIdentity();
3933 try {
3934 final Phone phone = getPhone(subId);
3935 if (phone != null) {
3936 return phone.getVoiceMessageCount();
3937 } else {
3938 return 0;
3939 }
3940 } finally {
3941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003943 }
3944
3945 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003946 * returns true, if the device is in a state where both voice and data
3947 * are supported simultaneously. This can change based on location or network condition.
3948 */
3949 @Override
3950 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003951 final long identity = Binder.clearCallingIdentity();
3952 try {
3953 final Phone phone = getPhone(subId);
3954 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3955 } finally {
3956 Binder.restoreCallingIdentity(identity);
3957 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003958 }
3959
3960 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003961 * Send the dialer code if called from the current default dialer or the caller has
3962 * carrier privilege.
3963 * @param inputCode The dialer code to send
3964 */
3965 @Override
3966 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003967 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003968 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003969 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3970 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003971 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003972 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003973 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003974 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003975
3976 final long identity = Binder.clearCallingIdentity();
3977 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003978 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003979 } finally {
3980 Binder.restoreCallingIdentity(identity);
3981 }
fionaxu235cc5e2017-03-06 22:25:57 -08003982 }
3983
Pengquan Menga1bb6272018-09-06 09:59:22 -07003984 @Override
3985 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003986 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003987 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003988 mApp, subId, "getNetworkSelectionMode");
3989 final long identity = Binder.clearCallingIdentity();
3990 try {
3991 if (!isActiveSubscription(subId)) {
3992 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3993 }
3994 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3995 } finally {
3996 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003997 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003998 }
3999
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004001 public boolean isInEmergencySmsMode() {
4002 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4003 final long identity = Binder.clearCallingIdentity();
4004 try {
4005 for (Phone phone : PhoneFactory.getPhones()) {
4006 if (phone.isInEmergencySmsMode()) {
4007 return true;
4008 }
4009 }
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
4013 return false;
4014 }
4015
shilu366312e2019-12-17 09:28:10 -08004016 /**
4017 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4018 * @param subId The subscription to use to check the configuration.
4019 * @param c The callback that will be used to send the result.
4020 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004021 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004022 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4023 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004024 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004025 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004026
4027 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4028 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4029 "IMS not available on device.");
4030 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 final long token = Binder.clearCallingIdentity();
4032 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004033 int slotId = getSlotIndexOrException(subId);
4034 verifyImsMmTelConfiguredOrThrow(slotId);
4035 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004036 } catch (ImsException e) {
4037 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004038 } finally {
4039 Binder.restoreCallingIdentity(token);
4040 }
4041 }
4042
shilu366312e2019-12-17 09:28:10 -08004043 /**
4044 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4045 * @param subId The subscription to use to check the configuration.
4046 * @param c The callback that will be used to send the result.
4047 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004048 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004049 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004050 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004051 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004052 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4053 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4054 }
Meng Wangafbc5852019-09-19 17:37:13 -07004055 final long token = Binder.clearCallingIdentity();
4056 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004057 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4058 .removeRegistrationCallbackForSubscription(c, subId);
4059 } catch (ImsException e) {
4060 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4061 + "is inactive, ignoring unregister.");
4062 // If the subscription is no longer active, just return, since the callback
4063 // will already have been removed internally.
4064 } finally {
4065 Binder.restoreCallingIdentity(token);
4066 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 }
4068
Brad Ebingera34a6c22019-10-22 17:36:18 -07004069 /**
4070 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4071 */
4072 @Override
4073 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4074 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4075 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4076 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4077 "IMS not available on device.");
4078 }
4079 final long token = Binder.clearCallingIdentity();
4080 try {
4081 Phone phone = getPhone(subId);
4082 if (phone == null) {
4083 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4084 + subId + "'");
4085 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4086 }
4087 phone.getImsRegistrationState(regState -> {
4088 try {
4089 consumer.accept((regState == null)
4090 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4091 } catch (RemoteException e) {
4092 // Ignore if the remote process is no longer available to call back.
4093 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4094 }
4095 });
4096 } finally {
4097 Binder.restoreCallingIdentity(token);
4098 }
4099 }
4100
4101 /**
4102 * Get the transport type for the IMS service registration state.
4103 */
4104 @Override
4105 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004106 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004107 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004108 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4109 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4110 "IMS not available on device.");
4111 }
4112 final long token = Binder.clearCallingIdentity();
4113 try {
4114 Phone phone = getPhone(subId);
4115 if (phone == null) {
4116 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4117 + subId + "'");
4118 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4119 }
4120 phone.getImsRegistrationTech(regTech -> {
4121 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4122 int regTechConverted = (regTech == null)
4123 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4124 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4125 regTechConverted);
4126 try {
4127 consumer.accept(regTechConverted);
4128 } catch (RemoteException e) {
4129 // Ignore if the remote process is no longer available to call back.
4130 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4131 }
4132 });
4133 } finally {
4134 Binder.restoreCallingIdentity(token);
4135 }
4136 }
4137
shilu366312e2019-12-17 09:28:10 -08004138 /**
4139 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4140 * @param subId The subscription to use to check the configuration.
4141 * @param c The callback that will be used to send the result.
4142 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004143 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004144 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4145 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004146 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004147 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004148 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4149 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4150 "IMS not available on device.");
4151 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 final long token = Binder.clearCallingIdentity();
4153 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004154 int slotId = getSlotIndexOrException(subId);
4155 verifyImsMmTelConfiguredOrThrow(slotId);
4156 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004157 } catch (ImsException e) {
4158 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 } finally {
4160 Binder.restoreCallingIdentity(token);
4161 }
4162 }
4163
shilu366312e2019-12-17 09:28:10 -08004164 /**
4165 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4166 * @param subId The subscription to use to check the configuration.
4167 * @param c The callback that will be used to send the result.
4168 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004169 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004170 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004171 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004172 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004173 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4174 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4175 }
Meng Wangafbc5852019-09-19 17:37:13 -07004176
4177 final long token = Binder.clearCallingIdentity();
4178 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004179 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004180 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004181 } catch (ImsException e) {
4182 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4183 + "is inactive, ignoring unregister.");
4184 // If the subscription is no longer active, just return, since the callback
4185 // will already have been removed internally.
4186 } finally {
4187 Binder.restoreCallingIdentity(token);
4188 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004189 }
4190
4191 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004192 public boolean isCapable(int subId, int capability, int regTech) {
4193 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 final long token = Binder.clearCallingIdentity();
4195 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004196 int slotId = getSlotIndexOrException(subId);
4197 verifyImsMmTelConfiguredOrThrow(slotId);
4198 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4199 } catch (com.android.ims.ImsException e) {
4200 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4201 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004202 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004203 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4204 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 } finally {
4206 Binder.restoreCallingIdentity(token);
4207 }
4208 }
4209
4210 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004211 public boolean isAvailable(int subId, int capability, int regTech) {
4212 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 final long token = Binder.clearCallingIdentity();
4214 try {
4215 Phone phone = getPhone(subId);
4216 if (phone == null) return false;
4217 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004218 } catch (com.android.ims.ImsException e) {
4219 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4220 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 } finally {
4222 Binder.restoreCallingIdentity(token);
4223 }
4224 }
4225
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004226 /**
4227 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4228 * subscription.
4229 * @param subId The subscription to use to check the configuration.
4230 * @param callback The callback that will be used to send the result.
4231 * @param capability The MmTelFeature capability that will be used to send the result.
4232 * @param transportType The transport type of the MmTelFeature capability.
4233 */
4234 @Override
4235 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4236 int transportType) {
4237 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004238 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4239 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4240 "IMS not available on device.");
4241 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004242 final long token = Binder.clearCallingIdentity();
4243 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004244 int slotId = getSlotIndex(subId);
4245 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4246 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4247 + subId + "'");
4248 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4249 }
4250 verifyImsMmTelConfiguredOrThrow(slotId);
4251 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4252 transportType, aBoolean -> {
4253 try {
4254 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4255 } catch (RemoteException e) {
4256 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4257 + "running. Ignore");
4258 }
4259 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004260 } catch (ImsException e) {
4261 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004262 } finally {
4263 Binder.restoreCallingIdentity(token);
4264 }
4265 }
4266
shilu366312e2019-12-17 09:28:10 -08004267 /**
4268 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4269 * @param subId The subscription to use to check the configuration.
4270 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 @Override
4272 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004273 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004274 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004275
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 final long token = Binder.clearCallingIdentity();
4277 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004278 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004279 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004280 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004281 } catch (ImsException e) {
4282 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 } finally {
4284 Binder.restoreCallingIdentity(token);
4285 }
4286 }
4287
4288 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004289 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004291 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004292 final long identity = Binder.clearCallingIdentity();
4293 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004294 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004295 // This setting doesn't require an active ImsService connection, so do not verify. The
4296 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004298 } catch (ImsException e) {
4299 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004300 } finally {
4301 Binder.restoreCallingIdentity(identity);
4302 }
4303 }
4304
shilu366312e2019-12-17 09:28:10 -08004305 /**
4306 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4307 * @param subId The subscription to use to check the configuration.
4308 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004310 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004311 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004312 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004313 final long identity = Binder.clearCallingIdentity();
4314 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004315 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004316 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004317 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004318 } catch (ImsException e) {
4319 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
4323 }
4324
4325 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004326 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004328 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004329 final long identity = Binder.clearCallingIdentity();
4330 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004331 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004332 // This setting doesn't require an active ImsService connection, so do not verify. The
4333 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004335 } catch (ImsException e) {
4336 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004337 } finally {
4338 Binder.restoreCallingIdentity(identity);
4339 }
4340 }
4341
shilu366312e2019-12-17 09:28:10 -08004342 /**
4343 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4344 * @param subId The subscription to use to check the configuration.
4345 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004346 @Override
4347 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004348 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004349 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004350 final long identity = Binder.clearCallingIdentity();
4351 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004352 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004353 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004354 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004355 } catch (ImsException e) {
4356 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004357 } finally {
4358 Binder.restoreCallingIdentity(identity);
4359 }
4360 }
4361
4362 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004363 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004365 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004366 final long identity = Binder.clearCallingIdentity();
4367 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004368 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004369 // This setting doesn't require an active ImsService connection, so do not verify. The
4370 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004371 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004372 } catch (ImsException e) {
4373 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 } finally {
4375 Binder.restoreCallingIdentity(identity);
4376 }
4377 }
4378
shilu366312e2019-12-17 09:28:10 -08004379 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004380 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4381 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4382 * @param subId The subscription to use to check the configuration.
4383 */
4384 @Override
4385 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004386 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004387 mApp, subId, "isCrossSimCallingEnabledByUser");
4388 final long identity = Binder.clearCallingIdentity();
4389 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004390 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004391 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004392 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004393 } catch (ImsException e) {
4394 throw new ServiceSpecificException(e.getCode());
4395 } finally {
4396 Binder.restoreCallingIdentity(identity);
4397 }
4398 }
4399
4400 /**
4401 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4402 * Requires MODIFY_PHONE_STATE permission.
4403 * @param subId The subscription to use to check the configuration.
4404 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4405 * false otherwise
4406 */
4407 @Override
4408 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4410 "setCrossSimCallingEnabled");
4411 final long identity = Binder.clearCallingIdentity();
4412 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004413 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004414 // This setting doesn't require an active ImsService connection, so do not verify. The
4415 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004416 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004417 } catch (ImsException e) {
4418 throw new ServiceSpecificException(e.getCode());
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
4422 }
4423
4424 /**
shilu366312e2019-12-17 09:28:10 -08004425 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4426 * @param subId The subscription to use to check the configuration.
4427 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004428 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004429
Brad Ebinger35c841c2018-10-01 10:40:55 -07004430 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004431 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004432 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004433 final long identity = Binder.clearCallingIdentity();
4434 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004435 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004436 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004437 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004438 } catch (ImsException e) {
4439 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004440 } finally {
4441 Binder.restoreCallingIdentity(identity);
4442 }
4443 }
4444
4445 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004446 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004448 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 final long identity = Binder.clearCallingIdentity();
4450 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004451 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004452 // This setting doesn't require an active ImsService connection, so do not verify. The
4453 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004454 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004455 } catch (ImsException e) {
4456 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004457 } finally {
4458 Binder.restoreCallingIdentity(identity);
4459 }
4460 }
4461
4462 @Override
4463 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4465 "setVoWiFiNonPersistent");
4466 final long identity = Binder.clearCallingIdentity();
4467 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004468 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004469 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004470 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004471 } catch (ImsException e) {
4472 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004473 } finally {
4474 Binder.restoreCallingIdentity(identity);
4475 }
4476 }
4477
shilu366312e2019-12-17 09:28:10 -08004478 /**
4479 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4480 * @param subId The subscription to use to check the configuration.
4481 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004482 @Override
4483 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004484 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004485 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 final long identity = Binder.clearCallingIdentity();
4487 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004488 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004489 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004490 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004491 } catch (ImsException e) {
4492 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 } finally {
4494 Binder.restoreCallingIdentity(identity);
4495 }
4496 }
4497
4498 @Override
4499 public void setVoWiFiModeSetting(int subId, int mode) {
4500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4501 "setVoWiFiModeSetting");
4502 final long identity = Binder.clearCallingIdentity();
4503 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004504 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004505 // This setting doesn't require an active ImsService connection, so do not verify. The
4506 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004507 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004508 } catch (ImsException e) {
4509 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004510 } finally {
4511 Binder.restoreCallingIdentity(identity);
4512 }
4513 }
4514
4515 @Override
4516 public int getVoWiFiRoamingModeSetting(int subId) {
4517 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4518 final long identity = Binder.clearCallingIdentity();
4519 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004520 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004521 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004522 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004523 } catch (ImsException e) {
4524 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004525 } finally {
4526 Binder.restoreCallingIdentity(identity);
4527 }
4528 }
4529
4530 @Override
4531 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4533 "setVoWiFiRoamingModeSetting");
4534 final long identity = Binder.clearCallingIdentity();
4535 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004536 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004537 // This setting doesn't require an active ImsService connection, so do not verify. The
4538 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004539 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004540 } catch (ImsException e) {
4541 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004542 } finally {
4543 Binder.restoreCallingIdentity(identity);
4544 }
4545 }
4546
4547 @Override
4548 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4550 "setRttCapabilityEnabled");
4551 final long identity = Binder.clearCallingIdentity();
4552 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004553 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004554 // This setting doesn't require an active ImsService connection, so do not verify. The
4555 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004556 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004557 } catch (ImsException e) {
4558 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004559 } finally {
4560 Binder.restoreCallingIdentity(identity);
4561 }
4562 }
4563
shilu366312e2019-12-17 09:28:10 -08004564 /**
4565 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4566 * @param subId The subscription to use to check the configuration.
4567 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004568 @Override
4569 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004570 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004571 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004572 final long identity = Binder.clearCallingIdentity();
4573 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004574 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004575 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004576 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004577 } catch (ImsException e) {
4578 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
4582 }
4583
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004584 @Override
4585 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4586 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004587
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004588 final long identity = Binder.clearCallingIdentity();
4589 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004590 if (!isImsAvailableOnDevice()) {
4591 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4592 "IMS not available on device.");
4593 }
4594 int slotId = getSlotIndexOrException(subId);
4595 verifyImsMmTelConfiguredOrThrow(slotId);
4596 ImsManager.getInstance(mApp, slotId)
4597 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004598 } catch (ImsException e) {
4599 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004600 } finally {
4601 Binder.restoreCallingIdentity(identity);
4602 }
4603 }
4604
4605 @Override
4606 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4607 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004608
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004609 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004610 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4611 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4612 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004613 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004614 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004615 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004616 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004617 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4618 + "is inactive, ignoring unregister.");
4619 // If the subscription is no longer active, just return, since the callback will already
4620 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004621 } finally {
4622 Binder.restoreCallingIdentity(identity);
4623 }
4624 }
4625
joonhunshincffb7fc2021-11-28 07:32:01 +00004626 @Override
4627 public void registerFeatureProvisioningChangedCallback(int subId,
4628 IFeatureProvisioningCallback callback) {
4629 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4630 mApp, subId, "registerFeatureProvisioningChangedCallback");
4631
4632 final long identity = Binder.clearCallingIdentity();
4633 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4634 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4635 }
4636
joonhunshin91bc1952022-04-29 08:47:15 +00004637 try {
4638 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4639 if (controller == null) {
4640 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4641 "Device does not support IMS");
4642 }
4643 controller.addFeatureProvisioningChangedCallback(subId, callback);
4644 } finally {
4645 Binder.restoreCallingIdentity(identity);
4646 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004647 }
4648
4649 @Override
4650 public void unregisterFeatureProvisioningChangedCallback(int subId,
4651 IFeatureProvisioningCallback callback) {
4652 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4653 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4654
4655 final long identity = Binder.clearCallingIdentity();
4656 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4657 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4658 }
4659
joonhunshin91bc1952022-04-29 08:47:15 +00004660 try {
4661 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4662 if (controller == null) {
4663 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4664 return;
4665 }
4666 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4667 } finally {
4668 Binder.restoreCallingIdentity(identity);
4669 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004670 }
allenwtsu99c623b2020-01-03 18:24:23 +08004671
4672 private void checkModifyPhoneStatePermission(int subId, String message) {
4673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4674 message);
4675 }
4676
allenwtsu99c623b2020-01-03 18:24:23 +08004677 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004678 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004679 boolean isProvisioned) {
4680 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4681
4682 final long identity = Binder.clearCallingIdentity();
4683 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004684 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4685 if (controller == null) {
4686 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4687 return;
4688 }
4689 controller.setRcsProvisioningStatusForCapability(
4690 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
allenwtsu99c623b2020-01-03 18:24:23 +08004694 }
4695
4696
4697 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004698 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4699 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4700 mApp, subId, "getRcsProvisioningStatusForCapability");
4701
allenwtsu99c623b2020-01-03 18:24:23 +08004702 final long identity = Binder.clearCallingIdentity();
4703 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004704 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4705 if (controller == null) {
4706 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4707
4708 // device does not support IMS, this method will return true always.
4709 return true;
4710 }
4711 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
4715 }
4716
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004717 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004718 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4719 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004720 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004721
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004722 final long identity = Binder.clearCallingIdentity();
4723 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004724 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4725 if (controller == null) {
4726 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4727 return;
4728 }
4729 controller.setImsProvisioningStatusForCapability(
4730 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004731 } finally {
4732 Binder.restoreCallingIdentity(identity);
4733 }
4734 }
4735
4736 @Override
4737 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004738 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4739 mApp, subId, "getProvisioningStatusForCapability");
4740
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004741 final long identity = Binder.clearCallingIdentity();
4742 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004743 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4744 if (controller == null) {
4745 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004746
joonhunshin91bc1952022-04-29 08:47:15 +00004747 // device does not support IMS, this method will return true always.
4748 return true;
4749 }
4750 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004751 } finally {
4752 Binder.restoreCallingIdentity(identity);
4753 }
4754 }
4755
4756 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004757 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4758 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4759 mApp, subId, "isProvisioningRequiredForCapability");
4760
4761 final long identity = Binder.clearCallingIdentity();
4762 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004763 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4764 if (controller == null) {
4765 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4766
4767 // device does not support IMS, this method will return false
4768 return false;
4769 }
4770 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004771 } finally {
4772 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004773 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004774 }
4775
4776 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004777 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4778 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4779 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004780
joonhunshincffb7fc2021-11-28 07:32:01 +00004781 final long identity = Binder.clearCallingIdentity();
4782 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004783 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4784 if (controller == null) {
4785 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4786
4787 // device does not support IMS, this method will return false
4788 return false;
4789 }
4790 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004791 } finally {
4792 Binder.restoreCallingIdentity(identity);
4793 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004794 }
4795
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004796 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004797 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004798 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4799 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4800 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004801 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4802 mApp, subId, "getImsProvisioningInt");
4803
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004804 final long identity = Binder.clearCallingIdentity();
4805 try {
4806 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004807 int slotId = getSlotIndex(subId);
4808 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4809 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4810 + subId + "' for key:" + key);
4811 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4812 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004813
joonhunshin91bc1952022-04-29 08:47:15 +00004814 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4815 if (controller == null) {
4816 loge("getImsProvisioningInt: Device does not support IMS");
4817
4818 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4819 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4820 }
4821 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004822 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4823 return retVal;
4824 }
4825
calvinpanb5a34062021-02-08 19:59:36 +08004826 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004827 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004828 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4829 + subId + "' for key:" + key);
4830 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004831 } finally {
4832 Binder.restoreCallingIdentity(identity);
4833 }
4834 }
4835
4836 @Override
4837 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004838 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4839 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4840 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004841 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4842 mApp, subId, "getImsProvisioningString");
4843
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004844 final long identity = Binder.clearCallingIdentity();
4845 try {
4846 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004847 int slotId = getSlotIndex(subId);
4848 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4849 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4850 + subId + "' for key:" + key);
4851 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4852 }
calvinpanb5a34062021-02-08 19:59:36 +08004853 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004854 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004855 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4856 + subId + "' for key:" + key);
4857 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004858 } finally {
4859 Binder.restoreCallingIdentity(identity);
4860 }
4861 }
4862
4863 @Override
4864 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004865 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4866 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4867 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4869 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004870
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004871 final long identity = Binder.clearCallingIdentity();
4872 try {
4873 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004874 int slotId = getSlotIndex(subId);
4875 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4876 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4877 + subId + "' for key:" + key);
4878 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4879 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004880
joonhunshin91bc1952022-04-29 08:47:15 +00004881 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4882 if (controller == null) {
4883 loge("setImsProvisioningInt: Device does not support IMS");
4884
4885 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
4886 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4887 }
4888 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00004889 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4890 return retVal;
4891 }
4892
calvinpanb5a34062021-02-08 19:59:36 +08004893 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4894 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004895 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004896 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004897 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004898 } finally {
4899 Binder.restoreCallingIdentity(identity);
4900 }
4901 }
4902
4903 @Override
4904 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004905 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4906 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4907 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4909 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004910 final long identity = Binder.clearCallingIdentity();
4911 try {
4912 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004913 int slotId = getSlotIndex(subId);
4914 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4915 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4916 + subId + "' for key:" + key);
4917 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4918 }
calvinpanb5a34062021-02-08 19:59:36 +08004919 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4920 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004922 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004923 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004924 } finally {
4925 Binder.restoreCallingIdentity(identity);
4926 }
4927 }
4928
Brad Ebinger919631e2021-06-02 17:46:35 -07004929 /**
4930 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4931 * for the given slot ID or no ImsResolver instance has been created.
4932 * @param slotId The slot ID that the IMS service is created for.
4933 * @throws ImsException If there is no ImsService configured for this slot.
4934 */
4935 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4936 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4937 ImsFeature.FEATURE_MMTEL)) {
4938 throw new ImsException("This subscription does not support MMTEL over IMS",
4939 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4940 }
4941 }
4942
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004943 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004944 int slotId = SubscriptionManager.getSlotIndex(subId);
4945 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004946 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4947 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004948 }
4949 return slotId;
4950 }
4951
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004952 private int getSlotIndex(int subId) {
4953 int slotId = SubscriptionManager.getSlotIndex(subId);
4954 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4955 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4956 }
4957 return slotId;
4958 }
4959
Wink Saville36469e72014-06-11 15:17:00 -07004960 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004961 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004962 */
4963 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004964 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4965 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004966 try {
4967 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4968 } catch (SecurityException se) {
4969 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4970 throw new SecurityException("Package " + callingPackage + " does not belong to "
4971 + Binder.getCallingUid());
4972 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004973 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004974 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004975 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004976 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004977 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004978 mApp, subId, callingPackage, callingFeatureId,
4979 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004980 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4981 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004982
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 final Phone phone = getPhone(subId);
4986 if (phone != null) {
4987 return phone.getServiceState().getDataNetworkType();
4988 } else {
4989 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4990 }
4991 } finally {
4992 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004994 }
4995
4996 /**
4997 * Returns the data network type
4998 */
4999 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005000 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005001 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5002 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005003 }
5004
5005 /**
5006 * Returns the data network type for a subId
5007 */
5008 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005009 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5010 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005011 String functionName = "getDataNetworkTypeForSubscriber";
5012 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5013 mApp, functionName)) {
5014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5015 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5016 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5017 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005018 }
5019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 final long identity = Binder.clearCallingIdentity();
5021 try {
5022 final Phone phone = getPhone(subId);
5023 if (phone != null) {
5024 return phone.getServiceState().getDataNetworkType();
5025 } else {
5026 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5027 }
5028 } finally {
5029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005031 }
5032
5033 /**
Wink Saville36469e72014-06-11 15:17:00 -07005034 * Returns the Voice network type for a subId
5035 */
5036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005037 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5038 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005039 String functionName = "getVoiceNetworkTypeForSubscriber";
5040 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5041 mApp, functionName)) {
5042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5043 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5044 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5045 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005046 }
5047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048 final long identity = Binder.clearCallingIdentity();
5049 try {
5050 final Phone phone = getPhone(subId);
5051 if (phone != null) {
5052 return phone.getServiceState().getVoiceNetworkType();
5053 } else {
5054 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5055 }
5056 } finally {
5057 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005059 }
5060
5061 /**
5062 * @return true if a ICC card is present
5063 */
5064 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005065 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005066 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5067 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005068 }
5069
5070 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005071 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005072 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005073 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005074 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005075 final long identity = Binder.clearCallingIdentity();
5076 try {
5077 final Phone phone = PhoneFactory.getPhone(slotIndex);
5078 if (phone != null) {
5079 return phone.getIccCard().hasIccCard();
5080 } else {
5081 return false;
5082 }
5083 } finally {
5084 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005086 }
5087
5088 /**
5089 * Return if the current radio is LTE on CDMA. This
5090 * is a tri-state return value as for a period of time
5091 * the mode may be unknown.
5092 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005093 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005094 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005095 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005096 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005097 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005098 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5099 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5100 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005101 }
5102
Sanket Padawe356d7632015-06-22 14:03:32 -07005103 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005104 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5105 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005106 try {
5107 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5108 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005109 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5110 }
5111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 final long identity = Binder.clearCallingIdentity();
5113 try {
5114 final Phone phone = getPhone(subId);
5115 if (phone == null) {
5116 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5117 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005118 return TelephonyProperties.lte_on_cdma_device()
5119 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120 }
5121 } finally {
5122 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005123 }
Wink Saville36469e72014-06-11 15:17:00 -07005124 }
5125
Wink Saville36469e72014-06-11 15:17:00 -07005126 /**
5127 * {@hide}
5128 * Returns Default subId, 0 in the case of single standby.
5129 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005130 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005131 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005132 }
5133
Shishir Agrawala9f32182016-04-12 12:00:16 -07005134 private int getSlotForDefaultSubscription() {
5135 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5136 }
5137
Wink Savilleb564aae2014-10-23 10:18:09 -07005138 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005139 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005140 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005141
Pengquan Menge92a50d2018-09-21 15:54:48 -07005142 private boolean isActiveSubscription(int subId) {
5143 return mSubscriptionController.isActiveSubId(subId);
5144 }
5145
Ihab Awadf2177b72013-11-25 13:33:23 -08005146 /**
5147 * @see android.telephony.TelephonyManager.WifiCallingChoices
5148 */
5149 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150 final long identity = Binder.clearCallingIdentity();
5151 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005152 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5154 getWhenToMakeWifiCallsDefaultPreference());
5155 } finally {
5156 Binder.restoreCallingIdentity(identity);
5157 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005158 }
5159
5160 /**
5161 * @see android.telephony.TelephonyManager.WifiCallingChoices
5162 */
5163 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 final long identity = Binder.clearCallingIdentity();
5165 try {
5166 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005167 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5169 } finally {
5170 Binder.restoreCallingIdentity(identity);
5171 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005172 }
5173
Sailesh Nepald1e68152013-12-12 19:08:02 -08005174 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005175 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005176 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005177 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005178
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005179 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5180 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5181 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005182 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005183 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5184 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005185 }
5186 return PhoneFactory.getPhone(phoneId);
5187 }
5188
Shishir Agrawal566b7612013-10-28 14:41:00 -07005189 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005190 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005191 @NonNull IccLogicalChannelRequest request) {
5192 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5193 /*message=*/ "iccOpenLogicalChannel");
5194
5195 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5196 // Verify that the callingPackage in the request belongs to the calling UID
5197 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5198
5199 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005200 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005201
Rambo Wanga1782702021-11-10 20:15:19 -08005202 private Phone getPhoneFromValidIccLogicalChannelRequest(
5203 @NonNull IccLogicalChannelRequest request, String message) {
5204 Phone phone;
5205 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5207 mApp, request.subId, message);
5208 phone = getPhoneFromSubId(request.subId);
5209 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5210 enforceModifyPermission();
5211 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5212 } else {
5213 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005214 }
Rambo Wanga1782702021-11-10 20:15:19 -08005215 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005216 }
5217
5218 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005219 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 final long identity = Binder.clearCallingIdentity();
5221 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005222 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005224 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5225 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005226 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5227 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 loge("The calling package is not allowed to access ISD-R.");
5229 throw new SecurityException(
5230 "The calling package is not allowed to access ISD-R.");
5231 }
Derek Tan740e1672017-06-27 14:56:27 -07005232 }
Derek Tan740e1672017-06-27 14:56:27 -07005233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005235 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5236 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 return response;
5238 } finally {
5239 Binder.restoreCallingIdentity(identity);
5240 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005241 }
5242
5243 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005244 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5245 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5246 /*message=*/"iccCloseLogicalChannel");
5247
5248 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5249
5250 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005251 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005252
Rambo Wanga1782702021-11-10 20:15:19 -08005253 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5254 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005255 // before this feature is enabled, this API should only return false if
5256 // the operation fails instead of throwing runtime exception for
5257 // backward-compatibility.
5258 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5259 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 final long identity = Binder.clearCallingIdentity();
5261 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005262 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005263 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264 }
Chen Xue9d737e2022-01-01 23:41:31 -08005265 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005266 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005267 Boolean success = false;
5268 if (result instanceof RuntimeException) {
5269 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005270 if (shouldThrowExceptionOnFailure) {
5271 throw (RuntimeException) result;
5272 } else {
5273 return false;
5274 }
Chen Xue9d737e2022-01-01 23:41:31 -08005275 } else if (result instanceof Boolean) {
5276 success = (Boolean) result;
5277 } else {
5278 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5279 }
Rambo Wanga1782702021-11-10 20:15:19 -08005280 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 return success;
5282 } finally {
5283 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005284 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005285 }
5286
5287 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005288 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005289 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5291 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005292 if (DBG) {
5293 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5294 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5295 + p3 + " data=" + data);
5296 }
5297 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5298 command, p1, p2, p3, data);
5299 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005300
Jordan Liu4c733742019-02-28 12:03:40 -08005301 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005302 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5303 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005304 enforceModifyPermission();
5305 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005306 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5307 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5308 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005309 }
5310 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005311 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5312 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005313 }
5314
5315 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5316 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005317 final long identity = Binder.clearCallingIdentity();
5318 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005319 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 return "";
5321 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005324 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5325 null /* workSource */);
5326 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328 // Append the returned status code to the end of the response payload.
5329 String s = Integer.toHexString(
5330 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5331 if (response.payload != null) {
5332 s = IccUtils.bytesToHexString(response.payload) + s;
5333 }
5334 return s;
5335 } finally {
5336 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005337 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005338 }
Jake Hambye994d462014-02-03 13:10:13 -08005339
Evan Charltonc66da362014-05-16 14:06:40 -07005340 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005341 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5342 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5344 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005346 if (DBG) {
5347 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5348 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5349 }
5350 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5351 cla, command, p1, p2, p3, data);
5352 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005353
Jordan Liu4c733742019-02-28 12:03:40 -08005354 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005355 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5356 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005357 enforceModifyPermission();
5358 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5359 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005360 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5361 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5362 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005363 }
5364
5365 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005366 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5367 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005368 }
5369
5370 // open APDU basic channel assuming the caller has sufficient permissions
5371 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5372 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 final long identity = Binder.clearCallingIdentity();
5374 try {
5375 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5376 && TextUtils.equals(ISDR_AID, data)) {
5377 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005378 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5379 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 if (bestComponent == null
5381 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5382 loge("The calling package is not allowed to select ISD-R.");
5383 throw new SecurityException(
5384 "The calling package is not allowed to select ISD-R.");
5385 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005386 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005389 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5390 null /* workSource */);
5391 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 // Append the returned status code to the end of the response payload.
5394 String s = Integer.toHexString(
5395 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5396 if (response.payload != null) {
5397 s = IccUtils.bytesToHexString(response.payload) + s;
5398 }
5399 return s;
5400 } finally {
5401 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005402 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005403 }
5404
5405 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005406 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005407 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5409 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005410
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 final long identity = Binder.clearCallingIdentity();
5412 try {
5413 if (DBG) {
5414 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5415 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5416 }
5417
5418 IccIoResult response =
5419 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5420 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5421 subId);
5422
5423 if (DBG) {
5424 log("Exchange SIM_IO [R]" + response);
5425 }
5426
5427 byte[] result = null;
5428 int length = 2;
5429 if (response.payload != null) {
5430 length = 2 + response.payload.length;
5431 result = new byte[length];
5432 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5433 } else {
5434 result = new byte[length];
5435 }
5436
5437 result[length - 1] = (byte) response.sw2;
5438 result[length - 2] = (byte) response.sw1;
5439 return result;
5440 } finally {
5441 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005442 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005443 }
5444
Nathan Haroldb3014052017-01-25 15:57:32 -08005445 /**
5446 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5447 * on a particular subscription
5448 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005449 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5450 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005452 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005453 return null;
5454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005455
5456 final long identity = Binder.clearCallingIdentity();
5457 try {
5458 if (appType != TelephonyManager.APPTYPE_USIM
5459 && appType != TelephonyManager.APPTYPE_SIM) {
5460 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5461 return null;
5462 }
5463 Object response = sendRequest(
5464 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5465 if (response instanceof String[]) {
5466 return (String[]) response;
5467 }
yincheng zhao2737e882019-09-06 17:06:54 -07005468 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005470 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 } finally {
5472 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005473 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005474 }
5475
yincheng zhao2737e882019-09-06 17:06:54 -07005476 /**
5477 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5478 * subscription.
5479 *
5480 * @param subId the id of the subscription.
5481 * @param appType the uicc app type, must be USIM or SIM.
5482 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5483 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005484 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005485 * @return number of fplmns that is successfully written to the SIM.
5486 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005487 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5488 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5490 mApp, subId, "setForbiddenPlmns");
5491
yincheng zhao2737e882019-09-06 17:06:54 -07005492 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5493 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5494 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5495 }
5496 if (fplmns == null) {
5497 throw new IllegalArgumentException("Fplmn List provided is null");
5498 }
5499 for (String fplmn : fplmns) {
5500 if (!CellIdentity.isValidPlmn(fplmn)) {
5501 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5502 }
5503 }
5504 final long identity = Binder.clearCallingIdentity();
5505 try {
5506 Object response = sendRequest(
5507 CMD_SET_FORBIDDEN_PLMNS,
5508 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5509 subId);
5510 return (int) response;
5511 } finally {
5512 Binder.restoreCallingIdentity(identity);
5513 }
5514 }
5515
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005516 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005517 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5519 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 final long identity = Binder.clearCallingIdentity();
5522 try {
5523 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5524 if (response.payload == null) {
5525 return "";
5526 }
Evan Charltonc66da362014-05-16 14:06:40 -07005527
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 // Append the returned status code to the end of the response payload.
5529 String s = Integer.toHexString(
5530 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5531 s = IccUtils.bytesToHexString(response.payload) + s;
5532 return s;
5533 } finally {
5534 Binder.restoreCallingIdentity(identity);
5535 }
Evan Charltonc66da362014-05-16 14:06:40 -07005536 }
5537
Jake Hambye994d462014-02-03 13:10:13 -08005538 /**
5539 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5540 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5541 *
5542 * @param itemID the ID of the item to read
5543 * @return the NV item as a String, or null on error.
5544 */
5545 @Override
5546 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005547 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5549 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550
5551 final long identity = Binder.clearCallingIdentity();
5552 try {
5553 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005554 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005555 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5556 return value;
5557 } finally {
5558 Binder.restoreCallingIdentity(identity);
5559 }
Jake Hambye994d462014-02-03 13:10:13 -08005560 }
5561
5562 /**
5563 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5564 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5565 *
5566 * @param itemID the ID of the item to read
5567 * @param itemValue the value to write, as a String
5568 * @return true on success; false on any failure
5569 */
5570 @Override
5571 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005572 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5574 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575
5576 final long identity = Binder.clearCallingIdentity();
5577 try {
5578 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5579 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005580 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5582 return success;
5583 } finally {
5584 Binder.restoreCallingIdentity(identity);
5585 }
Jake Hambye994d462014-02-03 13:10:13 -08005586 }
5587
5588 /**
5589 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5590 * Used for device configuration by some CDMA operators.
5591 *
5592 * @param preferredRoamingList byte array containing the new PRL
5593 * @return true on success; false on any failure
5594 */
5595 @Override
5596 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5598 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599
5600 final long identity = Binder.clearCallingIdentity();
5601 try {
5602 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5603 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5604 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5605 return success;
5606 } finally {
5607 Binder.restoreCallingIdentity(identity);
5608 }
Jake Hambye994d462014-02-03 13:10:13 -08005609 }
5610
5611 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005612 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005613 * Used for device configuration by some CDMA operators.
5614 *
chen xu6dac5ab2018-10-26 17:39:23 -07005615 * @param slotIndex - device slot.
5616 *
Jake Hambye994d462014-02-03 13:10:13 -08005617 * @return true on success; false on any failure
5618 */
5619 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005620 public boolean resetModemConfig(int slotIndex) {
5621 Phone phone = PhoneFactory.getPhone(slotIndex);
5622 if (phone != null) {
5623 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5624 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005625
chen xu6dac5ab2018-10-26 17:39:23 -07005626 final long identity = Binder.clearCallingIdentity();
5627 try {
5628 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5629 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5630 return success;
5631 } finally {
5632 Binder.restoreCallingIdentity(identity);
5633 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005634 }
chen xu6dac5ab2018-10-26 17:39:23 -07005635 return false;
5636 }
5637
5638 /**
5639 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5640 *
5641 * @param slotIndex - device slot.
5642 *
5643 * @return true on success; false on any failure
5644 */
5645 @Override
5646 public boolean rebootModem(int slotIndex) {
5647 Phone phone = PhoneFactory.getPhone(slotIndex);
5648 if (phone != null) {
5649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5650 mApp, phone.getSubId(), "rebootModem");
5651
5652 final long identity = Binder.clearCallingIdentity();
5653 try {
5654 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5655 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5656 return success;
5657 } finally {
5658 Binder.restoreCallingIdentity(identity);
5659 }
5660 }
5661 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005662 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005663
Brad Ebinger51f743a2017-01-23 13:50:20 -08005664 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005665 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5666 * {@link #disableIms(int)}.
5667 * @param slotIndex device slot.
5668 */
5669 public void resetIms(int slotIndex) {
5670 enforceModifyPermission();
5671
5672 final long identity = Binder.clearCallingIdentity();
5673 try {
5674 if (mImsResolver == null) {
5675 // may happen if the does not support IMS.
5676 return;
5677 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005678 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005679 } finally {
5680 Binder.restoreCallingIdentity(identity);
5681 }
5682 }
5683
5684 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005685 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5686 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005687 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005688 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005689 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690
5691 final long identity = Binder.clearCallingIdentity();
5692 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005693 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005694 // may happen if the device does not support IMS.
5695 return;
5696 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005697 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005701 }
5702
5703 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005704 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5705 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005706 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005707 public void disableIms(int slotId) {
5708 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709
5710 final long identity = Binder.clearCallingIdentity();
5711 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005712 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005713 // may happen if the device does not support IMS.
5714 return;
5715 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005716 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005720 }
5721
5722 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005723 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5724 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005725 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005726 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005727 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005728 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729
5730 final long identity = Binder.clearCallingIdentity();
5731 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005732 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005733 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5734 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005735 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005736 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005740 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005741 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005742 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5743 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005744 @Override
5745 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005746 enforceModifyPermission();
5747
5748 final long identity = Binder.clearCallingIdentity();
5749 try {
5750 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005751 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005752 } finally {
5753 Binder.restoreCallingIdentity(identity);
5754 }
5755 }
5756
5757 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005758 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005759 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005760 */
5761 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763
5764 final long identity = Binder.clearCallingIdentity();
5765 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005766 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005767 // may happen if the device does not support IMS.
5768 return null;
5769 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005770 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 } finally {
5772 Binder.restoreCallingIdentity(identity);
5773 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005774 }
5775
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005776 /**
5777 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005778 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005779 */
5780 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5781 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782
5783 final long identity = Binder.clearCallingIdentity();
5784 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005785 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005786 // may happen if the device does not support IMS.
5787 return null;
5788 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790 } finally {
5791 Binder.restoreCallingIdentity(identity);
5792 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005793 }
5794
Brad Ebinger884c07b2018-02-15 16:17:40 -08005795 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005796 * Sets the ImsService Package Name that Telephony will bind to.
5797 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005798 * @param slotIndex the slot ID that the ImsService should bind for.
5799 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005800 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005801 * @param featureTypes An integer array of feature types associated with a packageName.
5802 * @param packageName The name of the package that the current configuration will be replaced
5803 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005804 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005805 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005806 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5807 int[] featureTypes, String packageName) {
5808 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5809 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5811 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005812 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814 final long identity = Binder.clearCallingIdentity();
5815 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005816 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005817 // may happen if the device does not support IMS.
5818 return false;
5819 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005820 Map<Integer, String> featureConfig = new HashMap<>();
5821 for (int featureType : featureTypes) {
5822 featureConfig.put(featureType, packageName);
5823 }
5824 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5825 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826 } finally {
5827 Binder.restoreCallingIdentity(identity);
5828 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005829 }
5830
5831 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005832 * Clears any carrier ImsService overrides for the slot index specified that were previously
5833 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5834 *
5835 * This should only be used for testing.
5836 *
5837 * @param slotIndex the slot ID that the ImsService should bind for.
5838 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5839 */
5840 @Override
5841 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5842 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5843 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5844 "clearCarrierImsServiceOverride");
5845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5846 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5847 "clearCarrierImsServiceOverride");
5848
5849 final long identity = Binder.clearCallingIdentity();
5850 try {
5851 if (mImsResolver == null) {
5852 // may happen if the device does not support IMS.
5853 return false;
5854 }
5855 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5856 } finally {
5857 Binder.restoreCallingIdentity(identity);
5858 }
5859 }
5860
5861 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005862 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005863 *
5864 * @param slotId The slot that the ImsService is associated with.
5865 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5866 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005868 * @return the package name of the ImsService configuration.
5869 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005870 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5871 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005872 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005873 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005874 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005875 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5876 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005877
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005878 final long identity = Binder.clearCallingIdentity();
5879 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005880 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005881 // may happen if the device does not support IMS.
5882 return "";
5883 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005884 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005885 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5886 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 } finally {
5888 Binder.restoreCallingIdentity(identity);
5889 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005890 }
5891
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005892 /**
5893 * Get the MmTelFeature state associated with the requested subscription id.
5894 * @param subId The subscription that the MmTelFeature is associated with.
5895 * @param callback A callback with an integer containing the
5896 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5897 */
5898 @Override
5899 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5900 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005901 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5902 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5903 "IMS not available on device.");
5904 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005905 final long token = Binder.clearCallingIdentity();
5906 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005907 int slotId = getSlotIndex(subId);
5908 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5909 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5910 + subId + "'");
5911 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5912 }
5913 verifyImsMmTelConfiguredOrThrow(slotId);
5914 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5915 try {
5916 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5917 } catch (RemoteException e) {
5918 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5919 + "Ignore");
5920 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005921 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005922 } catch (ImsException e) {
5923 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005924 } finally {
5925 Binder.restoreCallingIdentity(token);
5926 }
5927 }
5928
Daniel Brightbb5840b2021-01-12 15:48:18 -08005929 /**
5930 * Sets the ims registration state on all valid {@link Phone}s.
5931 */
5932 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005933 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934
5935 final long identity = Binder.clearCallingIdentity();
5936 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005937 // NOTE: Before S, this method only set the default phone.
5938 for (final Phone phone : PhoneFactory.getPhones()) {
5939 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5940 phone.setImsRegistrationState(registered);
5941 }
5942 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 } finally {
5944 Binder.restoreCallingIdentity(identity);
5945 }
Wink Saville36469e72014-06-11 15:17:00 -07005946 }
5947
5948 /**
Stuart Scott54788802015-03-30 13:18:01 -07005949 * Set the network selection mode to automatic.
5950 *
5951 */
5952 @Override
5953 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5955 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956
5957 final long identity = Binder.clearCallingIdentity();
5958 try {
shilufc958392020-01-20 11:36:01 -08005959 if (!isActiveSubscription(subId)) {
5960 return;
5961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005963 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5964 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 } finally {
5966 Binder.restoreCallingIdentity(identity);
5967 }
Stuart Scott54788802015-03-30 13:18:01 -07005968 }
5969
Jack Yud10cdd42020-09-28 20:28:01 -07005970 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005971 * Ask the radio to connect to the input network and change selection mode to manual.
5972 *
5973 * @param subId the id of the subscription.
5974 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5975 * the operator to attach to.
5976 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5977 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5978 * normal network selection next time.
5979 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005980 */
5981 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005982 public boolean setNetworkSelectionModeManual(
5983 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5985 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005986
5987 if (!isActiveSubscription(subId)) {
5988 return false;
5989 }
5990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 final long identity = Binder.clearCallingIdentity();
5992 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005993 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005995 if (DBG) {
5996 log("setNetworkSelectionModeManual: subId: " + subId
5997 + " operator: " + operatorInfo);
5998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6000 } finally {
6001 Binder.restoreCallingIdentity(identity);
6002 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006003 }
shilu84f6e8b2019-12-19 13:58:01 -08006004 /**
6005 * Get the manual network selection
6006 *
6007 * @param subId the id of the subscription.
6008 *
6009 * @return the previously saved user selected PLMN
6010 */
6011 @Override
6012 public String getManualNetworkSelectionPlmn(int subId) {
6013 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006014 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006015 mApp, subId, "getManualNetworkSelectionPlmn");
6016
6017 final long identity = Binder.clearCallingIdentity();
6018 try {
6019 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006020 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006021 }
6022
6023 final Phone phone = getPhone(subId);
6024 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006025 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006026 }
6027 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6028 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6029 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6030 } finally {
6031 Binder.restoreCallingIdentity(identity);
6032 }
6033 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006034
6035 /**
6036 * Scans for available networks.
6037 */
6038 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006039 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6040 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6042 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006043 LocationAccessPolicy.LocationPermissionResult locationResult =
6044 LocationAccessPolicy.checkLocationPermission(mApp,
6045 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6046 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006047 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006048 .setCallingPid(Binder.getCallingPid())
6049 .setCallingUid(Binder.getCallingUid())
6050 .setMethod("getCellNetworkScanResults")
6051 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006052 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6053 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006054 .build());
6055 switch (locationResult) {
6056 case DENIED_HARD:
6057 throw new SecurityException("Not allowed to access scan results -- location");
6058 case DENIED_SOFT:
6059 return null;
6060 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061
Pengquan Menga1bb6272018-09-06 09:59:22 -07006062 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063 try {
6064 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006065 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 } finally {
6068 Binder.restoreCallingIdentity(identity);
6069 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006070 }
6071
6072 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006073 * Get the call forwarding info, given the call forwarding reason.
6074 */
6075 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006076 public void getCallForwarding(int subId, int callForwardingReason,
6077 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006078 enforceReadPrivilegedPermission("getCallForwarding");
6079 long identity = Binder.clearCallingIdentity();
6080 try {
6081 if (DBG) {
6082 log("getCallForwarding: subId " + subId
6083 + " callForwardingReason" + callForwardingReason);
6084 }
Hall Liu27d24262020-09-18 19:04:59 -07006085
6086 Phone phone = getPhone(subId);
6087 if (phone == null) {
6088 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006089 callback.onError(
6090 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006091 } catch (RemoteException e) {
6092 // ignore
6093 }
6094 return;
6095 }
6096
6097 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6098 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6099 @Override
6100 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6101 try {
6102 callback.onCallForwardingInfoAvailable(info);
6103 } catch (RemoteException e) {
6104 // ignore
6105 }
6106 }
6107
6108 @Override
6109 public void onError(int error) {
6110 try {
6111 callback.onError(error);
6112 } catch (RemoteException e) {
6113 // ignore
6114 }
6115 }
6116 });
6117 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006118 } finally {
6119 Binder.restoreCallingIdentity(identity);
6120 }
6121 }
6122
6123 /**
6124 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6125 * reason, the number to forward, and the timeout before the forwarding is attempted.
6126 */
6127 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006128 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6129 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006130 enforceModifyPermission();
6131 long identity = Binder.clearCallingIdentity();
6132 try {
6133 if (DBG) {
6134 log("setCallForwarding: subId " + subId
6135 + " callForwardingInfo" + callForwardingInfo);
6136 }
Hall Liu27d24262020-09-18 19:04:59 -07006137
6138 Phone phone = getPhone(subId);
6139 if (phone == null) {
6140 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006141 callback.accept(
6142 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006143 } catch (RemoteException e) {
6144 // ignore
6145 }
6146 return;
6147 }
6148
6149 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6150 FunctionalUtils.ignoreRemoteException(callback::accept));
6151
6152 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006153 } finally {
6154 Binder.restoreCallingIdentity(identity);
6155 }
6156 }
6157
6158 /**
Hall Liu27d24262020-09-18 19:04:59 -07006159 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006160 */
6161 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006162 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006163 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006164 long identity = Binder.clearCallingIdentity();
6165 try {
Hall Liu27d24262020-09-18 19:04:59 -07006166 Phone phone = getPhone(subId);
6167 if (phone == null) {
6168 try {
6169 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6170 } catch (RemoteException e) {
6171 // ignore
6172 }
6173 return;
6174 }
SongFerngWang0e767992021-03-31 22:08:45 +08006175 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6176 PersistableBundle c = configManager.getConfigForSubId(subId);
6177 boolean requireUssd = c.getBoolean(
6178 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006179
Shuo Qian4a594052020-01-23 11:59:30 -08006180 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006181 if (requireUssd) {
6182 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6183 getSubscriptionCarrierId(subId));
6184 String newUssdCommand = "";
6185 try {
6186 newUssdCommand = carrierXmlParser.getFeature(
6187 CarrierXmlParser.FEATURE_CALL_WAITING)
6188 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6189 } catch (NullPointerException e) {
6190 loge("Failed to generate USSD number" + e);
6191 }
6192 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6193 mMainThreadHandler, callback, carrierXmlParser,
6194 CarrierXmlParser.SsEntry.SSAction.QUERY);
6195 final String ussdCommand = newUssdCommand;
6196 Executors.newSingleThreadExecutor().execute(() -> {
6197 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6198 });
6199 } else {
6200 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6201 callback::accept);
6202 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6203 }
Shuo Qian4a594052020-01-23 11:59:30 -08006204 } finally {
6205 Binder.restoreCallingIdentity(identity);
6206 }
6207 }
6208
6209 /**
Hall Liu27d24262020-09-18 19:04:59 -07006210 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006211 */
6212 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006213 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006214 enforceModifyPermission();
6215 long identity = Binder.clearCallingIdentity();
6216 try {
Hall Liu27d24262020-09-18 19:04:59 -07006217 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6218
6219 Phone phone = getPhone(subId);
6220 if (phone == null) {
6221 try {
6222 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6223 } catch (RemoteException e) {
6224 // ignore
6225 }
6226 return;
6227 }
6228
SongFerngWang0e767992021-03-31 22:08:45 +08006229 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6230 PersistableBundle c = configManager.getConfigForSubId(subId);
6231 boolean requireUssd = c.getBoolean(
6232 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006233
SongFerngWang0e767992021-03-31 22:08:45 +08006234 if (DBG) log("getCallWaitingStatus: subId " + subId);
6235 if (requireUssd) {
6236 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6237 getSubscriptionCarrierId(subId));
6238 CarrierXmlParser.SsEntry.SSAction ssAction =
6239 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6240 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6241 String newUssdCommand = "";
6242 try {
6243 newUssdCommand = carrierXmlParser.getFeature(
6244 CarrierXmlParser.FEATURE_CALL_WAITING)
6245 .makeCommand(ssAction, null);
6246 } catch (NullPointerException e) {
6247 loge("Failed to generate USSD number" + e);
6248 }
6249 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6250 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6251 final String ussdCommand = newUssdCommand;
6252 Executors.newSingleThreadExecutor().execute(() -> {
6253 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6254 });
6255 } else {
6256 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6257 FunctionalUtils.ignoreRemoteException(callback::accept));
6258
6259 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6260 }
Shuo Qian4a594052020-01-23 11:59:30 -08006261 } finally {
6262 Binder.restoreCallingIdentity(identity);
6263 }
6264 }
6265
6266 /**
yinxub1bed742017-04-17 11:45:04 -07006267 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006268 *
yinxub1bed742017-04-17 11:45:04 -07006269 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006270 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6271 * location related information which will be sent if the caller already possess
6272 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006273 * @param request contains the radio access networks with bands/channels to scan
6274 * @param messenger callback messenger for scan results or errors
6275 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006276 * @return the id of the requested scan which can be used to stop the scan.
6277 */
6278 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006279 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6280 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006281 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6283 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006284 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006285 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6286 if (!renounceFineLocationAccess) {
6287 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6288 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6289 .setCallingPackage(callingPackage)
6290 .setCallingFeatureId(callingFeatureId)
6291 .setCallingPid(Binder.getCallingPid())
6292 .setCallingUid(Binder.getCallingUid())
6293 .setMethod("requestNetworkScan")
6294 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6295 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6296 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6297 .build());
6298 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006299 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006300 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6301 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006302 if (e != null) {
6303 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6304 throw e;
6305 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006306 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006307 return TelephonyScanManager.INVALID_SCAN_ID;
6308 }
6309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 }
Hall Liu912dfd32019-04-25 14:02:26 -07006311 int callingUid = Binder.getCallingUid();
6312 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006313 final long identity = Binder.clearCallingIdentity();
6314 try {
6315 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006316 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006317 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006318 } finally {
6319 Binder.restoreCallingIdentity(identity);
6320 }
yinxu504e1392017-04-12 16:03:22 -07006321 }
6322
Hall Liub2ac8ef2019-02-28 15:56:23 -08006323 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006324 NetworkScanRequest request, int subId, String callingPackage) {
6325 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006326 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6327 boolean hasNetworkScanPermission =
6328 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6329 == PERMISSION_GRANTED;
6330
6331 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6332 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6333 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006334 }
6335
6336 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6337 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006338 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6339 return new SecurityException("Specific channels must not be"
6340 + " scanned without location access.");
6341 }
6342 }
6343 }
6344
Hall Liub2ac8ef2019-02-28 15:56:23 -08006345 return null;
6346 }
6347
yinxu504e1392017-04-12 16:03:22 -07006348 /**
6349 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006350 *
6351 * @param subId id of the subscription
6352 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006353 */
6354 @Override
6355 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6357 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358
Hall Liu912dfd32019-04-25 14:02:26 -07006359 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360 final long identity = Binder.clearCallingIdentity();
6361 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006362 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363 } finally {
6364 Binder.restoreCallingIdentity(identity);
6365 }
yinxu504e1392017-04-12 16:03:22 -07006366 }
6367
6368 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006369 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006370 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006371 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006372 */
6373 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006374 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006375 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006376 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006377 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378
6379 final long identity = Binder.clearCallingIdentity();
6380 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006381 if (DBG) log("getAllowedNetworkTypesBitmask");
6382 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6383 int networkTypesBitmask = (result != null ? result[0] : -1);
6384 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6385 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386 } finally {
6387 Binder.restoreCallingIdentity(identity);
6388 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006389 }
6390
6391 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006392 * Get the allowed network types for certain reason.
6393 *
6394 * @param subId the id of the subscription.
6395 * @param reason the reason the allowed network type change is taking place
6396 * @return the allowed network types.
6397 */
6398 @Override
6399 public long getAllowedNetworkTypesForReason(int subId,
6400 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006401 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006402 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006403 final long identity = Binder.clearCallingIdentity();
6404 try {
6405 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6406 } finally {
6407 Binder.restoreCallingIdentity(identity);
6408 }
6409 }
6410
6411 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006412 * Enable/Disable E-UTRA-NR Dual Connectivity
6413 * @param subId subscription id of the sim card
6414 * @param nrDualConnectivityState expected NR dual connectivity state
6415 * This can be passed following states
6416 * <ol>
6417 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6418 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6419 * <li>Disable NR dual connectivity and force secondary cell to be released
6420 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6421 * </ol>
6422 * @return operation result.
6423 */
6424 @Override
6425 public int setNrDualConnectivityState(int subId,
6426 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6428 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006429 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006430 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6431 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6432 }
6433
Sooraj Sasindran37444802020-08-11 10:40:43 -07006434 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6435 final long identity = Binder.clearCallingIdentity();
6436 try {
6437 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6438 nrDualConnectivityState, subId,
6439 workSource);
6440 if (DBG) log("enableNRDualConnectivity result: " + result);
6441 return result;
6442 } finally {
6443 Binder.restoreCallingIdentity(identity);
6444 }
6445 }
6446
6447 /**
6448 * Is E-UTRA-NR Dual Connectivity enabled
6449 * @return true if dual connectivity is enabled else false
6450 */
6451 @Override
6452 public boolean isNrDualConnectivityEnabled(int subId) {
6453 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006454 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006455 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006456 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006457 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6458 return false;
6459 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006460 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6461 final long identity = Binder.clearCallingIdentity();
6462 try {
6463 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6464 null, subId, workSource);
6465 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6466 return isEnabled;
6467 } finally {
6468 Binder.restoreCallingIdentity(identity);
6469 }
6470 }
6471
6472 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006473 * Set the allowed network types of the device and
6474 * provide the reason triggering the allowed network change.
6475 *
6476 * @param subId the id of the subscription.
6477 * @param reason the reason the allowed network type change is taking place
6478 * @param allowedNetworkTypes the allowed network types.
6479 * @return true on success; false on any failure.
6480 */
6481 @Override
6482 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006483 @TelephonyManager.AllowedNetworkTypesReason int reason,
6484 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6486 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006487 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006488 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6489 return false;
6490 }
6491 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6492 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006493 return false;
6494 }
6495
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006496 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6497 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6498
6499
6500 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6501 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6502 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006503 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006504
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006505 final long identity = Binder.clearCallingIdentity();
6506 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006507 Boolean success = (Boolean) sendRequest(
6508 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6509 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6510
6511 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6512 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006513 } finally {
6514 Binder.restoreCallingIdentity(identity);
6515 }
6516 }
6517
6518 /**
Miaoa84611c2019-03-15 09:21:10 +08006519 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006520 *
Miaoa84611c2019-03-15 09:21:10 +08006521 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006522 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006523 * @hide
6524 */
6525 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006526 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006527 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006529 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530 try {
Miaoa84611c2019-03-15 09:21:10 +08006531 if (phone != null) {
6532 return phone.hasMatchedTetherApnSetting();
6533 } else {
6534 return false;
6535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536 } finally {
6537 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006538 }
Junda Liu475951f2014-11-07 16:45:03 -08006539 }
6540
6541 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006542 * Get the user enabled state of Mobile Data.
6543 *
6544 * TODO: remove and use isUserDataEnabled.
6545 * This can't be removed now because some vendor codes
6546 * calls through ITelephony directly while they should
6547 * use TelephonyManager.
6548 *
6549 * @return true on enabled
6550 */
6551 @Override
6552 public boolean getDataEnabled(int subId) {
6553 return isUserDataEnabled(subId);
6554 }
6555
6556 /**
6557 * Get whether mobile data is enabled per user setting.
6558 *
6559 * There are other factors deciding whether mobile data is actually enabled, but they are
6560 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006561 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006562 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6563 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006564 *
6565 * @return {@code true} if data is enabled else {@code false}
6566 */
6567 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006568 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006569 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006570 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006571 try {
6572 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6573 functionName);
6574 } catch (Exception e) {
6575 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6576 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006577 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006579 mApp, subId, functionName);
6580
Robert Greenwalt646120a2014-05-23 11:54:03 -07006581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582
6583 final long identity = Binder.clearCallingIdentity();
6584 try {
6585 int phoneId = mSubscriptionController.getPhoneId(subId);
6586 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6587 Phone phone = PhoneFactory.getPhone(phoneId);
6588 if (phone != null) {
6589 boolean retVal = phone.isUserDataEnabled();
6590 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6591 return retVal;
6592 } else {
6593 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6594 return false;
6595 }
6596 } finally {
6597 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006598 }
6599 }
6600
6601 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006602 * Checks if the device is capable of mobile data by considering whether whether the
6603 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6604 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006605 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006606 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006607 */
6608 @Override
6609 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006610 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006611 try {
6612 try {
6613 mApp.enforceCallingOrSelfPermission(
6614 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006615 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006616 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006617 try {
6618 mApp.enforceCallingOrSelfPermission(
6619 android.Manifest.permission.READ_PHONE_STATE,
6620 functionName);
6621 } catch (Exception e2) {
6622 mApp.enforceCallingOrSelfPermission(
6623 permission.READ_BASIC_PHONE_STATE, functionName);
6624 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006625 }
6626 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006627 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629
6630 final long identity = Binder.clearCallingIdentity();
6631 try {
6632 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633 Phone phone = PhoneFactory.getPhone(phoneId);
6634 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006635 boolean retVal;
Jack Yuf86fb842022-07-31 00:43:21 -07006636 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006637 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006638 return retVal;
6639 } else {
6640 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6641 return false;
6642 }
6643 } finally {
6644 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006645 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006646 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006647
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006648 /**
6649 * Check if data is enabled for a specific reason
6650 * @param subId Subscription index
6651 * @param reason the reason the data enable change is taking place
6652 * @return {@code true} if the overall data is enabled; {@code false} if not.
6653 */
6654 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006655 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006656 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006657 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006658 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006659 try {
6660 mApp.enforceCallingOrSelfPermission(
6661 android.Manifest.permission.ACCESS_NETWORK_STATE,
6662 functionName);
6663 } catch (Exception e) {
6664 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6665 functionName);
6666 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006667 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006668 try {
6669 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006670 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006671 } catch (Exception e2) {
6672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006673 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006674 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006675 }
6676
6677
6678 final long identity = Binder.clearCallingIdentity();
6679 try {
6680 int phoneId = mSubscriptionController.getPhoneId(subId);
6681 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006682 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006683 + " reason=" + reason);
6684 }
6685 Phone phone = PhoneFactory.getPhone(phoneId);
6686 if (phone != null) {
6687 boolean retVal;
Jack Yuf86fb842022-07-31 00:43:21 -07006688 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006689 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006690 return retVal;
6691 } else {
6692 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006693 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006694 + subId + " retVal=false");
6695 }
6696 return false;
6697 }
6698 } finally {
6699 Binder.restoreCallingIdentity(identity);
6700 }
6701 }
6702
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006703 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006704 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006705 // No permission needed; this only lets the caller inspect their own status.
6706 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006707 }
Junda Liu29340342014-07-10 15:23:27 -07006708
6709 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006710 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006711 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006712 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6713 }
6714
6715 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6716 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006717 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006718 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006719 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6720 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006721 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6722 if (cpt == null) {
6723 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006724 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6725 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006726 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006727 }
6728
6729 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006730 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006731 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006732 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006733 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006734 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006735 Phone phone = getPhone(subId);
6736 if (phone == null) {
6737 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6738 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6739 }
6740 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6741 if (cpt == null) {
6742 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006743 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6744 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006745 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006746 }
6747
6748 @Override
6749 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006750 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006751 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6752 }
6753
6754 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006755 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006756 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006757 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006758 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006759 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6760 Phone phone = PhoneFactory.getPhone(phoneId);
6761 if (phone == null) {
6762 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006763 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006764 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6765 if (cpt == null) {
6766 continue;
6767 }
6768 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006769 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6770 break;
6771 }
6772 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006773 return result;
Junda Liu29340342014-07-10 15:23:27 -07006774 }
Derek Tan89e89d42014-07-08 17:00:10 -07006775
6776 @Override
Junda Liue64de782015-04-16 17:19:16 -07006777 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006778 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006779 Phone phone = PhoneFactory.getPhone(phoneId);
6780 if (phone == null) {
6781 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006782 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006783 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6784 if (cpt == null) {
6785 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006786 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006787 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006788 }
6789
Amith Yamasani6e118872016-02-19 12:53:51 -08006790 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006791 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006792 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006793 Phone phone = PhoneFactory.getPhone(phoneId);
6794 if (phone == null) {
6795 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006796 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006797 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6798 if (cpt == null) {
6799 return Collections.emptyList();
6800 }
6801 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006802 }
6803
chen xuf7e9fe82019-05-09 19:31:02 -07006804 @Override
6805 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006806 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006807 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006808 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006809 try {
6810 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6811 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6812 }
6813 } finally {
6814 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006815 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006816 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006817 }
6818
Rambo Wang6812ffb2022-03-15 16:54:17 -07006819 @Override
6820 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6821 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6822
6823 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6824 if (phone == null) {
6825 return null;
6826 }
6827 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6828 if (cpt == null) {
6829 return null;
6830 }
6831 return cpt.getCarrierServicePackageName();
6832 }
6833
Wink Savilleb564aae2014-10-23 10:18:09 -07006834 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006835 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006836 UiccPort port = phone == null ? null : phone.getUiccPort();
6837 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006838 return null;
6839 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006840 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006841 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006842 return null;
6843 }
6844 return iccId;
6845 }
6846
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006847 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006848 public void setCallComposerStatus(int subId, int status) {
6849 enforceModifyPermission();
6850
6851 final long identity = Binder.clearCallingIdentity();
6852 try {
6853 Phone phone = getPhone(subId);
6854 if (phone != null) {
6855 Phone defaultPhone = phone.getImsPhone();
6856 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6857 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6858 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006859 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6860 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006861 }
6862 }
Shuo Qian284ae752020-12-22 19:10:14 -08006863 } catch (ImsException e) {
6864 throw new ServiceSpecificException(e.getCode());
6865 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006866 Binder.restoreCallingIdentity(identity);
6867 }
6868 }
6869
6870 @Override
6871 public int getCallComposerStatus(int subId) {
6872 enforceReadPrivilegedPermission("getCallComposerStatus");
6873
6874 final long identity = Binder.clearCallingIdentity();
6875 try {
6876 Phone phone = getPhone(subId);
6877 if (phone != null) {
6878 Phone defaultPhone = phone.getImsPhone();
6879 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6880 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6881 return imsPhone.getCallComposerStatus();
6882 }
6883 }
6884 } finally {
6885 Binder.restoreCallingIdentity(identity);
6886 }
6887 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6888 }
6889
6890 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006891 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6892 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006893 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006894 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006896 final long identity = Binder.clearCallingIdentity();
6897 try {
6898 final String iccId = getIccId(subId);
6899 final Phone phone = getPhone(subId);
6900 if (phone == null) {
6901 return false;
6902 }
6903 final String subscriberId = phone.getSubscriberId();
6904
6905 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006906 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907 + subscriberId + " to " + number);
6908 }
6909
6910 if (TextUtils.isEmpty(iccId)) {
6911 return false;
6912 }
6913
6914 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6915
6916 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6917 if (alphaTag == null) {
6918 editor.remove(alphaTagPrefKey);
6919 } else {
6920 editor.putString(alphaTagPrefKey, alphaTag);
6921 }
6922
6923 // Record both the line number and IMSI for this ICCID, since we need to
6924 // track all merged IMSIs based on line number
6925 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6926 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6927 if (number == null) {
6928 editor.remove(numberPrefKey);
6929 editor.remove(subscriberPrefKey);
6930 } else {
6931 editor.putString(numberPrefKey, number);
6932 editor.putString(subscriberPrefKey, subscriberId);
6933 }
6934
6935 editor.commit();
6936 return true;
6937 } finally {
6938 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006939 }
Derek Tan7226c842014-07-02 17:42:23 -07006940 }
6941
6942 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006943 public String getLine1NumberForDisplay(int subId, String callingPackage,
6944 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006945 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006946 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006947 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006948 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006949 return null;
6950 }
Derek Tan97ebb422014-09-05 16:55:38 -07006951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 final long identity = Binder.clearCallingIdentity();
6953 try {
6954 String iccId = getIccId(subId);
6955 if (iccId != null) {
6956 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6957 if (DBG_MERGE) {
6958 log("getLine1NumberForDisplay returning "
6959 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6960 }
6961 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006963 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6964 return null;
6965 } finally {
6966 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006967 }
Derek Tan7226c842014-07-02 17:42:23 -07006968 }
6969
6970 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006971 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6972 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006974 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006975 return null;
6976 }
Derek Tan97ebb422014-09-05 16:55:38 -07006977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 final long identity = Binder.clearCallingIdentity();
6979 try {
6980 String iccId = getIccId(subId);
6981 if (iccId != null) {
6982 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6983 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6984 }
6985 return null;
6986 } finally {
6987 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006988 }
Derek Tan7226c842014-07-02 17:42:23 -07006989 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006990
6991 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006992 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6993 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006994 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6995 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006996 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006997 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006998 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006999 return null;
7000 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007001
Jordan Liub49b04b2019-05-06 14:45:15 -07007002 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7003 // the process, where TelephonyManager was instantiated.
7004 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007005 final long identity = Binder.clearCallingIdentity();
7006 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007007 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 final TelephonyManager tele = TelephonyManager.from(context);
7009 final SubscriptionManager sub = SubscriptionManager.from(context);
7010
7011 // Figure out what subscribers are currently active
7012 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013
Jordan Liub49b04b2019-05-06 14:45:15 -07007014 // Only consider subs which match the current subId
7015 // This logic can be simplified. See b/131189269 for progress.
7016 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007017 activeSubscriberIds.add(tele.getSubscriberId(subId));
7018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019
7020 // First pass, find a number override for an active subscriber
7021 String mergeNumber = null;
7022 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7023 for (String key : prefs.keySet()) {
7024 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7025 final String subscriberId = (String) prefs.get(key);
7026 if (activeSubscriberIds.contains(subscriberId)) {
7027 final String iccId = key.substring(
7028 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7029 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7030 mergeNumber = (String) prefs.get(numberKey);
7031 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007032 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033 + " for active subscriber " + subscriberId);
7034 }
7035 if (!TextUtils.isEmpty(mergeNumber)) {
7036 break;
7037 }
7038 }
7039 }
7040 }
7041
7042 // Shortcut when no active merged subscribers
7043 if (TextUtils.isEmpty(mergeNumber)) {
7044 return null;
7045 }
7046
7047 // Second pass, find all subscribers under that line override
7048 final ArraySet<String> result = new ArraySet<>();
7049 for (String key : prefs.keySet()) {
7050 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7051 final String number = (String) prefs.get(key);
7052 if (mergeNumber.equals(number)) {
7053 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7054 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7055 final String subscriberId = (String) prefs.get(subscriberKey);
7056 if (!TextUtils.isEmpty(subscriberId)) {
7057 result.add(subscriberId);
7058 }
7059 }
7060 }
7061 }
7062
7063 final String[] resultArray = result.toArray(new String[result.size()]);
7064 Arrays.sort(resultArray);
7065 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007066 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7068 }
7069 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007070 } finally {
7071 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007072 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007073 }
7074
7075 @Override
zoey chen38003472019-12-13 17:16:31 +08007076 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7077 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007078
7079 final long identity = Binder.clearCallingIdentity();
7080 try {
7081 final TelephonyManager telephonyManager = mApp.getSystemService(
7082 TelephonyManager.class);
7083 String subscriberId = telephonyManager.getSubscriberId(subId);
7084 if (subscriberId == null) {
7085 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007086 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007087 + subId);
7088 }
7089 return null;
7090 }
7091
7092 final SubscriptionInfo info = SubscriptionController.getInstance()
7093 .getSubscriptionInfo(subId);
7094 final ParcelUuid groupUuid = info.getGroupUuid();
7095 // If it doesn't belong to any group, return just subscriberId of itself.
7096 if (groupUuid == null) {
7097 return new String[]{subscriberId};
7098 }
7099
7100 // Get all subscriberIds from the group.
7101 final List<String> mergedSubscriberIds = new ArrayList<>();
7102 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007103 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007104 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007105 for (SubscriptionInfo subInfo : groupInfos) {
7106 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7107 if (subscriberId != null) {
7108 mergedSubscriberIds.add(subscriberId);
7109 }
7110 }
7111
7112 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7113 } finally {
7114 Binder.restoreCallingIdentity(identity);
7115
7116 }
7117 }
7118
7119 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007120 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007121 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007122 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123
7124 final long identity = Binder.clearCallingIdentity();
7125 try {
7126 final Phone phone = getPhone(subId);
7127 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7128 } finally {
7129 Binder.restoreCallingIdentity(identity);
7130 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007131 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007132
7133 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007134 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007135 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7136 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007137 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7138 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139
7140 final long identity = Binder.clearCallingIdentity();
7141 try {
7142 final Phone phone = getPhone(subId);
7143 if (phone == null) {
7144 return false;
7145 }
7146 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7147 cdmaNonRoamingList);
7148 } finally {
7149 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007150 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007151 }
7152
7153 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007154 @Deprecated
7155 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7156 enforceModifyPermission();
7157
7158 int returnValue = 0;
7159 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007160 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007161 if(result.exception == null) {
7162 if (result.result != null) {
7163 byte[] responseData = (byte[])(result.result);
7164 if(responseData.length > oemResp.length) {
7165 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7166 responseData.length + "bytes. Buffer Size is " +
7167 oemResp.length + "bytes.");
7168 }
7169 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7170 returnValue = responseData.length;
7171 }
7172 } else {
7173 CommandException ex = (CommandException) result.exception;
7174 returnValue = ex.getCommandError().ordinal();
7175 if(returnValue > 0) returnValue *= -1;
7176 }
7177 } catch (RuntimeException e) {
7178 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7179 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7180 if(returnValue > 0) returnValue *= -1;
7181 }
7182
7183 return returnValue;
7184 }
7185
7186 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007187 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007188 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007189 try {
7190 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007191 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007192 mApp, phone.getSubId(), "getRadioAccessFamily");
7193 } catch (SecurityException e) {
7194 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7195 throw e;
7196 }
chen xub97461a2018-10-26 14:17:57 -07007197 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007198 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007199 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007200 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201 final long identity = Binder.clearCallingIdentity();
7202 try {
chen xub97461a2018-10-26 14:17:57 -07007203 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007204 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007205 mApp, phone.getSubId(), "getRadioAccessFamily");
7206 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207 } finally {
7208 Binder.restoreCallingIdentity(identity);
7209 }
chen xub97461a2018-10-26 14:17:57 -07007210 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007211 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007212
7213 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007214 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007215 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007216 try {
7217 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7218 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007219 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007220 }
7221 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007222 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007223 }
7224 RoleManager rm = mApp.getSystemService(RoleManager.class);
7225 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7226 if (!dialerRoleHolders.contains(callingPackage)) {
7227 throw new SecurityException("App must be the dialer role holder to"
7228 + " upload a call composer pic");
7229 }
7230
7231 Executors.newSingleThreadExecutor().execute(() -> {
7232 ByteArrayOutputStream output = new ByteArrayOutputStream(
7233 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7234 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7235 boolean readUntilEnd = false;
7236 int totalBytesRead = 0;
7237 byte[] buffer = new byte[16 * 1024];
7238 while (true) {
7239 int numRead;
7240 try {
7241 numRead = input.read(buffer);
7242 } catch (IOException e) {
7243 try {
7244 fd.checkError();
7245 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7246 null);
7247 } catch (IOException e1) {
7248 // This means that the other side closed explicitly with an error. If this
7249 // happens, log and ignore.
7250 loge("Remote end of call composer picture pipe closed: " + e1);
7251 }
7252 break;
7253 }
7254 if (numRead == -1) {
7255 readUntilEnd = true;
7256 break;
7257 }
7258 totalBytesRead += numRead;
7259 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7260 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7261 try {
7262 input.close();
7263 } catch (IOException e) {
7264 // ignore
7265 }
7266 break;
7267 }
7268 output.write(buffer, 0, numRead);
7269 }
7270 // Generally, the remote end will close the file descriptors. The only case where we
7271 // close is above, where the picture size is too big.
7272
7273 try {
7274 fd.checkError();
7275 } catch (IOException e) {
7276 loge("Remote end for call composer closed with an error: " + e);
7277 return;
7278 }
7279
Hall Liuaa4211e2021-01-20 15:43:39 -08007280 if (!readUntilEnd) {
7281 loge("Did not finish reading entire image; aborting");
7282 return;
7283 }
Hall Liu82694d52020-12-11 18:22:04 -08007284
Hall Liuaa4211e2021-01-20 15:43:39 -08007285 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7286 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7287 new CallComposerPictureTransfer.Factory() {},
7288 imageData,
7289 (result) -> {
7290 if (result.first != null) {
7291 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7292 Bundle outputResult = new Bundle();
7293 outputResult.putParcelable(
7294 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7295 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7296 outputResult);
7297 } else {
7298 callback.send(result.second, null);
7299 }
7300 }
7301 );
Hall Liu82694d52020-12-11 18:22:04 -08007302 });
7303 }
7304
7305 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007306 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007307 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007308 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007309
7310 final long identity = Binder.clearCallingIdentity();
7311 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007312 ImsManager.getInstance(defaultPhone.getContext(),
7313 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314 } finally {
7315 Binder.restoreCallingIdentity(identity);
7316 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007317 }
7318
7319 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007320 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007321 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7323 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007324 return false;
7325 }
Svet Ganovb320e182015-04-16 12:30:10 -07007326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 final long identity = Binder.clearCallingIdentity();
7328 try {
7329 // Check the user preference and the system-level IMS setting. Even if the user has
7330 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7331 // In the long run, we may instead need to check if there exists a connection service
7332 // which can support video calling.
7333 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007334 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 return imsManager.isVtEnabledByPlatform()
7336 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7337 && imsManager.isVtEnabledByUser();
7338 } finally {
7339 Binder.restoreCallingIdentity(identity);
7340 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007341 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007342
Andrew Leea1239f22015-03-02 17:44:07 -08007343 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007344 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7345 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007346 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007347 mApp, subId, callingPackage, callingFeatureId,
7348 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007349 return false;
7350 }
7351
7352 final long identity = Binder.clearCallingIdentity();
7353 try {
7354 CarrierConfigManager configManager =
7355 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007356 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7358 } finally {
7359 Binder.restoreCallingIdentity(identity);
7360 }
Andrew Leea1239f22015-03-02 17:44:07 -08007361 }
7362
7363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007364 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007366 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 return false;
7368 }
7369
7370 final long identity = Binder.clearCallingIdentity();
7371 try {
7372 CarrierConfigManager configManager =
7373 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007374 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7376 } finally {
7377 Binder.restoreCallingIdentity(identity);
7378 }
Andrew Leea1239f22015-03-02 17:44:07 -08007379 }
7380
Andrew Lee9431b832015-03-09 18:46:45 -07007381 @Override
7382 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007383 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007384 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007385 }
7386
7387 @Override
7388 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 final long identity = Binder.clearCallingIdentity();
7390 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007391 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007392 } finally {
7393 Binder.restoreCallingIdentity(identity);
7394 }
Andrew Lee9431b832015-03-09 18:46:45 -07007395 }
7396
Hall Liuf6668912018-10-31 17:05:23 -07007397 /**
7398 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7399 * support for the feature and device firmware support.
7400 *
7401 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7402 */
7403 @Override
7404 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007406 final Phone phone = getPhone(subscriptionId);
7407 if (phone == null) {
7408 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7409 return false;
7410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007412 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007413 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7414 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007415 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416 return isCarrierSupported && isDeviceSupported;
7417 } finally {
7418 Binder.restoreCallingIdentity(identity);
7419 }
Hall Liu98187582018-01-22 19:15:32 -08007420 }
7421
Hall Liuf6668912018-10-31 17:05:23 -07007422 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007423 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7424 * RTT setting, will return true if the device and carrier both support RTT.
7425 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007426 */
7427 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 final long identity = Binder.clearCallingIdentity();
7429 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007430 boolean isRttSupported = isRttSupported(subscriptionId);
7431 boolean isUserRttSettingOn = Settings.Secure.getInt(
7432 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7433 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7434 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7435 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 } finally {
7437 Binder.restoreCallingIdentity(identity);
7438 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007439 }
7440
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007441 @Deprecated
7442 @Override
7443 public String getDeviceId(String callingPackage) {
7444 return getDeviceIdWithFeature(callingPackage, null);
7445 }
7446
Sanket Padawe7310cc72015-01-14 09:53:20 -08007447 /**
7448 * Returns the unique device ID of phone, for example, the IMEI for
7449 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7450 *
7451 * <p>Requires Permission:
7452 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7453 */
7454 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007455 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007456 try {
7457 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7458 } catch (SecurityException se) {
7459 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7460 throw new SecurityException("Package " + callingPackage + " does not belong to "
7461 + Binder.getCallingUid());
7462 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007463 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007464 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007465 return null;
7466 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007467 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007468 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007469 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007470 return null;
7471 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472
7473 final long identity = Binder.clearCallingIdentity();
7474 try {
7475 return phone.getDeviceId();
7476 } finally {
7477 Binder.restoreCallingIdentity(identity);
7478 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007479 }
7480
Ping Sunc67b7c22016-03-02 19:16:45 +08007481 /**
7482 * {@hide}
7483 * Returns the IMS Registration Status on a particular subid
7484 *
7485 * @param subId
7486 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007487 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007488 Phone phone = getPhone(subId);
7489 if (phone != null) {
7490 return phone.isImsRegistered();
7491 } else {
7492 return false;
7493 }
7494 }
7495
Santos Cordon7a1885b2015-02-03 11:15:19 -08007496 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007497 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007498 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007500 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007501 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7502 }
7503 final long identity = Binder.clearCallingIdentity();
7504 try {
7505 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7506 } finally {
7507 Binder.restoreCallingIdentity(identity);
7508 }
7509 }
7510
7511 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007512 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007513 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007514 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007515 mApp,
7516 subscriptionId,
7517 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007518 final long identity = Binder.clearCallingIdentity();
7519 try {
7520 Phone phone = getPhone(subscriptionId);
7521 if (phone == null) {
7522 return null;
7523 }
7524 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7525 } finally {
7526 Binder.restoreCallingIdentity(identity);
7527 }
7528 }
7529
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007530 /**
7531 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007532 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007533 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 final long identity = Binder.clearCallingIdentity();
7535 try {
7536 Phone phone = getPhone(subId);
7537 if (phone != null) {
7538 return phone.isWifiCallingEnabled();
7539 } else {
7540 return false;
7541 }
7542 } finally {
7543 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007544 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007545 }
7546
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007547 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007548 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007549 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007550 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 final long identity = Binder.clearCallingIdentity();
7552 try {
7553 Phone phone = getPhone(subId);
7554 if (phone != null) {
7555 return phone.isVideoEnabled();
7556 } else {
7557 return false;
7558 }
7559 } finally {
7560 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007561 }
7562 }
7563
7564 /**
7565 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7566 * defined in {@link ImsRegistrationImplBase}.
7567 */
7568 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569 final long identity = Binder.clearCallingIdentity();
7570 try {
7571 Phone phone = getPhone(subId);
7572 if (phone != null) {
7573 return phone.getImsRegistrationTech();
7574 } else {
7575 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7576 }
7577 } finally {
7578 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007579 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007580 }
7581
Stuart Scott8eef64f2015-04-08 15:13:54 -07007582 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007583 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007584 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007585 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7586 return;
7587 }
Kai Shif70f46f2021-03-03 13:59:46 -08007588 Phone defaultPhone = getDefaultPhone();
7589 if (defaultPhone != null) {
7590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7591 mApp, getDefaultPhone().getSubId(), "factoryReset");
7592 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007593 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007594
Svet Ganovcc087f82015-05-12 20:35:54 -07007595 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007596 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7597 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007598 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007599 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007600 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007601 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007602 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007603 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007604 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007605 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007606 // There has been issues when Sms raw table somehow stores orphan
7607 // fragments. They lead to garbled message when new fragments come
7608 // in and combined with those stale ones. In case this happens again,
7609 // user can reset all network settings which will clean up this table.
7610 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007611 // Clean up IMS settings as well here.
7612 int slotId = getSlotIndex(subId);
7613 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7614 ImsManager.getInstance(mApp, slotId).factoryReset();
7615 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007616
Kai Shif70f46f2021-03-03 13:59:46 -08007617 if (defaultPhone == null) {
7618 return;
7619 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007620 // Erase modem config if erase modem on network setting is enabled.
7621 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7622 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7623 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007624 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007625 }
Kai Shif70f46f2021-03-03 13:59:46 -08007626
7627 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007628 } finally {
7629 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007630 }
7631 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007632
SongFerngWangfd89b102021-05-27 22:44:54 +08007633 @VisibleForTesting
7634 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7635 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7636 return;
7637 }
7638 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7639 RILConstants.PREFERRED_NETWORK_MODE);
7640 SubscriptionManager.setSubscriptionProperty(subId,
7641 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7642 "user=" + defaultNetworkType);
7643 phone.loadAllowedNetworksFromSubscriptionDatabase();
7644 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7645 defaultNetworkType, null);
7646 }
7647
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007648 private void cleanUpSmsRawTable(Context context) {
7649 ContentResolver resolver = context.getContentResolver();
7650 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7651 resolver.delete(uri, null, null);
7652 }
7653
Narayan Kamath1c496c22015-04-16 14:40:19 +01007654 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007655 public String getSimLocaleForSubscriber(int subId) {
7656 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7657 final Phone phone = getPhone(subId);
7658 if (phone == null) {
7659 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007660 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007661 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662 final long identity = Binder.clearCallingIdentity();
7663 try {
chen xu5d3637b2019-01-21 23:31:38 -08007664 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007665 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007666 if (info == null) {
7667 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7668 return null;
7669 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007670 // Try and fetch the locale from the carrier properties or from the SIM language
7671 // preferences (EF-PL and EF-LI)...
7672 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007674 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7675 if (localeFromDefaultSim != null) {
7676 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7677 if (DBG) log("Using locale from subId: " + subId + " locale: "
7678 + localeFromDefaultSim);
7679 return localeFromDefaultSim.toLanguageTag();
7680 } else {
7681 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007682 }
7683 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 // The SIM language preferences only store a language (e.g. fr = French), not an
7686 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7687 // the SIM and carrier preferences does not include a country we add the country
7688 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007689 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007691 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007692 return mccLocale.toLanguageTag();
7693 }
7694
7695 if (DBG) log("No locale found - returning null");
7696 return null;
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
7699 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007700 }
7701
7702 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007703 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007704 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007705 }
7706
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007707 /**
7708 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7709 */
7710 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007711 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007712 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007713 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007714
Gary Jian3aa9a762022-01-24 16:41:19 +08007715 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7716 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007717
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007718 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007719 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7720 * representing the state of the modem.
7721 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007722 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7723 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007724 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007725 */
7726 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007727 public void requestModemActivityInfo(ResultReceiver result) {
7728 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007729 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730
7731 final long identity = Binder.clearCallingIdentity();
7732 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007733 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 } finally {
7735 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007736 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007737 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007738
Siddharth Rayb8114062018-06-17 15:02:38 -07007739 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7740 // less than total activity duration.
7741 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7742 if (info == null) {
7743 return false;
7744 }
7745 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007746 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7747 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7748
Siddharth Rayb8114062018-06-17 15:02:38 -07007749 return (info.isValid()
7750 && (info.getSleepTimeMillis() <= activityDurationMs)
7751 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007752 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007753 && (totalTxTimeMs <= activityDurationMs));
7754 }
7755
Gary Jian3aa9a762022-01-24 16:41:19 +08007756 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7757 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7758 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7759 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7760
7761 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7762 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7763 }
7764
7765 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7766 mLastModemActivityInfo.setReceiveTimeMillis(
7767 rat,
7768 freq,
7769 info.getReceiveTimeMillis(rat, freq)
7770 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7771 }
7772
7773 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7774 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7775 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7776 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7777
7778 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7779 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7780 }
7781 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7782 mLastModemActivityInfo.setReceiveTimeMillis(
7783 rat,
7784 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7785 }
7786
7787 /**
7788 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7789 * @param info recent ModemActivityInfo
7790 */
7791 private void mergeModemActivityInfo(ModemActivityInfo info) {
7792 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7793 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7794 boolean matched;
7795 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7796 matched = false;
7797 int rat = info.getSpecificInfoRat(i);
7798 int freq = info.getSpecificInfoFrequencyRange(i);
7799 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7800 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7801 //if it already exists
7802 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7803 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7804 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7805 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7806 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7807 updateLastModemActivityInfo(info, rat, freq);
7808 matched = true;
7809 }
7810 } else {
7811 updateLastModemActivityInfo(info, rat);
7812 matched = true;
7813 }
7814 }
7815 }
7816
7817 if (!matched) {
7818 mDeltaSpecificInfo =
7819 new ActivityStatsTechSpecificInfo(
7820 rat,
7821 freq,
7822 info.getTransmitTimeMillis(rat, freq),
7823 (int) info.getReceiveTimeMillis(rat, freq));
7824 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7825 }
7826 }
7827 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7828 mLastModemActivitySpecificInfo =
7829 new ActivityStatsTechSpecificInfo[merged.size()];
7830 merged.toArray(mLastModemActivitySpecificInfo);
7831
7832 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7833 mLastModemActivityInfo.setSleepTimeMillis(
7834 info.getSleepTimeMillis()
7835 + mLastModemActivityInfo.getSleepTimeMillis());
7836 mLastModemActivityInfo.setIdleTimeMillis(
7837 info.getIdleTimeMillis()
7838 + mLastModemActivityInfo.getIdleTimeMillis());
7839 }
7840
Jack Yu85bd38a2015-11-09 11:34:32 -08007841 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007842 * Returns the service state information on specified subscription.
7843 */
7844 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007845 public ServiceState getServiceStateForSubscriber(int subId,
7846 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7847 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007848 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007849 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007850 return null;
7851 }
7852
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007853 boolean hasFinePermission = false;
7854 boolean hasCoarsePermission = false;
7855 if (!renounceFineLocationAccess) {
7856 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7857 LocationAccessPolicy.checkLocationPermission(mApp,
7858 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7859 .setCallingPackage(callingPackage)
7860 .setCallingFeatureId(callingFeatureId)
7861 .setCallingPid(Binder.getCallingPid())
7862 .setCallingUid(Binder.getCallingUid())
7863 .setMethod("getServiceStateForSubscriber")
7864 .setLogAsInfo(true)
7865 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7866 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7867 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7868 .build());
7869 hasFinePermission =
7870 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7871 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007872
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007873 if (!renounceCoarseLocationAccess) {
7874 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7875 LocationAccessPolicy.checkLocationPermission(mApp,
7876 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7877 .setCallingPackage(callingPackage)
7878 .setCallingFeatureId(callingFeatureId)
7879 .setCallingPid(Binder.getCallingPid())
7880 .setCallingUid(Binder.getCallingUid())
7881 .setMethod("getServiceStateForSubscriber")
7882 .setLogAsInfo(true)
7883 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7884 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7885 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7886 .build());
7887 hasCoarsePermission =
7888 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7889 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007890
Jack Yu479f40e2020-10-27 21:29:25 -07007891 final Phone phone = getPhone(subId);
7892 if (phone == null) {
7893 return null;
7894 }
7895
Jordan Liu0f2bc442020-11-18 16:47:37 -08007896 final long identity = Binder.clearCallingIdentity();
7897
Jack Yu479f40e2020-10-27 21:29:25 -07007898 boolean isCallingPackageDataService = phone.getDataServicePackages()
7899 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007901 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7902 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7903 Rlog.d(LOG_TAG,
7904 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7905 return null;
7906 }
7907
Hall Liuf19c44f2018-11-27 14:38:17 -08007908 ServiceState ss = phone.getServiceState();
7909
7910 // Scrub out the location info in ServiceState depending on what level of access
7911 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007912 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007913 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7914 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007918 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007919
7920 /**
7921 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7922 *
7923 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7924 * voicemail ringtone.
7925 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7926 * PhoneAccount.
7927 */
7928 @Override
7929 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930 final long identity = Binder.clearCallingIdentity();
7931 try {
7932 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7933 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007934 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7938 } finally {
7939 Binder.restoreCallingIdentity(identity);
7940 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007941 }
7942
7943 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007944 * Sets the per-account voicemail ringtone.
7945 *
7946 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7947 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7948 *
7949 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7950 * voicemail ringtone.
7951 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7952 * PhoneAccount.
7953 */
7954 @Override
7955 public void setVoicemailRingtoneUri(String callingPackage,
7956 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007957 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007958 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007959 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7960 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7962 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7963 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007964 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007965
7966 final long identity = Binder.clearCallingIdentity();
7967 try {
7968 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7969 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007970 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007971 }
7972 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7973 } finally {
7974 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007975 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007976 }
7977
7978 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007979 * Returns whether vibration is set for voicemail notification in Phone settings.
7980 *
7981 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7982 * voicemail vibration setting.
7983 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7984 */
7985 @Override
7986 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987 final long identity = Binder.clearCallingIdentity();
7988 try {
7989 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7990 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007991 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007994 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7995 } finally {
7996 Binder.restoreCallingIdentity(identity);
7997 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007998 }
7999
Youhan Wange64578a2016-05-02 15:32:42 -07008000 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008001 * Sets the per-account voicemail vibration.
8002 *
8003 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8004 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8005 *
8006 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8007 * voicemail vibration setting.
8008 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8009 * specific PhoneAccount.
8010 */
8011 @Override
8012 public void setVoicemailVibrationEnabled(String callingPackage,
8013 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008014 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008016 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8017 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8019 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8020 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008021 }
8022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008023 final long identity = Binder.clearCallingIdentity();
8024 try {
8025 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8026 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008027 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008028 }
8029 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8030 } finally {
8031 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008032 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008033 }
8034
8035 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008036 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8037 *
8038 * @throws SecurityException if the caller does not have the required permission
8039 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008040 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008041 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008042 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008043 }
8044
8045 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008046 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8047 * permission.
8048 *
8049 * @throws SecurityException if the caller does not have the required permission
8050 */
8051 private void enforceSendSmsPermission() {
8052 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8053 }
8054
8055 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008056 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008057 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008058 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008059 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008060 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008061 final long identity = Binder.clearCallingIdentity();
8062 try {
8063 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008064 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008065 if (componentName == null) {
8066 throw new SecurityException(
8067 "Caller not current active visual voicemail package[null]");
8068 }
8069 String vvmPackage = componentName.getPackageName();
8070 if (!callingPackage.equals(vvmPackage)) {
8071 throw new SecurityException("Caller not current active visual voicemail package["
8072 + vvmPackage + "]");
8073 }
8074 } finally {
8075 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008076 }
8077 }
8078
8079 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008080 * Return the application ID for the app type.
8081 *
8082 * @param subId the subscription ID that this request applies to.
8083 * @param appType the uicc app type.
8084 * @return Application ID for specificied app type, or null if no uicc.
8085 */
8086 @Override
8087 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008088 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008089 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090
8091 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008092 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093 if (phone == null) {
8094 return null;
8095 }
8096 String aid = null;
8097 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008098 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008099 .getApplicationByType(appType).getAid();
8100 } catch (Exception e) {
8101 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8102 }
8103 return aid;
8104 } finally {
8105 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008106 }
Youhan Wange64578a2016-05-02 15:32:42 -07008107 }
8108
Youhan Wang4001d252016-05-11 10:29:41 -07008109 /**
8110 * Return the Electronic Serial Number.
8111 *
8112 * @param subId the subscription ID that this request applies to.
8113 * @return ESN or null if error.
8114 */
8115 @Override
8116 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008117 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008118 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008119
8120 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008121 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008122 if (phone == null) {
8123 return null;
8124 }
8125 String esn = null;
8126 try {
8127 esn = phone.getEsn();
8128 } catch (Exception e) {
8129 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8130 }
8131 return esn;
8132 } finally {
8133 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008134 }
Youhan Wang4001d252016-05-11 10:29:41 -07008135 }
8136
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008137 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008138 * Return the Preferred Roaming List Version.
8139 *
8140 * @param subId the subscription ID that this request applies to.
8141 * @return PRLVersion or null if error.
8142 */
8143 @Override
8144 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008145 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008146 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008147
8148 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008149 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008150 if (phone == null) {
8151 return null;
8152 }
8153 String cdmaPrlVersion = null;
8154 try {
8155 cdmaPrlVersion = phone.getCdmaPrlVersion();
8156 } catch (Exception e) {
8157 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8158 }
8159 return cdmaPrlVersion;
8160 } finally {
8161 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008162 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008163 }
8164
8165 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008166 * Get snapshot of Telephony histograms
8167 * @return List of Telephony histograms
8168 * @hide
8169 */
8170 @Override
8171 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8173 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008174
8175 final long identity = Binder.clearCallingIdentity();
8176 try {
8177 return RIL.getTelephonyRILTimingHistograms();
8178 } finally {
8179 Binder.restoreCallingIdentity(identity);
8180 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008181 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008182
8183 /**
8184 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008185 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8186 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008187 * Require system privileges. In the future we may add this to carrier APIs.
8188 *
Michele Berionne482f8202018-11-27 18:57:59 -08008189 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008190 */
8191 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008192 @TelephonyManager.SetCarrierRestrictionResult
8193 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008194 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008195 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008196
Michele Berionne482f8202018-11-27 18:57:59 -08008197 if (carrierRestrictionRules == null) {
8198 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008199 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008201 final long identity = Binder.clearCallingIdentity();
8202 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008203 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008204 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008205 } finally {
8206 Binder.restoreCallingIdentity(identity);
8207 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008208 }
8209
8210 /**
8211 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008212 * Get the allowed carrier list and the excluded carrier list, including the priority between
8213 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008214 * Require system privileges. In the future we may add this to carrier APIs.
8215 *
Michele Berionne482f8202018-11-27 18:57:59 -08008216 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008217 */
8218 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008219 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008220 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008221 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008222
8223 final long identity = Binder.clearCallingIdentity();
8224 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008225 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8226 if (response instanceof CarrierRestrictionRules) {
8227 return (CarrierRestrictionRules) response;
8228 }
8229 // Response is an Exception of some kind,
8230 // which is signalled to the user as a NULL retval
8231 return null;
8232 } catch (Exception e) {
8233 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8234 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008235 } finally {
8236 Binder.restoreCallingIdentity(identity);
8237 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008238 }
8239
fionaxu59545b42016-05-25 15:53:37 -07008240 /**
fionaxu59545b42016-05-25 15:53:37 -07008241 * Action set from carrier signalling broadcast receivers to enable/disable radio
8242 * @param subId the subscription ID that this action applies to.
8243 * @param enabled control enable or disable radio.
8244 * {@hide}
8245 */
8246 @Override
8247 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8248 enforceModifyPermission();
8249 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008250
8251 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008252 if (phone == null) {
8253 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8254 return;
8255 }
8256 try {
8257 phone.carrierActionSetRadioEnabled(enabled);
8258 } catch (Exception e) {
8259 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008260 } finally {
8261 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008262 }
8263 }
8264
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008265 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008266 * Enable or disable Voice over NR (VoNR)
8267 * @param subId the subscription ID that this action applies to.
8268 * @param enabled enable or disable VoNR.
8269 * @return operation result.
8270 */
8271 @Override
8272 public int setVoNrEnabled(int subId, boolean enabled) {
8273 enforceModifyPermission();
8274 final Phone phone = getPhone(subId);
8275
8276 final long identity = Binder.clearCallingIdentity();
8277 if (phone == null) {
8278 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8279 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8280 }
8281
8282 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8283 try {
8284 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8285 workSource);
8286 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008287
8288 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8289 if (DBG) {
8290 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8291 }
8292 SubscriptionManager.setSubscriptionProperty(
8293 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8294 (enabled ? "1" : "0"));
8295 }
8296
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008297 return result;
8298 } finally {
8299 Binder.restoreCallingIdentity(identity);
8300 }
8301 }
8302
8303 /**
8304 * Is voice over NR enabled
8305 * @return true if VoNR is enabled else false
8306 */
8307 @Override
8308 public boolean isVoNrEnabled(int subId) {
8309 enforceReadPrivilegedPermission("isVoNrEnabled");
8310 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8311 final long identity = Binder.clearCallingIdentity();
8312 try {
8313 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8314 null, subId, workSource);
8315 if (DBG) log("isVoNrEnabled: " + isEnabled);
8316 return isEnabled;
8317 } finally {
8318 Binder.restoreCallingIdentity(identity);
8319 }
8320 }
8321
8322 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008323 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8324 * network status based on which carrier apps could apply actions accordingly,
8325 * enable/disable default url handler for example.
8326 *
8327 * @param subId the subscription ID that this action applies to.
8328 * @param report control start/stop reporting the default network status.
8329 * {@hide}
8330 */
8331 @Override
8332 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8333 enforceModifyPermission();
8334 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335
8336 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008337 if (phone == null) {
8338 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8339 return;
8340 }
8341 try {
8342 phone.carrierActionReportDefaultNetworkStatus(report);
8343 } catch (Exception e) {
8344 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008345 } finally {
8346 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008347 }
8348 }
8349
8350 /**
fionaxud9622282017-07-17 17:51:30 -07008351 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8352 * @param subId the subscription ID that this action applies to.
8353 * {@hide}
8354 */
8355 @Override
8356 public void carrierActionResetAll(int subId) {
8357 enforceModifyPermission();
8358 final Phone phone = getPhone(subId);
8359 if (phone == null) {
8360 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8361 return;
8362 }
8363 try {
8364 phone.carrierActionResetAll();
8365 } catch (Exception e) {
8366 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8367 }
8368 }
8369
8370 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008371 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8372 * bug report is being generated.
8373 */
8374 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008375 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008376 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8377 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008378 writer.println("Permission Denial: can't dump Phone from pid="
8379 + Binder.getCallingPid()
8380 + ", uid=" + Binder.getCallingUid()
8381 + "without permission "
8382 + android.Manifest.permission.DUMP);
8383 return;
8384 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008385 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008386 }
Jack Yueb89b242016-06-22 13:27:47 -07008387
Brad Ebingerdac2f002018-04-03 15:17:52 -07008388 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008389 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8390 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8391 @NonNull String[] args) {
8392 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8393 this, in.getFileDescriptor(), out.getFileDescriptor(),
8394 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008395 }
8396
Jack Yueb89b242016-06-22 13:27:47 -07008397 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008398 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008399 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008400 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008401 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008402 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008403 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008404 */
8405 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008406 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008407 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008408 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8409 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8410 try {
8411 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008412 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008413 } catch (SecurityException se) {
8414 enforceModifyPermission();
8415 }
8416 } else {
8417 enforceModifyPermission();
8418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008419
8420 final long identity = Binder.clearCallingIdentity();
8421 try {
8422 Phone phone = getPhone(subId);
8423 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008424 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8425 phone.carrierActionSetMeteredApnsEnabled(enabled);
8426 } else {
Jack Yuf86fb842022-07-31 00:43:21 -07008427 phone.getDataSettingsManager().setDataEnabled(
8428 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008430 }
8431 } finally {
8432 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008433 }
8434 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008435
8436 /**
8437 * Get Client request stats
8438 * @return List of Client Request Stats
8439 * @hide
8440 */
8441 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008442 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8443 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008444 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008445 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008446 return null;
8447 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008448 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450 final long identity = Binder.clearCallingIdentity();
8451 try {
8452 if (phone != null) {
8453 return phone.getClientRequestStats();
8454 }
8455
8456 return null;
8457 } finally {
8458 Binder.restoreCallingIdentity(identity);
8459 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008460 }
8461
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008462 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008463 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008464 if (uid == Process.ROOT_UID && packageName == null) {
8465 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8466 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8467 // exception. ROOT_UID seems not to have a valid package name returned by
8468 // PackageManager, so just fake it here to avoid issues when running telephony shell
8469 // commands that plumb through the RIL as root, like so:
8470 // $ adb root
8471 // $ adb shell cmd phone ...
8472 packageName = "root";
8473 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008474 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008475 }
Jack Yueb4124c2017-02-16 15:32:43 -08008476
8477 /**
Grace Chen70990072017-03-24 17:21:30 -07008478 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008479 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008480 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008481 * @param state State of SIM (power down, power up, pass through)
8482 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8483 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8484 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008485 *
8486 **/
8487 @Override
Grace Chen70990072017-03-24 17:21:30 -07008488 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008489 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008490 Phone phone = PhoneFactory.getPhone(slotIndex);
8491
vagdeviaf9a5b92018-08-15 16:01:53 -07008492 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008494 final long identity = Binder.clearCallingIdentity();
8495 try {
8496 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008497 phone.setSimPowerState(state, null, workSource);
8498 }
8499 } finally {
8500 Binder.restoreCallingIdentity(identity);
8501 }
8502 }
8503
8504 /**
8505 * Set SIM card power state.
8506 *
8507 * @param slotIndex SIM slot id.
8508 * @param state State of SIM (power down, power up, pass through)
8509 * @param callback callback to trigger after success or failure
8510 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8511 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8512 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8513 *
8514 **/
8515 @Override
8516 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8517 IIntegerConsumer callback) {
8518 enforceModifyPermission();
8519 Phone phone = PhoneFactory.getPhone(slotIndex);
8520
8521 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8522
8523 final long identity = Binder.clearCallingIdentity();
8524 try {
8525 if (phone != null) {
8526 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8527 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008528 }
8529 } finally {
8530 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008531 }
8532 }
Shuo Qiandd210312017-04-12 22:11:33 +00008533
Tyler Gunn65d45c22017-06-05 11:22:26 -07008534 private boolean isUssdApiAllowed(int subId) {
8535 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008536 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008537 if (configManager == null) {
8538 return false;
8539 }
8540 PersistableBundle pb = configManager.getConfigForSubId(subId);
8541 if (pb == null) {
8542 return false;
8543 }
8544 return pb.getBoolean(
8545 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8546 }
8547
Shuo Qiandd210312017-04-12 22:11:33 +00008548 /**
8549 * Check if phone is in emergency callback mode
8550 * @return true if phone is in emergency callback mode
8551 * @param subId sub id
8552 */
goneil9c5f4872017-12-05 14:07:56 -08008553 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008554 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008555 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008556 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008557
8558 final long identity = Binder.clearCallingIdentity();
8559 try {
8560 if (phone != null) {
8561 return phone.isInEcm();
8562 } else {
8563 return false;
8564 }
8565 } finally {
8566 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008567 }
8568 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008569
8570 /**
8571 * Get the current signal strength information for the given subscription.
8572 * Because this information is not updated when the device is in a low power state
8573 * it should not be relied-upon to be current.
8574 * @param subId Subscription index
8575 * @return the most recent cached signal strength info from the modem
8576 */
8577 @Override
8578 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008579 final long identity = Binder.clearCallingIdentity();
8580 try {
8581 Phone p = getPhone(subId);
8582 if (p == null) {
8583 return null;
8584 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008585
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008586 return p.getSignalStrength();
8587 } finally {
8588 Binder.restoreCallingIdentity(identity);
8589 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008590 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008591
Pengquan Meng77b7f132018-08-22 14:49:57 -07008592 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008593 * Get the current modem radio state for the given slot.
8594 * @param slotIndex slot index.
8595 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008596 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008597 * @return the current radio power state from the modem
8598 */
8599 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008600 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008601 Phone phone = PhoneFactory.getPhone(slotIndex);
8602 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8604 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008605 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8606 }
8607
8608 final long identity = Binder.clearCallingIdentity();
8609 try {
8610 return phone.getRadioPowerState();
8611 } finally {
8612 Binder.restoreCallingIdentity(identity);
8613 }
8614 }
8615 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8616 }
8617
8618 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008619 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8620 *
8621 * <p>Requires one of the following permissions:
8622 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008623 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008624 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8625 * privileges.
8626 *
8627 * @param subId subscription id
8628 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8629 * {@code false}.
8630 */
8631 @Override
8632 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008633 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008634 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008635 try {
8636 mApp.enforceCallingOrSelfPermission(
8637 android.Manifest.permission.ACCESS_NETWORK_STATE,
8638 functionName);
8639 } catch (Exception e) {
8640 mApp.enforceCallingOrSelfPermission(
8641 permission.READ_BASIC_PHONE_STATE, functionName);
8642 }
Shuo Qian093013d2020-08-13 15:42:55 -07008643 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008644 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008645 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008646 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008647
Pengquan Menga1bb6272018-09-06 09:59:22 -07008648 boolean isEnabled = false;
8649 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008650 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008651 Phone phone = getPhone(subId);
8652 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008653 } finally {
8654 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008656 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008657 }
8658
8659
8660 /**
8661 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8662 *
8663 * <p> Requires permission:
8664 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8665 * privileges.
8666 *
8667 * @param subId subscription id
8668 * @param isEnabled {@code true} means enable, {@code false} means disable.
8669 */
8670 @Override
8671 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8673 mApp, subId, "setDataRoamingEnabled");
8674
Pengquan Menga1bb6272018-09-06 09:59:22 -07008675 final long identity = Binder.clearCallingIdentity();
8676 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008677 Phone phone = getPhone(subId);
8678 if (phone != null) {
8679 phone.setDataRoamingEnabled(isEnabled);
8680 }
8681 } finally {
8682 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008683 }
8684 }
8685
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008686 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008687 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008688 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008689 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008690 mApp, subId, "isManualNetworkSelectionAllowed");
8691
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008692 boolean isAllowed = true;
8693 final long identity = Binder.clearCallingIdentity();
8694 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008695 Phone phone = getPhone(subId);
8696 if (phone != null) {
8697 isAllowed = phone.isCspPlmnEnabled();
8698 }
8699 } finally {
8700 Binder.restoreCallingIdentity(identity);
8701 }
8702 return isAllowed;
8703 }
8704
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008705 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8706 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008707 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008708 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008709 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008710 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8711 if (phone == null) {
8712 return false;
8713 }
8714 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8715 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8716 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008717 }
8718
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008719 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008720 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008721 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008722 mApp.getSystemService(AppOpsManager.class)
8723 .checkPackage(Binder.getCallingUid(), callingPackage);
8724
Jordan Liu1e142fc2019-04-22 15:10:43 -07008725 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008726 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008727 try {
8728 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008729 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008730 } catch (SecurityException e) {
8731 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8732 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008733 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008734 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008735 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008736 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008737 }
sandeepjsb6c87872021-09-27 15:34:44 +00008738 // checking compatibility, if calling app's target SDK is T and beyond.
8739 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8740 Binder.getCallingUid())) {
8741 isIccIdAccessRestricted = true;
8742 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008743 final long identity = Binder.clearCallingIdentity();
8744 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008745 UiccController uiccController = UiccController.getInstance();
8746 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008747 if (hasReadPermission) {
8748 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008749 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008750
8751 // Remove private info if the caller doesn't have access
8752 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8753 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008754 //setting the value after compatibility check
8755 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008756 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8757 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008758 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008759 if (card == null) {
8760 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008761 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008762 continue;
8763 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008764 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8765 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008766 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008767 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008768 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008769 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8770 for (UiccPortInfo portInfo : portInfos) {
8771 UiccPort port = uiccController.getUiccPortForSlot(
8772 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8773 if (port == null) {
8774 // assume no access if port is null
8775 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8776 continue;
8777 }
8778 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8779 uiccPortInfos.add(portInfo);
8780 } else {
8781 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8782 }
8783 }
8784 filteredInfos.add(new UiccCardInfo(
8785 cardInfo.isEuicc(),
8786 cardInfo.getCardId(),
8787 null,
8788 cardInfo.getPhysicalSlotIndex(),
8789 cardInfo.isRemovable(),
8790 cardInfo.isMultipleEnabledProfilesSupported(),
8791 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008792 }
8793 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008794 } finally {
8795 Binder.restoreCallingIdentity(identity);
8796 }
8797 }
8798
sandeepjsb6c87872021-09-27 15:34:44 +00008799 /**
8800 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8801 * generally private and require carrier privileges to view.
8802 *
8803 * @hide
8804 */
8805 @NonNull
8806 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8807 List<UiccPortInfo> portinfo = new ArrayList<>();
8808 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8809 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8810 }
8811 return new UiccCardInfo(
8812 cardInfo.isEuicc(),
8813 cardInfo.getCardId(),
8814 null,
8815 cardInfo.getPhysicalSlotIndex(),
8816 cardInfo.isRemovable(),
8817 cardInfo.isMultipleEnabledProfilesSupported(),
8818 portinfo
8819 );
8820 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008821
sandeepjsb6c87872021-09-27 15:34:44 +00008822 /**
8823 * @hide
8824 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8825 * These values are generally private and require carrier privileges to view.
8826 */
8827 @NonNull
8828 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8829 return new UiccPortInfo(
8830 UiccPortInfo.ICCID_REDACTED,
8831 portInfo.getPortIndex(),
8832 portInfo.getLogicalSlotIndex(),
8833 portInfo.isActive()
8834 );
8835 }
8836 @Override
8837 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008838 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008839 mApp.getSystemService(AppOpsManager.class)
8840 .checkPackage(Binder.getCallingUid(), callingPackage);
8841
sandeepjsb6c87872021-09-27 15:34:44 +00008842 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008843
Aman Guptaf3c90b32022-03-17 04:54:16 +00008844 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8845 // we are reading iccId which is PII data.
8846 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008847
8848 // checking compatibility, if calling app's target SDK is T and beyond.
8849 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8850 Binder.getCallingUid())) {
8851 isLogicalSlotAccessRestricted = true;
8852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008853 final long identity = Binder.clearCallingIdentity();
8854 try {
8855 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008856 if (slots == null || slots.length == 0) {
8857 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008858 return null;
8859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008860 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8861 for (int i = 0; i < slots.length; i++) {
8862 UiccSlot slot = slots[i];
8863 if (slot == null) {
8864 continue;
8865 }
8866
Jordan Liu7be7e652019-05-06 18:55:02 +00008867 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008868 UiccCard card = slot.getUiccCard();
8869 if (card != null) {
8870 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008871 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008872 cardId = slot.getEid();
8873 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008874 // If cardId is null, use iccId of default port as cardId.
8875 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008877 }
8878
Jordan Liu857451f2019-05-09 16:35:35 -07008879 if (cardId != null) {
8880 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8881 // if cardId is an EID, it's all digits so this is fine
8882 cardId = IccUtils.stripTrailingFs(cardId);
8883 }
8884
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008885 int cardState = 0;
8886 switch (slot.getCardState()) {
8887 case CARDSTATE_ABSENT:
8888 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8889 break;
8890 case CARDSTATE_PRESENT:
8891 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8892 break;
8893 case CARDSTATE_ERROR:
8894 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8895 break;
8896 case CARDSTATE_RESTRICTED:
8897 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8898 break;
8899 default:
8900 break;
8901
8902 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008903 List<UiccPortInfo> portInfos = new ArrayList<>();
8904 int[] portIndexes = slot.getPortList();
8905 for (int portIdx : portIndexes) {
8906 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00008907 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008908 portInfos.add(new UiccPortInfo(iccId, portIdx,
8909 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008911 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008912 slot.isEuicc(),
8913 cardId,
8914 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008915 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008916 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008917 //setting the value after compatibility check
8918 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008919 }
8920 return infos;
8921 } finally {
8922 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008923 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008924 }
8925
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008926 /* Returns null if doesn't have read permission or carrier privilege access. */
8927 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8928 boolean hasReadPermission) {
8929 String iccId = slot.getIccId(portIndex);
8930 if (hasReadPermission) { // if has read permission
8931 return iccId;
8932 } else {
8933 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8934 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8935 // if no read permission, checking carrier privilege access
8936 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8937 return iccId;
8938 }
8939 }
8940 }
8941 // No read permission or carrier privilege access.
8942 return UiccPortInfo.ICCID_REDACTED;
8943 }
8944
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008945 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008946 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008947 public boolean switchSlots(int[] physicalSlots) {
8948 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008949
8950 final long identity = Binder.clearCallingIdentity();
8951 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008952 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8953 for (int i = 0; i < physicalSlots.length; i++) {
8954 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8955 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8956 physicalSlots[i], i));
8957 }
8958 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008959 } finally {
8960 Binder.restoreCallingIdentity(identity);
8961 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008962 }
Jack Yu4c988042018-02-27 15:30:01 -08008963
8964 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008965 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8966 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8967 enforceModifyPermission();
8968
8969 final long identity = Binder.clearCallingIdentity();
8970 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008971 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00008972 } finally {
8973 Binder.restoreCallingIdentity(identity);
8974 }
8975 }
8976
8977 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008978 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008979 final long identity = Binder.clearCallingIdentity();
8980 try {
8981 return UiccController.getInstance().getCardIdForDefaultEuicc();
8982 } finally {
8983 Binder.restoreCallingIdentity(identity);
8984 }
8985 }
8986
Pengquan Meng85728fb2018-03-12 16:31:21 -07008987 /**
goneil47ffb6e2018-04-06 15:40:58 -07008988 * A test API to reload the UICC profile.
8989 *
8990 * <p>Requires that the calling app has permission
8991 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8992 * @hide
8993 */
8994 @Override
8995 public void refreshUiccProfile(int subId) {
8996 enforceModifyPermission();
8997
8998 final long identity = Binder.clearCallingIdentity();
8999 try {
9000 Phone phone = getPhone(subId);
9001 if (phone == null) {
9002 return;
9003 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009004 UiccPort uiccPort = phone.getUiccPort();
9005 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009006 return;
9007 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009008 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009009 if (uiccProfile == null) {
9010 return;
9011 }
9012 uiccProfile.refresh();
9013 } finally {
9014 Binder.restoreCallingIdentity(identity);
9015 }
9016 }
9017
9018 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009019 * Returns false if the mobile data is disabled by default, otherwise return true.
9020 */
9021 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009022 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009023 }
9024
9025 /**
9026 * Returns true if the data roaming is enabled by default, i.e the system property
9027 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9028 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9029 */
9030 private boolean getDefaultDataRoamingEnabled(int subId) {
9031 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009032 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009033 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009034 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9035 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9036 return isDataRoamingEnabled;
9037 }
9038
9039 /**
9040 * Returns the default network type for the given {@code subId}, if the default network type is
9041 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9042 */
9043 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009044 List<Integer> list = TelephonyProperties.default_network();
9045 int phoneId = mSubscriptionController.getPhoneId(subId);
9046 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9047 return list.get(phoneId);
9048 }
9049 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009050 }
fionaxua13278b2018-03-21 00:08:13 -07009051
9052 @Override
9053 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009054 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009055 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009056
9057 final long identity = Binder.clearCallingIdentity();
9058 try {
9059 final Phone phone = getPhone(subId);
9060 if (phone == null) {
9061 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9062 return;
9063 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009064 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9065 if (cpt != null) {
9066 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9067 }
9068 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009069 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9070 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009071 if (carrierPrivilegeRules == null) {
9072 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9073 } else {
9074 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009076 } finally {
9077 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009078 }
fionaxua13278b2018-03-21 00:08:13 -07009079 }
9080
9081 @Override
9082 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009083 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009084
9085 final long identity = Binder.clearCallingIdentity();
9086 try {
9087 final Phone phone = getPhone(subId);
9088 if (phone == null) {
9089 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9090 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9091 }
9092 return phone.getCarrierIdListVersion();
9093 } finally {
9094 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009095 }
fionaxua13278b2018-03-21 00:08:13 -07009096 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009097
9098 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009099 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9100 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009102 mApp, subId, callingPackage, callingFeatureId,
9103 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009104 return -1;
9105 }
9106
9107 final long identity = Binder.clearCallingIdentity();
9108 try {
9109 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9110 } finally {
9111 Binder.restoreCallingIdentity(identity);
9112 }
9113 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009114
9115 @Override
9116 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009117 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009118 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009119 mApp, subId, "getCdmaRoamingMode");
9120
9121 final long identity = Binder.clearCallingIdentity();
9122 try {
9123 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9124 } finally {
9125 Binder.restoreCallingIdentity(identity);
9126 }
9127 }
9128
9129 @Override
9130 public boolean setCdmaRoamingMode(int subId, int mode) {
9131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9132 mApp, subId, "setCdmaRoamingMode");
9133
9134 final long identity = Binder.clearCallingIdentity();
9135 try {
9136 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9137 } finally {
9138 Binder.restoreCallingIdentity(identity);
9139 }
9140 }
9141
9142 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009143 public int getCdmaSubscriptionMode(int subId) {
9144 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009145 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009146 mApp, subId, "getCdmaSubscriptionMode");
9147
9148 final long identity = Binder.clearCallingIdentity();
9149 try {
9150 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9151 } finally {
9152 Binder.restoreCallingIdentity(identity);
9153 }
9154 }
9155
9156 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009157 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9159 mApp, subId, "setCdmaSubscriptionMode");
9160
9161 final long identity = Binder.clearCallingIdentity();
9162 try {
9163 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9164 } finally {
9165 Binder.restoreCallingIdentity(identity);
9166 }
9167 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009168
sqianc5eccab2018-10-19 18:46:41 -07009169 @Override
sqian8c685422019-02-22 15:55:18 -08009170 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009171 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009173 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9174 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009175 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9176 }
9177 final long identity = Binder.clearCallingIdentity();
9178 try {
sqian854d44b2018-12-12 16:48:18 -08009179 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9180 for (Phone phone: PhoneFactory.getPhones()) {
9181 if (phone.getEmergencyNumberTracker() != null
9182 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9183 emergencyNumberListInternal.put(
9184 phone.getSubId(),
9185 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9186 }
sqian11b7a0e2018-12-05 18:48:28 -08009187 }
sqian854d44b2018-12-12 16:48:18 -08009188 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009189 } finally {
9190 Binder.restoreCallingIdentity(identity);
9191 }
sqianc5eccab2018-10-19 18:46:41 -07009192 }
9193
9194 @Override
sqian8c685422019-02-22 15:55:18 -08009195 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009196 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009197 if (!exactMatch) {
9198 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009199 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009200 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009201 }
9202 final long identity = Binder.clearCallingIdentity();
9203 try {
sqian854d44b2018-12-12 16:48:18 -08009204 for (Phone phone: PhoneFactory.getPhones()) {
9205 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009206 && phone.getEmergencyNumberTracker()
9207 .isEmergencyNumber(number, exactMatch)) {
9208 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009209 }
sqian11b7a0e2018-12-05 18:48:28 -08009210 }
9211 return false;
9212 } finally {
9213 Binder.restoreCallingIdentity(identity);
9214 }
9215 }
9216
sqianf4ca7ed2019-01-15 18:32:07 -08009217 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009218 * Start emergency callback mode for GsmCdmaPhone for testing.
9219 */
9220 @Override
9221 public void startEmergencyCallbackMode() {
9222 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9223 "startEmergencyCallbackMode");
9224 enforceModifyPermission();
9225 final long identity = Binder.clearCallingIdentity();
9226 try {
9227 for (Phone phone : PhoneFactory.getPhones()) {
9228 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9229 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9230 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9231 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9232 gsmCdmaPhone.obtainMessage(
9233 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9234 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9235 }
9236 }
9237 } finally {
9238 Binder.restoreCallingIdentity(identity);
9239 }
9240 }
9241
9242 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009243 * Update emergency number list for test mode.
9244 */
9245 @Override
9246 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9247 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9248 "updateEmergencyNumberListTestMode");
9249
9250 final long identity = Binder.clearCallingIdentity();
9251 try {
9252 for (Phone phone: PhoneFactory.getPhones()) {
9253 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9254 if (tracker != null) {
9255 tracker.executeEmergencyNumberTestModeCommand(action, num);
9256 }
9257 }
9258 } finally {
9259 Binder.restoreCallingIdentity(identity);
9260 }
9261 }
9262
9263 /**
9264 * Get the full emergency number list for test mode.
9265 */
9266 @Override
9267 public List<String> getEmergencyNumberListTestMode() {
9268 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9269 "getEmergencyNumberListTestMode");
9270
9271 final long identity = Binder.clearCallingIdentity();
9272 try {
9273 Set<String> emergencyNumbers = new HashSet<>();
9274 for (Phone phone: PhoneFactory.getPhones()) {
9275 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9276 if (tracker != null) {
9277 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9278 emergencyNumbers.add(num.getNumber());
9279 }
9280 }
9281 }
9282 return new ArrayList<>(emergencyNumbers);
9283 } finally {
9284 Binder.restoreCallingIdentity(identity);
9285 }
9286 }
9287
chen xud6b45bd2018-10-30 22:27:10 -07009288 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009289 public int getEmergencyNumberDbVersion(int subId) {
9290 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9291
9292 final long identity = Binder.clearCallingIdentity();
9293 try {
9294 final Phone phone = getPhone(subId);
9295 if (phone == null) {
9296 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9297 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9298 }
9299 return phone.getEmergencyNumberDbVersion();
9300 } finally {
9301 Binder.restoreCallingIdentity(identity);
9302 }
9303 }
9304
9305 @Override
9306 public void notifyOtaEmergencyNumberDbInstalled() {
9307 enforceModifyPermission();
9308
9309 final long identity = Binder.clearCallingIdentity();
9310 try {
9311 for (Phone phone: PhoneFactory.getPhones()) {
9312 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9313 if (tracker != null) {
9314 tracker.updateOtaEmergencyNumberDatabase();
9315 }
9316 }
9317 } finally {
9318 Binder.restoreCallingIdentity(identity);
9319 }
9320 }
9321
9322 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009323 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009324 enforceActiveEmergencySessionPermission();
9325
9326 final long identity = Binder.clearCallingIdentity();
9327 try {
9328 for (Phone phone: PhoneFactory.getPhones()) {
9329 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9330 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009331 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9332 }
9333 }
9334 } finally {
9335 Binder.restoreCallingIdentity(identity);
9336 }
9337 }
9338
9339 @Override
9340 public void resetOtaEmergencyNumberDbFilePath() {
9341 enforceActiveEmergencySessionPermission();
9342
9343 final long identity = Binder.clearCallingIdentity();
9344 try {
9345 for (Phone phone: PhoneFactory.getPhones()) {
9346 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9347 if (tracker != null) {
9348 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009349 }
9350 }
9351 } finally {
9352 Binder.restoreCallingIdentity(identity);
9353 }
9354 }
9355
9356 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009357 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9358 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9359 Phone phone = getPhone(subId);
9360 if (phone == null) {
9361 return null;
9362 }
9363 final long identity = Binder.clearCallingIdentity();
9364 try {
9365 UiccProfile profile = UiccController.getInstance()
9366 .getUiccProfileForPhone(phone.getPhoneId());
9367 if (profile != null) {
9368 return profile.getCertsFromCarrierPrivilegeAccessRules();
9369 }
9370 } finally {
9371 Binder.restoreCallingIdentity(identity);
9372 }
9373 return null;
9374 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009375
9376 /**
9377 * Enable or disable a modem stack.
9378 */
9379 @Override
9380 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9381 enforceModifyPermission();
9382
9383 final long identity = Binder.clearCallingIdentity();
9384 try {
9385 Phone phone = PhoneFactory.getPhone(slotIndex);
9386 if (phone == null) {
9387 return false;
9388 } else {
9389 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9390 }
9391 } finally {
9392 Binder.restoreCallingIdentity(identity);
9393 }
9394 }
Michelecea4cf22018-12-21 15:00:11 -08009395
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009396 /**
9397 * Whether a modem stack is enabled or not.
9398 */
9399 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009400 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9401 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009402 Phone phone = PhoneFactory.getPhone(slotIndex);
9403 if (phone == null) return false;
9404
9405 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009406 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9407 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009408 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9409 }
9410
9411 final long identity = Binder.clearCallingIdentity();
9412 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009413 try {
9414 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9415 } catch (NoSuchElementException ex) {
9416 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9417 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009418 } finally {
9419 Binder.restoreCallingIdentity(identity);
9420 }
9421 }
9422
Michelecea4cf22018-12-21 15:00:11 -08009423 @Override
Michele0ea7d782019-03-19 14:58:42 -07009424 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009425 enforceModifyPermission();
9426
9427 final long identity = Binder.clearCallingIdentity();
9428 try {
9429 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009430 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009431 .commit();
9432 } finally {
9433 Binder.restoreCallingIdentity(identity);
9434 }
9435 }
9436
9437 @Override
Michele0ea7d782019-03-19 14:58:42 -07009438 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009439 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009440 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009441 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9442 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009443 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009444 }
Michelecea4cf22018-12-21 15:00:11 -08009445
9446 final long identity = Binder.clearCallingIdentity();
9447 try {
Michele0ea7d782019-03-19 14:58:42 -07009448 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009449 } finally {
9450 Binder.restoreCallingIdentity(identity);
9451 }
9452 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009453
Michele0ea7d782019-03-19 14:58:42 -07009454 @TelephonyManager.IsMultiSimSupportedResult
9455 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009456 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9457 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9458 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009459 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9460 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009461 }
9462 // Check if the hardware supports multisim functionality. If usage of multisim is not
9463 // supported by the modem, indicate that it is restricted.
9464 PhoneCapability staticCapability =
9465 mPhoneConfigurationManager.getStaticPhoneCapability();
9466 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009467 loge("isMultiSimSupportedInternal: no static configuration available");
9468 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009469 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009470 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009471 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9472 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009473 }
9474 // Check if support of multiple SIMs is restricted by carrier
9475 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009476 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009477 }
9478
Michele0ea7d782019-03-19 14:58:42 -07009479 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009480 }
9481
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009482 /**
9483 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009484 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9485 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9486 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009487 * @param numOfSims number of active sims we want to switch to
9488 */
9489 @Override
9490 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009491 if (numOfSims == 1) {
9492 enforceModifyPermission();
9493 } else {
9494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9495 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9496 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009497 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009498
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009499 try {
Michele30b57b22019-03-01 12:01:14 -08009500 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009501 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009502 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9503 return;
9504 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009505 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9506 } finally {
9507 Binder.restoreCallingIdentity(identity);
9508 }
9509 }
9510
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009511 @Override
9512 public boolean isApplicationOnUicc(int subId, int appType) {
9513 enforceReadPrivilegedPermission("isApplicationOnUicc");
9514 Phone phone = getPhone(subId);
9515 if (phone == null) {
9516 return false;
9517 }
9518 final long identity = Binder.clearCallingIdentity();
9519 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009520 UiccPort uiccPort = phone.getUiccPort();
9521 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009522 return false;
9523 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009524 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009525 if (uiccProfile == null) {
9526 return false;
9527 }
9528 if (TelephonyManager.APPTYPE_SIM <= appType
9529 && appType <= TelephonyManager.APPTYPE_ISIM) {
9530 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9531 }
9532 return false;
9533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
9537
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009538 /**
chen xub4baa772019-04-03 10:23:41 -07009539 * Get whether making changes to modem configurations will trigger reboot.
9540 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009541 */
9542 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009543 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9544 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009546 mApp, subId, callingPackage, callingFeatureId,
9547 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009548 return false;
9549 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009550 final long identity = Binder.clearCallingIdentity();
9551 try {
9552 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9553 } finally {
9554 Binder.restoreCallingIdentity(identity);
9555 }
9556 }
9557
Nathan Harold29f5f052019-02-15 13:41:57 -08009558 private void updateModemStateMetrics() {
9559 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9560 // TODO: check the state for each modem if the api is ready.
9561 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9562 }
9563
Pengquan Meng3889a572019-01-23 11:16:29 -08009564 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009565 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009566 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009567 // Verify that the callingPackage belongs to the calling UID
9568 mApp.getSystemService(AppOpsManager.class)
9569 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009570 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009571 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009572 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009573 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9574 if (slotInfos != null) {
9575 for (int i = 0; i < slotInfos.length; i++) {
9576 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9577 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9578 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9579 portInfo.getLogicalSlotIndex()));
9580 }
9581 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009582 }
9583 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009584 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009585 } finally {
9586 Binder.restoreCallingIdentity(identity);
9587 }
9588 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009589
9590 /**
9591 * Get the IRadio HAL Version
9592 */
9593 @Override
9594 public int getRadioHalVersion() {
9595 Phone phone = getDefaultPhone();
9596 if (phone == null) return -1;
9597 HalVersion hv = phone.getHalVersion();
9598 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9599 return hv.major * 100 + hv.minor;
9600 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009601
9602 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009603 * Get the current calling package name.
9604 * @return the current calling package name
9605 */
9606 @Override
9607 public String getCurrentPackageName() {
9608 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9609 }
9610
9611 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009612 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9613 * corresponding network requests on a subId.
9614 *
9615 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009616 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009617 * 2) APN is un-metered for this subscription, or
9618 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009619 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009620 *
9621 * @return whether data is allowed for a apn type.
9622 *
9623 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009624 */
9625 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009626 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009627 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9628 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009629
9630 // Now that all security checks passes, perform the operation as ourselves.
9631 final long identity = Binder.clearCallingIdentity();
9632 try {
9633 Phone phone = getPhone(subId);
9634 if (phone == null) return false;
9635
Jack Yu27422a52022-03-21 10:38:05 -07009636 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009637 boolean isDataEnabled;
Jack Yuf86fb842022-07-31 00:43:21 -07009638 isMetered = phone.getDataNetworkController().getDataConfigManager()
9639 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9640 phone.getServiceState().getDataRoaming());
9641 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009642 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009643 } finally {
9644 Binder.restoreCallingIdentity(identity);
9645 }
9646 }
9647
9648 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009649 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009650 enforceReadPrivilegedPermission("isApnMetered");
9651
9652 // Now that all security checks passes, perform the operation as ourselves.
9653 final long identity = Binder.clearCallingIdentity();
9654 try {
9655 Phone phone = getPhone(subId);
9656 if (phone == null) return true; // By default return true.
Jack Yuf86fb842022-07-31 00:43:21 -07009657 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9658 DataUtils.apnTypeToNetworkCapability(apnType),
9659 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009660 } finally {
9661 Binder.restoreCallingIdentity(identity);
9662 }
9663 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009664
9665 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009666 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9667 int subscriptionId, IBooleanConsumer resultCallback) {
9668 enforceModifyPermission();
9669 long token = Binder.clearCallingIdentity();
9670 try {
9671 Phone phone = getPhone(subscriptionId);
9672 if (phone == null) {
9673 try {
9674 if (resultCallback != null) {
9675 resultCallback.accept(false);
9676 }
9677 } catch (RemoteException e) {
9678 // ignore
9679 }
9680 return;
9681 }
9682 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9683 Pair.create(specifiers, (x) -> {
9684 try {
9685 if (resultCallback != null) {
9686 resultCallback.accept(x);
9687 }
9688 } catch (RemoteException e) {
9689 // ignore
9690 }
9691 });
9692 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9693 } finally {
9694 Binder.restoreCallingIdentity(token);
9695 }
9696 }
9697
9698 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009699 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9700 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009701 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009702 mApp, subId, "getSystemSelectionChannels");
9703 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9704 final long identity = Binder.clearCallingIdentity();
9705 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009706 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9707 if (result instanceof IllegalStateException) {
9708 throw (IllegalStateException) result;
9709 }
9710 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009711 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9712 return specifiers;
9713 } finally {
9714 Binder.restoreCallingIdentity(identity);
9715 }
9716 }
9717
9718 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009719 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009720 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009721 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009722 }
9723
9724 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009725 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9726 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009727 if (callingPackage == null) {
9728 callingPackage = getCurrentPackageName();
9729 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009730 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9731 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009732 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9733 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009734 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9735 }
9736 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9737 Intent intent = new Intent();
9738 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9739 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9740 // Bring up choose default SMS subscription dialog right now
9741 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9742 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9743 mApp.startActivity(intent);
9744 }
chen xud5ca2d52019-05-28 15:20:57 -07009745
9746 @Override
9747 public String getMmsUAProfUrl(int subId) {
9748 //TODO investigate if this API should require proper permission check in R b/133791609
9749 final long identity = Binder.clearCallingIdentity();
9750 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009751 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9752 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9753 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9754 return carrierUAProfUrl;
9755 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009756 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9757 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009758 } finally {
9759 Binder.restoreCallingIdentity(identity);
9760 }
9761 }
9762
9763 @Override
9764 public String getMmsUserAgent(int subId) {
9765 //TODO investigate if this API should require proper permission check in R b/133791609
9766 final long identity = Binder.clearCallingIdentity();
9767 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009768 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9769 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9770 if (!TextUtils.isEmpty(carrierUserAgent)) {
9771 return carrierUserAgent;
9772 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009773 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9774 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009775 } finally {
9776 Binder.restoreCallingIdentity(identity);
9777 }
9778 }
Jack Yub07d4972019-05-28 16:12:25 -07009779
9780 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009781 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9782 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009783
Jack Yub07d4972019-05-28 16:12:25 -07009784 final long identity = Binder.clearCallingIdentity();
9785 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009786 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009787 if (phone == null) return false;
9788
Hall Liua62f5da2020-09-25 10:42:19 -07009789 switch (policy) {
9790 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yuf86fb842022-07-31 00:43:21 -07009791 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
Hall Liua62f5da2020-09-25 10:42:19 -07009792 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yuf86fb842022-07-31 00:43:21 -07009793 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
Hall Liua62f5da2020-09-25 10:42:19 -07009794 default:
9795 throw new IllegalArgumentException(policy + " is not a valid policy");
9796 }
Jack Yub07d4972019-05-28 16:12:25 -07009797 } finally {
9798 Binder.restoreCallingIdentity(identity);
9799 }
9800 }
9801
9802 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009803 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009804 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009805 enforceModifyPermission();
9806
changbettyd5c246e2019-12-24 15:40:37 +08009807 final long identity = Binder.clearCallingIdentity();
9808 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009809 Phone phone = getPhone(subscriptionId);
9810 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009811
Hall Liua62f5da2020-09-25 10:42:19 -07009812 switch (policy) {
9813 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yuf86fb842022-07-31 00:43:21 -07009814 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
Hall Liua62f5da2020-09-25 10:42:19 -07009815 break;
9816 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yuf86fb842022-07-31 00:43:21 -07009817 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
Hall Liua62f5da2020-09-25 10:42:19 -07009818 break;
9819 default:
9820 throw new IllegalArgumentException(policy + " is not a valid policy");
9821 }
changbettyd5c246e2019-12-24 15:40:37 +08009822 } finally {
9823 Binder.restoreCallingIdentity(identity);
9824 }
9825 }
9826
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009827 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009828 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009829 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9830 * otherwise.
9831 */
9832 @Override
9833 public void setCepEnabled(boolean isCepEnabled) {
9834 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9835
9836 final long identity = Binder.clearCallingIdentity();
9837 try {
9838 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9839 for (Phone phone : PhoneFactory.getPhones()) {
9840 Phone defaultPhone = phone.getImsPhone();
9841 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9842 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9843 ImsPhoneCallTracker imsPhoneCallTracker =
9844 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9845 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9846 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9847 + imsPhone.getMsisdn());
9848 }
9849 }
9850 } finally {
9851 Binder.restoreCallingIdentity(identity);
9852 }
9853 }
allenwtsu46dcc572020-01-08 18:24:03 +08009854
9855 /**
9856 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9857 *
9858 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9859 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9860 * before being read.
9861 */
9862 @Override
9863 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9864 isCompressed) {
9865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9866 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009867 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9868 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9869 }
9870 if (!isImsAvailableOnDevice()) {
9871 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9872 "IMS not available on device.");
9873 }
9874
9875 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009876 try {
Hui Wang761a6682020-10-31 05:12:53 +00009877 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9878 } finally {
9879 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009880 }
9881 }
zoey chene02881a2019-12-30 16:11:23 +08009882
9883 @Override
9884 public boolean isIccLockEnabled(int subId) {
9885 enforceReadPrivilegedPermission("isIccLockEnabled");
9886
9887 // Now that all security checks passes, perform the operation as ourselves.
9888 final long identity = Binder.clearCallingIdentity();
9889 try {
9890 Phone phone = getPhone(subId);
9891 if (phone != null && phone.getIccCard() != null) {
9892 return phone.getIccCard().getIccLockEnabled();
9893 } else {
9894 return false;
9895 }
9896 } finally {
9897 Binder.restoreCallingIdentity(identity);
9898 }
9899 }
9900
9901 /**
9902 * Set the ICC pin lock enabled or disabled.
9903 *
9904 * @return an integer representing the status of IccLock enabled or disabled in the following
9905 * three cases:
9906 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9907 * successfully.
9908 * - Positive number and zero for remaining password attempts.
9909 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9910 *
9911 */
9912 @Override
9913 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9914 enforceModifyPermission();
9915
9916 Phone phone = getPhone(subId);
9917 if (phone == null) {
9918 return 0;
9919 }
9920 // Now that all security checks passes, perform the operation as ourselves.
9921 final long identity = Binder.clearCallingIdentity();
9922 try {
9923 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9924 new Pair<Boolean, String>(enabled, password), phone, null);
9925 return attemptsRemaining;
9926
9927 } catch (Exception e) {
9928 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9929 } finally {
9930 Binder.restoreCallingIdentity(identity);
9931 }
9932 return 0;
9933 }
9934
9935 /**
9936 * Change the ICC password used in ICC pin lock.
9937 *
9938 * @return an integer representing the status of IccLock changed in the following three cases:
9939 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9940 * - Positive number and zero for remaining password attempts.
9941 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9942 *
9943 */
9944 @Override
9945 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9946 enforceModifyPermission();
9947
9948 Phone phone = getPhone(subId);
9949 if (phone == null) {
9950 return 0;
9951 }
9952 // Now that all security checks passes, perform the operation as ourselves.
9953 final long identity = Binder.clearCallingIdentity();
9954 try {
9955 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9956 new Pair<String, String>(oldPassword, newPassword), phone, null);
9957 return attemptsRemaining;
9958
9959 } catch (Exception e) {
9960 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9961 } finally {
9962 Binder.restoreCallingIdentity(identity);
9963 }
9964 return 0;
9965 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009966
9967 /**
9968 * Request for receiving user activity notification
9969 */
9970 @Override
9971 public void requestUserActivityNotification() {
9972 if (!mNotifyUserActivity.get()
9973 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9974 mNotifyUserActivity.set(true);
9975 }
9976 }
9977
9978 /**
9979 * Called when userActivity is signalled in the power manager.
9980 * This is safe to call from any thread, with any window manager locks held or not.
9981 */
9982 @Override
9983 public void userActivity() {
9984 // ***************************************
9985 // * Inherited from PhoneWindowManager *
9986 // ***************************************
9987 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9988 // WITH ITS LOCKS HELD.
9989 //
9990 // This code must be VERY careful about the locks
9991 // it acquires.
9992 // In fact, the current code acquires way too many,
9993 // and probably has lurking deadlocks.
9994
9995 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9996 throw new SecurityException("Only the OS may call notifyUserActivity()");
9997 }
9998
9999 if (mNotifyUserActivity.getAndSet(false)) {
10000 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10001 USER_ACTIVITY_NOTIFICATION_DELAY);
10002 }
10003 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010004
10005 @Override
10006 public boolean canConnectTo5GInDsdsMode() {
10007 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10008 }
Jack Yud10cdd42020-09-28 20:28:01 -070010009
10010 @Override
10011 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10012 String callingFeatureId) {
10013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10014 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10015 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10016 }
10017
10018 Phone phone = getPhone(subId);
10019 if (phone == null) {
10020 throw new RuntimeException("phone is not available");
10021 }
10022 // Now that all security checks passes, perform the operation as ourselves.
10023 final long identity = Binder.clearCallingIdentity();
10024 try {
10025 return phone.getEquivalentHomePlmns();
10026 } finally {
10027 Binder.restoreCallingIdentity(identity);
10028 }
10029 }
Daniel Bright59e67312020-11-13 11:49:37 -080010030
10031 @Override
10032 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010033 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10034 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010035 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010036 if (radioInterfaceCapabilities == null) {
10037 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010038 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010039 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010040 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010041
Hui Wang641e81c2020-10-12 12:14:23 -070010042 @Override
10043 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10044 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010045 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10046 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10047 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10048 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10049 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010050 if (DBG) {
10051 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10052 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10053 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10054 }
10055
10056 if (!SubscriptionManager.isValidSubscriptionId(subId)
10057 || appType < TelephonyManager.APPTYPE_UNKNOWN
10058 || appType > TelephonyManager.APPTYPE_ISIM
10059 || nafUrl == null || securityProtocol == null || callback == null) {
10060 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10061 if (callback != null) {
10062 try {
10063 callback.onAuthenticationFailure(
10064 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10065 } catch (RemoteException exception) {
10066 log("Fail to notify onAuthenticationFailure due to " + exception);
10067 }
10068 return;
10069 }
10070 }
10071
10072 final long token = Binder.clearCallingIdentity();
10073 try {
10074 getGbaManager(subId).bootstrapAuthenticationRequest(
10075 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10076 forceBootStrapping, callback));
10077 } finally {
10078 Binder.restoreCallingIdentity(token);
10079 }
10080 }
10081
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010082 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010083 * Attempts to set the radio power state for all phones for thermal reason.
10084 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010085 * requested radio power state will actually be set. See {@link
10086 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10087 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010088 * @param enable {@code true} if trying to turn radio on.
10089 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10090 * false}.
10091 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010092 private boolean setRadioPowerForThermal(boolean enable) {
10093 boolean isPhoneAvailable = false;
10094 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10095 Phone phone = PhoneFactory.getPhone(i);
10096 if (phone != null) {
10097 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10098 isPhoneAvailable = true;
10099 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010100 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010101
10102 // return true if successfully informed the phone object about the thermal radio power
10103 // request.
10104 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010105 }
10106
10107 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010108 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010109 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10110 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10111 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10112 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10113 throw new IllegalArgumentException("modem does not support data throttling");
10114 }
10115
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010116 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10117 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010118 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010119 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10120 }
10121
Sarah Chinecc78c42022-03-31 21:16:48 -070010122 setDataEnabledForReason(
10123 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010124
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010125 if (isDataThrottlingSupported) {
10126 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010127 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010128 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10129 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10130 } else if (thermalMitigationResult
10131 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010132 log("Modem likely does not support data throttling on secondary carrier. Data " +
10133 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10134 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010135 }
10136 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010137 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010138
10139 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010140 }
10141
Jack Nudelman644b91a2021-03-12 14:09:48 -080010142 private static List<String> getThermalMitigationAllowlist(Context context) {
10143 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10144 for (String pckg : context.getResources()
10145 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10146 sThermalMitigationAllowlistedPackages.add(pckg);
10147 }
10148 }
10149
10150 return sThermalMitigationAllowlistedPackages;
10151 }
10152
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010153 private boolean isAnyPhoneInEmergencyState() {
10154 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10155 if (tm.isInEmergencyCall()) {
10156 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10157 return true;
10158 }
10159 for (Phone phone : PhoneFactory.getPhones()) {
10160 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10161 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10162 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10163 + phone.isInEcm());
10164 return true;
10165 }
10166 }
10167
10168 return false;
10169 }
10170
Jack Nudelman644b91a2021-03-12 14:09:48 -080010171 /**
10172 * Used by shell commands to add an authorized package name for thermal mitigation.
10173 * @param packageName name of package to be allowlisted
10174 * @param context
10175 */
10176 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10177 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10178 sThermalMitigationAllowlistedPackages.add(packageName);
10179 }
10180
10181 /**
10182 * Used by shell commands to remove an authorized package name for thermal mitigation.
10183 * @param packageName name of package to remove from allowlist
10184 * @param context
10185 */
10186 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10187 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10188 sThermalMitigationAllowlistedPackages.remove(packageName);
10189 }
10190
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010191 /**
10192 * Thermal mitigation request to control functionalities at modem.
10193 *
10194 * @param subId the id of the subscription.
10195 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010196 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010197 *
10198 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10199 */
10200 @Override
10201 @ThermalMitigationResult
10202 public int sendThermalMitigationRequest(
10203 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010204 ThermalMitigationRequest thermalMitigationRequest,
10205 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010206 enforceModifyPermission();
10207
Jack Nudelman644b91a2021-03-12 14:09:48 -080010208 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10209 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10210 .contains(callingPackage)) {
10211 throw new SecurityException("Calling package must be configured in the device config. "
10212 + "calling package: " + callingPackage);
10213 }
10214
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010215 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10216 final long identity = Binder.clearCallingIdentity();
10217
10218 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10219 try {
10220 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10221 switch (thermalMitigationAction) {
10222 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10223 thermalMitigationResult =
10224 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010225 thermalMitigationRequest.getDataThrottlingRequest(),
10226 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010227 break;
10228 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10229 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10230 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10231 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10232 }
10233
10234 // Ensure that radio is on. If not able to power on due to phone being
10235 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010236 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010237 thermalMitigationResult =
10238 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10239 break;
10240 }
10241
10242 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010243 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010244 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10245 break;
10246 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10247 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10248 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10249 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10250 }
10251
10252 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10253 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010254 Phone phone = getPhone(subId);
10255 if (phone == null) {
10256 thermalMitigationResult =
10257 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10258 break;
10259 }
10260
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010261 TelephonyConnectionService service =
10262 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010263 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010264 Log.e(LOG_TAG, "An emergency call is pending");
10265 thermalMitigationResult =
10266 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10267 break;
10268 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010269 thermalMitigationResult =
10270 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10271 break;
10272 }
10273 } else {
10274 thermalMitigationResult =
10275 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10276 break;
10277 }
10278
10279 // Turn radio off. If not able to power off due to phone being unavailable,
10280 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010281 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010282 thermalMitigationResult =
10283 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10284 break;
10285 }
10286 thermalMitigationResult =
10287 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10288 break;
10289 default:
10290 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10291 + "not exist. Requested action: " + thermalMitigationAction);
10292 }
10293 } catch (IllegalArgumentException e) {
10294 throw e;
10295 } catch (Exception e) {
10296 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10297 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10298 } finally {
10299 Binder.restoreCallingIdentity(identity);
10300 }
10301
10302 if (DBG) {
10303 log("thermalMitigationRequest returning with thermalMitigationResult: "
10304 + thermalMitigationResult);
10305 }
10306
10307 return thermalMitigationResult;
10308 }
Hui Wang641e81c2020-10-12 12:14:23 -070010309
10310 /**
10311 * Set the GbaService Package Name that Telephony will bind to.
10312 *
10313 * @param subId The sim that the GbaService is associated with.
10314 * @param packageName The name of the package to be replaced with.
10315 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10316 */
10317 @Override
10318 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10319 enforceModifyPermission();
10320
10321 final long identity = Binder.clearCallingIdentity();
10322 try {
10323 return getGbaManager(subId).overrideServicePackage(packageName);
10324 } finally {
10325 Binder.restoreCallingIdentity(identity);
10326 }
10327 }
10328
10329 /**
10330 * Return the package name of the currently bound GbaService.
10331 *
10332 * @param subId The sim that the GbaService is associated with.
10333 * @return the package name of the GbaService configuration, null if GBA is not supported.
10334 */
10335 @Override
10336 public String getBoundGbaService(int subId) {
10337 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10338
10339 final long identity = Binder.clearCallingIdentity();
10340 try {
10341 return getGbaManager(subId).getServicePackage();
10342 } finally {
10343 Binder.restoreCallingIdentity(identity);
10344 }
10345 }
10346
10347 /**
10348 * Set the release time for telephony to unbind GbaService.
10349 *
10350 * @param subId The sim that the GbaService is associated with.
10351 * @param interval The release time to unbind GbaService by millisecond.
10352 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10353 */
10354 @Override
10355 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10356 enforceModifyPermission();
10357
10358 final long identity = Binder.clearCallingIdentity();
10359 try {
10360 return getGbaManager(subId).overrideReleaseTime(interval);
10361 } finally {
10362 Binder.restoreCallingIdentity(identity);
10363 }
10364 }
10365
10366 /**
10367 * Return the release time for telephony to unbind GbaService.
10368 *
10369 * @param subId The sim that the GbaService is associated with.
10370 * @return The release time to unbind GbaService by millisecond.
10371 */
10372 @Override
10373 public int getGbaReleaseTime(int subId) {
10374 enforceReadPrivilegedPermission("getGbaReleaseTime");
10375
10376 final long identity = Binder.clearCallingIdentity();
10377 try {
10378 return getGbaManager(subId).getReleaseTime();
10379 } finally {
10380 Binder.restoreCallingIdentity(identity);
10381 }
10382 }
10383
10384 private GbaManager getGbaManager(int subId) {
10385 GbaManager instance = GbaManager.getInstance(subId);
10386 if (instance == null) {
10387 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10388 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10389 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10390 }
10391 return instance;
10392 }
Hui Wang761a6682020-10-31 05:12:53 +000010393
10394 /**
10395 * indicate whether the device and the carrier can support
10396 * RCS VoLTE single registration.
10397 */
10398 @Override
10399 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010400 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10401 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10402 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10403 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010404
10405 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10406 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10407 }
10408
10409 final long identity = Binder.clearCallingIdentity();
10410 try {
10411 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10412 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010413 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10414 if (isCapable != null) {
10415 return isCapable;
10416 }
Hui Wang761a6682020-10-31 05:12:53 +000010417 }
Hui Wang67af90e2021-06-04 16:57:15 -070010418 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10419 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010420 } finally {
10421 Binder.restoreCallingIdentity(identity);
10422 }
10423 }
10424
10425 /**
10426 * Register RCS provisioning callback.
10427 */
10428 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010429 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010430 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010431 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010432 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010433 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10434 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010435
10436 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10437 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10438 }
10439 if (!isImsAvailableOnDevice()) {
10440 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10441 "IMS not available on device.");
10442 }
10443
10444 final long identity = Binder.clearCallingIdentity();
10445 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010446 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010447 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010448 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10449 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010450 }
Hui Wang761a6682020-10-31 05:12:53 +000010451 } finally {
10452 Binder.restoreCallingIdentity(identity);
10453 }
10454 }
10455
10456 /**
10457 * Unregister RCS provisioning callback.
10458 */
10459 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010460 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010461 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010462 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010463 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010464 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10465 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010466
10467 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10468 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10469 }
10470 if (!isImsAvailableOnDevice()) {
10471 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10472 "IMS not available on device.");
10473 }
10474
10475 final long identity = Binder.clearCallingIdentity();
10476 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010477 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010478 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010479 } finally {
10480 Binder.restoreCallingIdentity(identity);
10481 }
10482 }
10483
10484 /**
10485 * trigger RCS reconfiguration.
10486 */
10487 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010488 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10489 "triggerRcsReconfiguration",
10490 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010491
10492 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10493 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10494 }
10495 if (!isImsAvailableOnDevice()) {
10496 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10497 "IMS not available on device.");
10498 }
10499
10500 final long identity = Binder.clearCallingIdentity();
10501 try {
10502 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10503 } finally {
10504 Binder.restoreCallingIdentity(identity);
10505 }
10506 }
10507
10508 /**
10509 * Provide the client configuration parameters of the RCS application.
10510 */
10511 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010512 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10513 "setRcsClientConfiguration",
10514 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010515
10516 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10517 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10518 }
10519 if (!isImsAvailableOnDevice()) {
10520 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10521 "IMS not available on device.");
10522 }
10523
10524 final long identity = Binder.clearCallingIdentity();
10525
10526 try {
10527 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10528 if (configBinder == null) {
10529 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010530 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10531 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010532 } else {
10533 configBinder.setRcsClientConfiguration(rcc);
10534 }
joonhunshin3e154242021-09-17 06:33:39 +000010535
10536 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10537 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010538 } catch (RemoteException e) {
10539 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010540 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10541 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010542 } finally {
10543 Binder.restoreCallingIdentity(identity);
10544 }
10545 }
10546
10547 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010548 * Enables or disables the test mode for RCS VoLTE single registration.
10549 */
10550 @Override
10551 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10552 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10553 "setRcsSingleRegistrationTestModeEnabled");
10554
10555 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10556 }
10557
10558 /**
10559 * Gets the test mode for RCS VoLTE single registration.
10560 */
10561 @Override
10562 public boolean getRcsSingleRegistrationTestModeEnabled() {
10563 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10564 "getRcsSingleRegistrationTestModeEnabled");
10565
10566 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10567 }
10568
10569 /**
Hui Wang761a6682020-10-31 05:12:53 +000010570 * Overrides the config of RCS VoLTE single registration enabled for the device.
10571 */
10572 @Override
10573 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10574 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10575 "setDeviceSingleRegistrationEnabledOverride");
10576 enforceModifyPermission();
10577
10578 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10579 : Boolean.parseBoolean(enabledStr);
10580 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010581 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010582 }
10583
10584 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010585 * Sends a device to device communication message. Only usable via shell.
10586 * @param message message to send.
10587 * @param value message value.
10588 */
10589 @Override
10590 public void sendDeviceToDeviceMessage(int message, int value) {
10591 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010592 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010593 enforceModifyPermission();
10594
10595 final long identity = Binder.clearCallingIdentity();
10596 try {
10597 TelephonyConnectionService service =
10598 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10599 if (service == null) {
10600 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10601 return;
10602 }
10603 service.sendTestDeviceToDeviceMessage(message, value);
10604 } finally {
10605 Binder.restoreCallingIdentity(identity);
10606 }
10607 }
10608
Tyler Gunnbabbda02021-02-10 11:05:02 -080010609 /**
10610 * Sets the specified device to device transport active.
10611 * @param transport The transport to set active.
10612 */
10613 @Override
10614 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10615 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10616 "setActiveDeviceToDeviceTransport");
10617 enforceModifyPermission();
10618
10619 final long identity = Binder.clearCallingIdentity();
10620 try {
10621 TelephonyConnectionService service =
10622 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10623 if (service == null) {
10624 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10625 return;
10626 }
10627 service.setActiveDeviceToDeviceTransport(transport);
10628 } finally {
10629 Binder.restoreCallingIdentity(identity);
10630 }
10631 }
Tyler Gunn92479152021-01-20 16:30:10 -080010632
Tyler Gunnd4339262021-05-03 14:46:49 -070010633 @Override
10634 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10635 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10636 "setDeviceToDeviceForceEnabled");
10637
10638 final long identity = Binder.clearCallingIdentity();
10639 try {
10640 Arrays.stream(PhoneFactory.getPhones()).forEach(
10641 p -> {
10642 Phone thePhone = p.getImsPhone();
10643 if (thePhone != null && thePhone instanceof ImsPhone) {
10644 ImsPhone imsPhone = (ImsPhone) thePhone;
10645 CallTracker tracker = imsPhone.getCallTracker();
10646 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10647 ImsPhoneCallTracker imsPhoneCallTracker =
10648 (ImsPhoneCallTracker) tracker;
10649 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10650 }
10651 }
10652 }
10653 );
10654 } finally {
10655 Binder.restoreCallingIdentity(identity);
10656 }
10657 }
10658
Tyler Gunn92479152021-01-20 16:30:10 -080010659 /**
Hui Wang761a6682020-10-31 05:12:53 +000010660 * Gets the config of RCS VoLTE single registration enabled for the device.
10661 */
10662 @Override
10663 public boolean getDeviceSingleRegistrationEnabled() {
10664 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10665 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10666 }
10667
10668 /**
10669 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10670 */
10671 @Override
10672 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10673 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10674 "setCarrierSingleRegistrationEnabledOverride");
10675 enforceModifyPermission();
10676
10677 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10678 : Boolean.parseBoolean(enabledStr);
10679 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10680 subId, enabled);
10681 }
10682
10683 /**
10684 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10685 */
10686 @Override
10687 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10688 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10689 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10690 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010691
10692 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010693 * Overrides the ims feature validation result
10694 */
10695 @Override
10696 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10697 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10698 "setImsFeatureValidationOverride");
10699
10700 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10701 : Boolean.parseBoolean(enabledStr);
10702 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10703 subId, enabled);
10704 }
10705
10706 /**
10707 * Gets the ims feature validation override value
10708 */
10709 @Override
10710 public boolean getImsFeatureValidationOverride(int subId) {
10711 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10712 "getImsFeatureValidationOverride");
10713 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10714 }
10715
10716 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010717 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10718 * their mobile plan.
10719 */
10720 @Override
10721 public String getMobileProvisioningUrl() {
10722 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10723 final long identity = Binder.clearCallingIdentity();
10724 try {
10725 return getDefaultPhone().getMobileProvisioningUrl();
10726 } finally {
10727 Binder.restoreCallingIdentity(identity);
10728 }
10729 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010730
James.cf Linbcdf8b32021-01-14 16:44:13 +080010731 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010732 * Get the EAB contact from the EAB database.
10733 */
10734 @Override
10735 public String getContactFromEab(String contact) {
10736 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10737 enforceModifyPermission();
10738 final long identity = Binder.clearCallingIdentity();
10739 try {
10740 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10741 } finally {
10742 Binder.restoreCallingIdentity(identity);
10743 }
10744 }
10745
10746 /**
Calvin Pana1434322021-07-01 19:27:01 +080010747 * Get the EAB capability from the EAB database.
10748 */
10749 @Override
10750 public String getCapabilityFromEab(String contact) {
10751 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10752 enforceModifyPermission();
10753 final long identity = Binder.clearCallingIdentity();
10754 try {
10755 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10756 } finally {
10757 Binder.restoreCallingIdentity(identity);
10758 }
10759 }
10760
10761 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010762 * Remove the EAB contacts from the EAB database.
10763 */
10764 @Override
10765 public int removeContactFromEab(int subId, String contacts) {
10766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10767 enforceModifyPermission();
10768 final long identity = Binder.clearCallingIdentity();
10769 try {
10770 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10771 } finally {
10772 Binder.restoreCallingIdentity(identity);
10773 }
10774 }
10775
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010776 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010777 public boolean getDeviceUceEnabled() {
10778 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10779 final long identity = Binder.clearCallingIdentity();
10780 try {
10781 return mApp.getDeviceUceEnabled();
10782 } finally {
10783 Binder.restoreCallingIdentity(identity);
10784 }
10785 }
10786
10787 @Override
10788 public void setDeviceUceEnabled(boolean isEnabled) {
10789 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10790 final long identity = Binder.clearCallingIdentity();
10791 try {
10792 mApp.setDeviceUceEnabled(isEnabled);
10793 } finally {
10794 Binder.restoreCallingIdentity(identity);
10795 }
10796 }
10797
Brad Ebinger14d467f2021-02-12 06:18:28 +000010798 /**
10799 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10800 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10801 */
10802 // Used for SHELL command only right now.
10803 @Override
10804 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10805 List<String> featureTags) {
10806 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10807 "addUceRegistrationOverrideShell");
10808 final long identity = Binder.clearCallingIdentity();
10809 try {
10810 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10811 new ArraySet<>(featureTags));
10812 } catch (ImsException e) {
10813 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10814 } finally {
10815 Binder.restoreCallingIdentity(identity);
10816 }
10817 }
10818
10819 /**
10820 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10821 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10822 */
10823 // Used for SHELL command only right now.
10824 @Override
10825 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10826 List<String> featureTags) {
10827 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10828 "removeUceRegistrationOverrideShell");
10829 final long identity = Binder.clearCallingIdentity();
10830 try {
10831 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10832 new ArraySet<>(featureTags));
10833 } catch (ImsException e) {
10834 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10835 } finally {
10836 Binder.restoreCallingIdentity(identity);
10837 }
10838 }
10839
10840 /**
10841 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10842 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10843 */
10844 // Used for SHELL command only right now.
10845 @Override
10846 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10847 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10848 "clearUceRegistrationOverrideShell");
10849 final long identity = Binder.clearCallingIdentity();
10850 try {
10851 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10852 } catch (ImsException e) {
10853 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10854 } finally {
10855 Binder.restoreCallingIdentity(identity);
10856 }
10857 }
10858
10859 /**
10860 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10861 */
10862 // Used for SHELL command only right now.
10863 @Override
10864 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10866 "getLatestRcsContactUceCapabilityShell");
10867 final long identity = Binder.clearCallingIdentity();
10868 try {
10869 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10870 } catch (ImsException e) {
10871 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10872 } finally {
10873 Binder.restoreCallingIdentity(identity);
10874 }
10875 }
10876
10877 /**
10878 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10879 * device does not have an active PUBLISH.
10880 */
10881 // Used for SHELL command only right now.
10882 @Override
10883 public String getLastUcePidfXmlShell(int subId) {
10884 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10885 final long identity = Binder.clearCallingIdentity();
10886 try {
10887 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10888 } catch (ImsException e) {
10889 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10890 } finally {
10891 Binder.restoreCallingIdentity(identity);
10892 }
10893 }
10894
James.cf Line8713a42021-04-29 16:04:26 +080010895 /**
10896 * Remove UCE requests cannot be sent to the network status.
10897 */
10898 // Used for SHELL command only right now.
10899 @Override
10900 public boolean removeUceRequestDisallowedStatus(int subId) {
10901 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10902 final long identity = Binder.clearCallingIdentity();
10903 try {
10904 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10905 } catch (ImsException e) {
10906 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10907 } finally {
10908 Binder.restoreCallingIdentity(identity);
10909 }
10910 }
10911
James.cf Lin18bb9002021-05-25 01:37:38 +080010912 /**
10913 * Remove UCE requests cannot be sent to the network status.
10914 */
10915 // Used for SHELL command only.
10916 @Override
10917 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10918 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10919 final long identity = Binder.clearCallingIdentity();
10920 try {
10921 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10922 } catch (ImsException e) {
10923 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10924 } finally {
10925 Binder.restoreCallingIdentity(identity);
10926 }
10927 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010928
James.cf Lin4b784aa2021-01-31 03:25:15 +080010929 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010930 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10931 String callingPackage) {
10932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10933 mApp, subId, "setSignalStrengthUpdateRequest");
10934
10935 final int callingUid = Binder.getCallingUid();
10936 // Verify that tha callingPackage belongs to the calling UID
10937 mApp.getSystemService(AppOpsManager.class)
10938 .checkPackage(callingUid, callingPackage);
10939
Rambo Wang3607f502021-02-01 21:51:40 -080010940 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010941
10942 final long identity = Binder.clearCallingIdentity();
10943 try {
10944 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10945 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10946
10947 if (result instanceof IllegalStateException) {
10948 throw (IllegalStateException) result;
10949 }
10950 } finally {
10951 Binder.restoreCallingIdentity(identity);
10952 }
10953 }
10954
10955 @Override
10956 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10957 String callingPackage) {
10958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10959 mApp, subId, "clearSignalStrengthUpdateRequest");
10960
10961 final int callingUid = Binder.getCallingUid();
10962 // Verify that tha callingPackage belongs to the calling UID
10963 mApp.getSystemService(AppOpsManager.class)
10964 .checkPackage(callingUid, callingPackage);
10965
10966 final long identity = Binder.clearCallingIdentity();
10967 try {
10968 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10969 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10970
10971 if (result instanceof IllegalStateException) {
10972 throw (IllegalStateException) result;
10973 }
10974 } finally {
10975 Binder.restoreCallingIdentity(identity);
10976 }
10977 }
10978
Rambo Wang3607f502021-02-01 21:51:40 -080010979 private static void validateSignalStrengthUpdateRequest(Context context,
10980 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010981 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10982 // phone/system process do not have further restriction on request
10983 return;
10984 }
10985
10986 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010987 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010988 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010989 context.enforceCallingOrSelfPermission(
10990 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10991 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010992 }
10993
10994 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10995 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10996 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10997 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10998 || info.isEnabled()) {
10999 throw new IllegalArgumentException(
11000 "Only system can set hide fields in SignalThresholdInfo");
11001 }
11002
11003 // Thresholds length for each RAN need in range. This has been validated in
11004 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11005 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11006 final int[] thresholds = info.getThresholds();
11007 Objects.requireNonNull(thresholds);
11008 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11009 || thresholds.length
11010 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11011 throw new IllegalArgumentException(
11012 "thresholds length is out of range: " + thresholds.length);
11013 }
11014 }
11015 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011016
11017 /**
11018 * Gets the current phone capability.
11019 *
11020 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11021 * @return the PhoneCapability which describes the data connection capability of modem.
11022 * It's used to evaluate possible phone config change, for example from single
11023 * SIM device to multi-SIM device.
11024 */
11025 @Override
11026 public PhoneCapability getPhoneCapability() {
11027 enforceReadPrivilegedPermission("getPhoneCapability");
11028 final long identity = Binder.clearCallingIdentity();
11029 try {
11030 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11031 } finally {
11032 Binder.restoreCallingIdentity(identity);
11033 }
11034 }
Michele Berionne5e411512020-11-13 02:36:59 +000011035
11036 /**
11037 * Prepare TelephonyManager for an unattended reboot. The reboot is
11038 * required to be done shortly after the API is invoked.
11039 */
11040 @Override
11041 @TelephonyManager.PrepareUnattendedRebootResult
11042 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011043 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011044 enforceRebootPermission();
11045
11046 final long identity = Binder.clearCallingIdentity();
11047 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011048 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011049 } finally {
11050 Binder.restoreCallingIdentity(identity);
11051 }
11052 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011053
11054 /**
11055 * Request to get the current slicing configuration including URSP rules and
11056 * NSSAIs (configured, allowed and rejected).
11057 *
11058 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11059 */
11060 @Override
11061 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011062 TelephonyPermissions
11063 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11064 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011065
11066 final long identity = Binder.clearCallingIdentity();
11067 try {
11068 Phone phone = getDefaultPhone();
11069 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11070 } finally {
11071 Binder.restoreCallingIdentity(identity);
11072 }
11073 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011074
11075 /**
11076 * Register an IMS connection state callback
11077 */
11078 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011079 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11080 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011081 if (feature == ImsFeature.FEATURE_MMTEL) {
11082 // ImsMmTelManager
11083 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11084 TelephonyPermissions
11085 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11086 mApp, subId, "registerImsStateCallback");
11087 } else if (feature == ImsFeature.FEATURE_RCS) {
11088 // ImsRcsManager or SipDelegateManager
11089 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11090 Binder.getCallingUid(), "registerImsStateCallback",
11091 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11092 Manifest.permission.READ_PRECISE_PHONE_STATE,
11093 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11094 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11095 }
11096
11097 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11098 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11099 "IMS not available on device.");
11100 }
11101
11102 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11103 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11104 }
11105
11106 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11107 if (controller == null) {
11108 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11109 "IMS not available on device.");
11110 }
11111
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011112 if (callingPackage == null) {
11113 callingPackage = getCurrentPackageName();
11114 }
11115
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011116 final long token = Binder.clearCallingIdentity();
11117 try {
11118 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011119 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011120 } catch (ImsException e) {
11121 throw new ServiceSpecificException(e.getCode());
11122 } finally {
11123 Binder.restoreCallingIdentity(token);
11124 }
11125 }
11126
11127 /**
11128 * Unregister an IMS connection state callback
11129 */
11130 @Override
11131 public void unregisterImsStateCallback(IImsStateCallback cb) {
11132 final long token = Binder.clearCallingIdentity();
11133 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11134 if (controller == null) {
11135 return;
11136 }
11137 try {
11138 controller.unregisterImsStateCallback(cb);
11139 } finally {
11140 Binder.restoreCallingIdentity(token);
11141 }
11142 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011143
11144 /**
11145 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11146 *
11147 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11148 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11149 * SecurityException.
11150 * If there is current registered network this value will be same as the registered cell
11151 * identity. If the device goes out of service the previous cell identity is cached and
11152 * will be returned. If the cache age of the Cell identity is more than 24 hours
11153 * it will be cleared and null will be returned.
11154 *
11155 */
11156 @Override
11157 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11158 String callingFeatureId) {
11159 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11160 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11161 LocationAccessPolicy.checkLocationPermission(mApp,
11162 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11163 .setCallingPackage(callingPackage)
11164 .setCallingFeatureId(callingFeatureId)
11165 .setCallingPid(Binder.getCallingPid())
11166 .setCallingUid(Binder.getCallingUid())
11167 .setMethod("getLastKnownCellIdentity")
11168 .setLogAsInfo(true)
11169 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11170 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11171 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11172 .build());
11173
11174 boolean hasFinePermission =
11175 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11176 if (!hasFinePermission
11177 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11178 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011179 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011180 }
11181
11182 final long identity = Binder.clearCallingIdentity();
11183 try {
11184 Phone phone = getPhone(subId);
11185 if (phone == null) return null;
11186 ServiceStateTracker sst = phone.getServiceStateTracker();
11187 if (sst == null) return null;
11188 return sst.getLastKnownCellIdentity();
11189 } finally {
11190 Binder.restoreCallingIdentity(identity);
11191 }
11192 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011193
jimsun3b9ccac2021-10-26 15:01:23 +080011194 /**
11195 * Sets the modem service class Name that Telephony will bind to.
11196 *
11197 * @param serviceName The class name of the modem service.
11198 * @return true if the operation is succeed, otherwise false.
11199 */
11200 public boolean setModemService(String serviceName) {
11201 Log.d(LOG_TAG, "setModemService - " + serviceName);
11202 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11204 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11205 "setModemService");
11206 return mPhoneConfigurationManager.setModemService(serviceName);
11207 }
11208
11209 /**
11210 * Return the class name of the currently bounded modem service.
11211 *
11212 * @return the class name of the modem service.
11213 */
11214 public String getModemService() {
11215 String result;
11216 Log.d(LOG_TAG, "getModemService");
11217 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11218 TelephonyPermissions
11219 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11220 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11221 "getModemService");
11222 result = mPhoneConfigurationManager.getModemService();
11223 Log.d(LOG_TAG, "result = " + result);
11224 return result;
11225 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011226
11227 @Override
11228 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11229 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11230 mApp.enforceCallingOrSelfPermission(
11231 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11232 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11233
11234 final long identity = Binder.clearCallingIdentity();
11235 try {
11236 Phone phone = getPhone(subId);
11237 if (phone == null) return;
11238 phone.setVoiceServiceStateOverride(hasService);
11239 } finally {
11240 Binder.restoreCallingIdentity(identity);
11241 }
11242 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011243
11244 /**
11245 * set removable eSIM as default eUICC.
11246 *
11247 * @hide
11248 */
11249 @Override
11250 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11251 enforceModifyPermission();
11252 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11253
11254 final long identity = Binder.clearCallingIdentity();
11255 try {
11256 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11257 } finally {
11258 Binder.restoreCallingIdentity(identity);
11259 }
11260 }
11261
11262 /**
11263 * Returns whether the removable eSIM is default eUICC or not.
11264 *
11265 * @hide
11266 */
11267 @Override
11268 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11269 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11270 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11271
11272 final long identity = Binder.clearCallingIdentity();
11273 try {
11274 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11275 } finally {
11276 Binder.restoreCallingIdentity(identity);
11277 }
11278 }
11279
11280
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011281}