blob: bdbd5f9e8ce0161b240774c18b89824deec4a86b [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070034import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000035import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080036import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080075import android.telephony.AccessNetworkConstants;
76import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070077import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070078import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080079import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080080import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070081import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080082import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070083import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080084import android.telephony.CellIdentityCdma;
85import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070087import android.telephony.CellInfoGsm;
88import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070089import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080090import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070091import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070092import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070093import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080094import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070095import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080096import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070097import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080098import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080099import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700100import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800101import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800103import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800104import android.telephony.SignalStrengthUpdateRequest;
105import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800106import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800107import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800108import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700109import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700110import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800111import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800112import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800113import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000114import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000115import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000116import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700117import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700118import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800119import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800120import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700121import android.telephony.gba.GbaAuthRequest;
122import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700123import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000126import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700127import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000128import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700129import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800130import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700131import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800132import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700133import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000134import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700135import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800136import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800137import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700140import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800142import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800143
Andrew Lee312e8172014-10-23 17:01:36 -0700144import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800145import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800146import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800147import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700150import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700151import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800152import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800153import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800156import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700157import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800158import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800159import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800160import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700161import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000162import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800164import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800166import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800167import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700168import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700169import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700170import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700172import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800173import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700174import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700175import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700176import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700177import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800178import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800179import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700180import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700181import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700182import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800183import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800184import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800185import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700186import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700188import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800189import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700190import com.android.internal.telephony.imsphone.ImsPhone;
191import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000192import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800193import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700194import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195import com.android.internal.telephony.uicc.IccIoResult;
196import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800197import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700198import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000201import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800202import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000203import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800204import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700205import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700206import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800207import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800208import com.android.phone.callcomposer.CallComposerPictureManager;
209import com.android.phone.callcomposer.CallComposerPictureTransfer;
210import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700211import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700212import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800213import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700214import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700215import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800216import com.android.services.telephony.TelecomAccountRegistry;
217import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800218import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800219
Hall Liu82694d52020-12-11 18:22:04 -0800220import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700221import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.io.IOException;
223import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700224import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800226import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000227import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800228import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800229import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800230import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800231import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100232import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800233import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700234import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800235import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800236import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800237import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800238import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800239import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240
241/**
242 * Implementation of the ITelephony interface.
243 */
Santos Cordon117fee72014-05-16 17:56:12 -0700244public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245 private static final String LOG_TAG = "PhoneInterfaceManager";
246 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
247 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800248 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249
250 // Message codes used with mMainThreadHandler
251 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700252 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
253 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700254 private static final int CMD_OPEN_CHANNEL = 9;
255 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
256 private static final int CMD_CLOSE_CHANNEL = 11;
257 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800258 private static final int CMD_NV_READ_ITEM = 13;
259 private static final int EVENT_NV_READ_ITEM_DONE = 14;
260 private static final int CMD_NV_WRITE_ITEM = 15;
261 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
262 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
263 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700264 private static final int CMD_RESET_MODEM_CONFIG = 19;
265 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800266 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
267 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800268 private static final int CMD_SEND_ENVELOPE = 25;
269 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000270 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
271 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700272 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
273 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
274 private static final int CMD_EXCHANGE_SIM_IO = 31;
275 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800276 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
277 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700278 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
279 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700280 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
281 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700282 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
283 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
284 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
285 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700286 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
287 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
288 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
289 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700290 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800291 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
292 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000293 private static final int CMD_SWITCH_SLOTS = 50;
294 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700295 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
296 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
297 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
298 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
299 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
300 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
301 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
302 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700303 private static final int CMD_GET_ALL_CELL_INFO = 60;
304 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
305 private static final int CMD_GET_CELL_LOCATION = 62;
306 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700307 private static final int CMD_MODEM_REBOOT = 64;
308 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700309 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
310 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800311 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
312 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700313 private static final int CMD_GET_MODEM_STATUS = 70;
314 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700315 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
316 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700317 private static final int CMD_ERASE_MODEM_CONFIG = 74;
318 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800319 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
320 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
321 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
322 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800323 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
324 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800325 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800326 private static final int CMD_GET_CALL_FORWARDING = 83;
327 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
328 private static final int CMD_SET_CALL_FORWARDING = 85;
329 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
330 private static final int CMD_GET_CALL_WAITING = 87;
331 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
332 private static final int CMD_SET_CALL_WAITING = 89;
333 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700334 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
335 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
336 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
337 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700338 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
339 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800340 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
341 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800342 private static final int CMD_SET_DATA_THROTTLING = 99;
343 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800344 private static final int CMD_SET_SIM_POWER = 101;
345 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800346 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
347 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
348 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
349 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800350 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
351 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000352 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800353 private static final int CMD_GET_SLICING_CONFIG = 110;
354 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800355 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700356 private static final int CMD_ENABLE_VONR = 113;
357 private static final int EVENT_ENABLE_VONR_DONE = 114;
358 private static final int CMD_IS_VONR_ENABLED = 115;
359 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800361 // Parameters of select command.
362 private static final int SELECT_COMMAND = 0xA4;
363 private static final int SELECT_P1 = 0x04;
364 private static final int SELECT_P2 = 0;
365 private static final int SELECT_P3 = 0x10;
366
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 /** The singleton instance. */
368 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800369 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Wink Saville3ab207e2014-11-20 13:07:20 -0800371 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800373 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700374 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700376 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800378 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700380 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800381 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000382 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383
Peter Wangdafb9ac2020-01-15 14:13:38 -0800384 /** User Activity */
385 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800386 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
387
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700388 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
389
Derek Tan97ebb422014-09-05 16:55:38 -0700390 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
391 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800392 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800393 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700394
Michelecea4cf22018-12-21 15:00:11 -0800395 // String to store multi SIM allowed
396 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
397
Derek Tan740e1672017-06-27 14:56:27 -0700398 // The AID of ISD-R.
399 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
400
yinxub1bed742017-04-17 11:45:04 -0700401 private NetworkScanRequestTracker mNetworkScanRequestTracker;
402
David Kelly5e06a7f2018-03-12 14:10:59 +0000403 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
404 private static final int MANUFACTURER_CODE_LENGTH = 8;
405
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800406 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800407 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800408
Derek Tan89e89d42014-07-08 17:00:10 -0700409 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700410 * Experiment flag to enable erase modem config on reset network, default value is false
411 */
412 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
413 "reset_network_erase_modem_config_enabled";
414
Rambo Wang0f050d82021-02-12 11:43:36 -0800415 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800416
sandeepjsb6c87872021-09-27 15:34:44 +0000417 /**
418 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
419 * one ICCID active at the same time.
420 * Apps should use below API signatures if targeting SDK is T and beyond.
421 *
422 * @hide
423 */
424 @ChangeId
425 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
426 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800427
Naina Nallurid63128d2019-09-17 14:10:30 -0700428 /**
Chen Xu540470b2021-12-14 17:15:47 -0800429 * Apps targeting on Android T and beyond will get exception whenever icc close channel
430 * operation fails.
431 */
432 @ChangeId
433 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
434 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
435
436 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 * A request object to use for transmitting data to an ICC.
438 */
439 private static final class IccAPDUArgument {
440 public int channel, cla, command, p1, p2, p3;
441 public String data;
442
443 public IccAPDUArgument(int channel, int cla, int command,
444 int p1, int p2, int p3, String data) {
445 this.channel = channel;
446 this.cla = cla;
447 this.command = command;
448 this.p1 = p1;
449 this.p2 = p2;
450 this.p3 = p3;
451 this.data = data;
452 }
453 }
454
455 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700456 * A request object to use for transmitting data to an ICC.
457 */
458 private static final class ManualNetworkSelectionArgument {
459 public OperatorInfo operatorInfo;
460 public boolean persistSelection;
461
462 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
463 this.operatorInfo = operatorInfo;
464 this.persistSelection = persistSelection;
465 }
466 }
467
468 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
470 * request after sending. The main thread will notify the request when it is complete.
471 */
472 private static final class MainThreadRequest {
473 /** The argument to use for the request */
474 public Object argument;
475 /** The result of the request that is run on the main thread */
476 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800477 // The subscriber id that this request applies to. Defaults to
478 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
479 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480
Nathan Harold92bed182018-10-12 18:16:49 -0700481 // In cases where subId is unavailable, the caller needs to specify the phone.
482 public Phone phone;
483
vagdeviaf9a5b92018-08-15 16:01:53 -0700484 public WorkSource workSource;
485
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 public MainThreadRequest(Object argument) {
487 this.argument = argument;
488 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800489
Nathan Harold92bed182018-10-12 18:16:49 -0700490 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
491 this.argument = argument;
492 if (phone != null) {
493 this.phone = phone;
494 }
495 this.workSource = workSource;
496 }
497
vagdeviaf9a5b92018-08-15 16:01:53 -0700498 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800499 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800500 if (subId != null) {
501 this.subId = subId;
502 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700503 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505 }
506
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800507 private static final class IncomingThirdPartyCallArgs {
508 public final ComponentName component;
509 public final String callId;
510 public final String callerDisplayName;
511
512 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
513 String callerDisplayName) {
514 this.component = component;
515 this.callId = callId;
516 this.callerDisplayName = callerDisplayName;
517 }
518 }
519
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 /**
521 * A handler that processes messages on the main thread in the phone process. Since many
522 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
523 * inbound binder threads to the main thread in the phone process. The Binder thread
524 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
525 * on, which will be notified when the operation completes and will contain the result of the
526 * request.
527 *
528 * <p>If a MainThreadRequest object is provided in the msg.obj field,
529 * note that request.result must be set to something non-null for the calling thread to
530 * unblock.
531 */
532 private final class MainThreadHandler extends Handler {
533 @Override
534 public void handleMessage(Message msg) {
535 MainThreadRequest request;
536 Message onCompleted;
537 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000538 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800540 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541
542 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 case CMD_HANDLE_USSD_REQUEST: {
544 request = (MainThreadRequest) msg.obj;
545 final Phone phone = getPhoneFromRequest(request);
546 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800547 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700549
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 if (!isUssdApiAllowed(request.subId)) {
551 // Carrier does not support use of this API, return failure.
552 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
553 UssdResponse response = new UssdResponse(ussdRequest, null);
554 Bundle returnData = new Bundle();
555 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
556 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700557
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 request.result = true;
559 notifyRequester(request);
560 return;
561 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700562
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 try {
564 request.result = phone != null
565 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
566 } catch (CallStateException cse) {
567 request.result = false;
568 }
569 // Wake up the requesting thread
570 notifyRequester(request);
571 break;
pkanwar32d516d2016-10-14 19:37:38 -0700572 }
573
Yorke Lee716f67e2015-06-17 15:39:16 -0700574 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700575 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700576 final Phone phone = getPhoneFromRequest(request);
577 request.result = phone != null ?
578 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
579 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700580 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700582 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700584
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000588 uiccPort = getUiccPortFromRequest(request);
589 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800591 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800595 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000596 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800597 iccArgument.channel, iccArgument.cla, iccArgument.command,
598 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
599 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 break;
602
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
608 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800609 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 if (ar.result == null) {
611 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800612 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800614 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 } else {
616 loge("iccTransmitApduLogicalChannel: Unknown exception");
617 }
618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 break;
621
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
624 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000625 uiccPort = getUiccPortFromRequest(request);
626 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800628 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800632 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000633 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800634 iccArgument.cla, iccArgument.command, iccArgument.p1,
635 iccArgument.p2,
636 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 }
638 break;
639
640 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
645 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800646 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 if (ar.result == null) {
648 loge("iccTransmitApduBasicChannel: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("iccTransmitApduBasicChannel: CommandException: " +
651 ar.exception);
652 } else {
653 loge("iccTransmitApduBasicChannel: Unknown exception");
654 }
655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 break;
658
659 case CMD_EXCHANGE_SIM_IO:
660 request = (MainThreadRequest) msg.obj;
661 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000662 uiccPort = getUiccPortFromRequest(request);
663 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800665 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 } else {
668 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
669 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000670 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
672 iccArgument.data, onCompleted);
673 }
674 break;
675
676 case EVENT_EXCHANGE_SIM_IO_DONE:
677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result;
681 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 break;
686
Derek Tan4d5e5c12014-02-04 11:54:58 -0800687 case CMD_SEND_ENVELOPE:
688 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000689 uiccPort = getUiccPortFromRequest(request);
690 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800692 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 } else {
695 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800696 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800698 break;
699
700 case EVENT_SEND_ENVELOPE_DONE:
701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800706 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700707 if (ar.result == null) {
708 loge("sendEnvelopeWithStatus: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("sendEnvelopeWithStatus: CommandException: " +
711 ar.exception);
712 } else {
713 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
714 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800717 break;
718
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 case CMD_OPEN_CHANNEL:
720 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000721 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800722 IccLogicalChannelRequest openChannelRequest =
723 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800726 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800727 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 } else {
730 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800731 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
732 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 break;
735
736 case EVENT_OPEN_CHANNEL_DONE:
737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 int[] result = (int[]) ar.result;
742 int channelId = result[0];
743 byte[] selectResponse = null;
744 if (result.length > 1) {
745 selectResponse = new byte[result.length - 1];
746 for (int i = 1; i < result.length; ++i) {
747 selectResponse[i - 1] = (byte) result[i];
748 }
749 }
750 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800751 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800752
753 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700754 if (uiccPort == null) {
755 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
756 } else {
757 IccLogicalChannelRequest channelRequest =
758 (IccLogicalChannelRequest) request.argument;
759 channelRequest.channel = channelId;
760 uiccPort.onLogicalChannelOpened(channelRequest);
761 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 if (ar.result == null) {
764 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700766 if (ar.exception != null) {
767 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
768 }
769
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700770 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700771 if (ar.exception instanceof CommandException) {
772 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800773 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700774 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700775 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700776 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700777 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700778 }
779 }
780 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800781 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700783 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700784 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 break;
786
787 case CMD_CLOSE_CHANNEL:
788 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000789 uiccPort = getUiccPortFromRequest(request);
790 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700791 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800792 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800793 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800794 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700795 } else {
796 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000797 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700798 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 break;
800
801 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
804 if (ar.exception == null) {
805 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800806 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700807 if (uiccPort == null) {
808 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
809 } else {
810 final int channelId = (Integer) request.argument;
811 uiccPort.onLogicalChannelClosed(channelId);
812 }
Chen Xu540470b2021-12-14 17:15:47 -0800813 } else {
814 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800815 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800816 if (ar.exception instanceof CommandException) {
817 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
818 CommandException.Error error =
819 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800820 if (error == CommandException.Error.INVALID_ARGUMENTS) {
821 // should only throw exceptions from the binder threads.
822 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800823 "iccCloseLogicalChannel: invalid argument ");
824 }
825 } else {
826 loge("iccCloseLogicalChannel: Unknown exception");
827 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800828 request.result = (exception != null) ? exception :
829 new IllegalStateException(
830 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800831 }
832 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800833 break;
834
835 case CMD_NV_READ_ITEM:
836 request = (MainThreadRequest) msg.obj;
837 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800838 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
839 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800840 break;
841
842 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800845 if (ar.exception == null && ar.result != null) {
846 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700847 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800848 request.result = "";
849 if (ar.result == null) {
850 loge("nvReadItem: Empty response");
851 } else if (ar.exception instanceof CommandException) {
852 loge("nvReadItem: CommandException: " +
853 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700854 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800855 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700856 }
857 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700858 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700859 break;
860
Jake Hambye994d462014-02-03 13:10:13 -0800861 case CMD_NV_WRITE_ITEM:
862 request = (MainThreadRequest) msg.obj;
863 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
864 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800865 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700866 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800867 break;
868
869 case EVENT_NV_WRITE_ITEM_DONE:
870 handleNullReturnEvent(msg, "nvWriteItem");
871 break;
872
873 case CMD_NV_WRITE_CDMA_PRL:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800876 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800877 break;
878
879 case EVENT_NV_WRITE_CDMA_PRL_DONE:
880 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
881 break;
882
chen xu6dac5ab2018-10-26 17:39:23 -0700883 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800884 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700885 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800886 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800887 break;
888
chen xu6dac5ab2018-10-26 17:39:23 -0700889 case EVENT_RESET_MODEM_CONFIG_DONE:
890 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800891 break;
892
Sooraj Sasindran37444802020-08-11 10:40:43 -0700893 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
894 request = (MainThreadRequest) msg.obj;
895 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
896 request);
897 Phone phone = getPhoneFromRequest(request);
898 if (phone != null) {
899 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
900 } else {
901 loge("isNRDualConnectivityEnabled: No phone object");
902 request.result = false;
903 notifyRequester(request);
904 }
905 break;
906 }
907
908 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result;
913 } else {
914 // request.result must be set to something non-null
915 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700916 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700917 request.result = ar.result;
918 } else {
919 request.result = false;
920 }
921 if (ar.result == null) {
922 loge("isNRDualConnectivityEnabled: Empty response");
923 } else if (ar.exception instanceof CommandException) {
924 loge("isNRDualConnectivityEnabled: CommandException: "
925 + ar.exception);
926 } else {
927 loge("isNRDualConnectivityEnabled: Unknown exception");
928 }
929 }
930 notifyRequester(request);
931 break;
932
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700933 case CMD_IS_VONR_ENABLED: {
934 request = (MainThreadRequest) msg.obj;
935 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
936 request);
937 Phone phone = getPhoneFromRequest(request);
938 if (phone != null) {
939 phone.isVoNrEnabled(onCompleted, request.workSource);
940 } else {
941 loge("isVoNrEnabled: No phone object");
942 request.result = false;
943 notifyRequester(request);
944 }
945 break;
946 }
947
948 case EVENT_IS_VONR_ENABLED_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 if (ar.exception == null && ar.result != null) {
952 request.result = ar.result;
953 } else {
954 // request.result must be set to something non-null
955 // for the calling thread to unblock
956 if (ar.result != null) {
957 request.result = ar.result;
958 } else {
959 request.result = false;
960 }
961 if (ar.result == null) {
962 loge("isVoNrEnabled: Empty response");
963 } else if (ar.exception instanceof CommandException) {
964 loge("isVoNrEnabled: CommandException: "
965 + ar.exception);
966 } else {
967 loge("isVoNrEnabled: Unknown exception");
968 }
969 }
970 notifyRequester(request);
971 break;
972
Sooraj Sasindran37444802020-08-11 10:40:43 -0700973 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
974 request = (MainThreadRequest) msg.obj;
975 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
976 Phone phone = getPhoneFromRequest(request);
977 if (phone != null) {
978 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
979 request.workSource);
980 } else {
981 loge("enableNrDualConnectivity: No phone object");
982 request.result =
983 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
984 notifyRequester(request);
985 }
986 break;
987 }
988
989 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 if (ar.exception == null) {
993 request.result =
994 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
995 } else {
996 request.result =
997 TelephonyManager
998 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
999 if (ar.exception instanceof CommandException) {
1000 CommandException.Error error =
1001 ((CommandException) (ar.exception)).getCommandError();
1002 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1003 request.result =
1004 TelephonyManager
1005 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001006 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1007 request.result =
1008 TelephonyManager
1009 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001010 }
1011 loge("enableNrDualConnectivity" + ": CommandException: "
1012 + ar.exception);
1013 } else {
1014 loge("enableNrDualConnectivity" + ": Unknown exception");
1015 }
1016 }
1017 notifyRequester(request);
1018 break;
1019 }
1020
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001021 case CMD_ENABLE_VONR: {
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1024 Phone phone = getPhoneFromRequest(request);
1025 if (phone != null) {
1026 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1027 request.workSource);
1028 } else {
1029 loge("setVoNrEnabled: No phone object");
1030 request.result =
1031 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1032 notifyRequester(request);
1033 }
1034 break;
1035 }
1036
1037 case EVENT_ENABLE_VONR_DONE: {
1038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
1040 if (ar.exception == null) {
1041 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1042 } else {
1043 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1044 if (ar.exception instanceof CommandException) {
1045 CommandException.Error error =
1046 ((CommandException) (ar.exception)).getCommandError();
1047 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1048 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1049 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1050 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1051 } else {
1052 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1053 }
1054 loge("setVoNrEnabled" + ": CommandException: "
1055 + ar.exception);
1056 } else {
1057 loge("setVoNrEnabled" + ": Unknown exception");
1058 }
1059 }
1060 notifyRequester(request);
1061 break;
1062 }
1063
SongFerngWang3ef3e072020-12-21 16:41:52 +08001064 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001065 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001066 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1067 request);
1068 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001069 break;
1070
SongFerngWang3ef3e072020-12-21 16:41:52 +08001071 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001072 ar = (AsyncResult) msg.obj;
1073 request = (MainThreadRequest) ar.userObj;
1074 if (ar.exception == null && ar.result != null) {
1075 request.result = ar.result; // Integer
1076 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301077 // request.result must be set to something non-null
1078 // for the calling thread to unblock
1079 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001080 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001081 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001082 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001083 loge("getAllowedNetworkTypesBitmask: CommandException: "
1084 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001087 }
1088 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001089 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 break;
1091
SongFerngWang3ef3e072020-12-21 16:41:52 +08001092 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001093 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001094 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1095 request);
1096 Pair<Integer, Long> reasonWithNetworkTypes =
1097 (Pair<Integer, Long>) request.argument;
1098 getPhoneFromRequest(request).setAllowedNetworkTypes(
1099 reasonWithNetworkTypes.first,
1100 reasonWithNetworkTypes.second,
1101 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001102 break;
1103
SongFerngWang3ef3e072020-12-21 16:41:52 +08001104 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1105 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001106 break;
1107
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001108 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1109 request = (MainThreadRequest)msg.obj;
1110 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001111 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001112 break;
1113
1114 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1115 ar = (AsyncResult)msg.obj;
1116 request = (MainThreadRequest)ar.userObj;
1117 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001118 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001119 break;
1120
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001121 case CMD_SET_VOICEMAIL_NUMBER:
1122 request = (MainThreadRequest) msg.obj;
1123 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1124 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001125 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1126 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001127 break;
1128
1129 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1130 handleNullReturnEvent(msg, "setVoicemailNumber");
1131 break;
1132
Stuart Scott54788802015-03-30 13:18:01 -07001133 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1134 request = (MainThreadRequest) msg.obj;
1135 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1136 request);
1137 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1138 break;
1139
1140 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1141 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1142 break;
1143
Shishir Agrawal302c8692015-06-19 13:49:39 -07001144 case CMD_PERFORM_NETWORK_SCAN:
1145 request = (MainThreadRequest) msg.obj;
1146 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1147 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1148 break;
1149
Hall Liu27d24262020-09-18 19:04:59 -07001150 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001151 request = (MainThreadRequest) msg.obj;
1152 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001153 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1154 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1155 request.argument;
1156 int callForwardingReason = args.first;
1157 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001158 break;
Hall Liu27d24262020-09-18 19:04:59 -07001159 }
1160 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001163 TelephonyManager.CallForwardingInfoCallback callback =
1164 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1165 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001166 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001167 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001168 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1169 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1170 // Service Class is a bit mask per 3gpp 27.007. Search for
1171 // any service for voice call.
1172 if ((callForwardInfo.serviceClass
1173 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001174 callForwardingInfo = new CallForwardingInfo(
1175 callForwardInfo.status
1176 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001177 callForwardInfo.reason,
1178 callForwardInfo.number,
1179 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001180 break;
1181 }
1182 }
1183 // Didn't find a call forward info for voice call.
1184 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001185 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1186 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001187 }
Hall Liu27d24262020-09-18 19:04:59 -07001188 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001189 } else {
1190 if (ar.result == null) {
1191 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1192 }
1193 if (ar.exception != null) {
1194 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1195 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001196 int errorCode = TelephonyManager
1197 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001198 if (ar.exception instanceof CommandException) {
1199 CommandException.Error error =
1200 ((CommandException) (ar.exception)).getCommandError();
1201 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001202 errorCode = TelephonyManager
1203 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001204 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001205 errorCode = TelephonyManager
1206 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 }
1208 }
Hall Liu27d24262020-09-18 19:04:59 -07001209 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001210 }
Shuo Qian4a594052020-01-23 11:59:30 -08001211 break;
Hall Liu27d24262020-09-18 19:04:59 -07001212 }
Shuo Qian4a594052020-01-23 11:59:30 -08001213
Hall Liu27d24262020-09-18 19:04:59 -07001214 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001215 request = (MainThreadRequest) msg.obj;
1216 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001217 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001218 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001219 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1220 request.argument).first;
1221 request.phone.setCallForwardingOption(
1222 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001223 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001224 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001225 callForwardingInfoToSet.getReason(),
1226 callForwardingInfoToSet.getNumber(),
1227 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1228 break;
Hall Liu27d24262020-09-18 19:04:59 -07001229 }
Shuo Qian4a594052020-01-23 11:59:30 -08001230
Hall Liu27d24262020-09-18 19:04:59 -07001231 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001232 ar = (AsyncResult) msg.obj;
1233 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001234 Consumer<Integer> callback =
1235 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1236 request.argument).second;
1237 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001238 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001239 int errorCode = TelephonyManager.CallForwardingInfoCallback
1240 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001241 if (ar.exception instanceof CommandException) {
1242 CommandException.Error error =
1243 ((CommandException) (ar.exception)).getCommandError();
1244 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001245 errorCode = TelephonyManager.CallForwardingInfoCallback
1246 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001247 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001248 errorCode = TelephonyManager.CallForwardingInfoCallback
1249 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001250 }
1251 }
1252 callback.accept(errorCode);
1253 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001254 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001255 }
Shuo Qian4a594052020-01-23 11:59:30 -08001256 break;
Hall Liu27d24262020-09-18 19:04:59 -07001257 }
Shuo Qian4a594052020-01-23 11:59:30 -08001258
Hall Liu27d24262020-09-18 19:04:59 -07001259 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001260 request = (MainThreadRequest) msg.obj;
1261 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1262 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1263 break;
Hall Liu27d24262020-09-18 19:04:59 -07001264 }
Shuo Qian4a594052020-01-23 11:59:30 -08001265
Hall Liu27d24262020-09-18 19:04:59 -07001266 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001269 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001270 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001271 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001272 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 // Service Class is a bit mask per 3gpp 27.007.
1274 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001275 if (callForwardResults.length > 1
1276 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001277 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001278 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001279 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1280 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001281 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001282 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001283 }
1284 } else {
1285 if (ar.result == null) {
1286 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1287 }
1288 if (ar.exception != null) {
1289 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1290 }
1291 if (ar.exception instanceof CommandException) {
1292 CommandException.Error error =
1293 ((CommandException) (ar.exception)).getCommandError();
1294 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001295 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001296 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001297 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1298 callWaitingStatus =
1299 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001300 }
1301 }
1302 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001303 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001304 break;
Hall Liu27d24262020-09-18 19:04:59 -07001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306
Hall Liu27d24262020-09-18 19:04:59 -07001307 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001308 request = (MainThreadRequest) msg.obj;
1309 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001310 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1311 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001312 break;
Hall Liu27d24262020-09-18 19:04:59 -07001313 }
Shuo Qian4a594052020-01-23 11:59:30 -08001314
Hall Liu27d24262020-09-18 19:04:59 -07001315 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001316 ar = (AsyncResult) msg.obj;
1317 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001318 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1319 Consumer<Integer> callback =
1320 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1321 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001322 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001323 if (ar.exception instanceof CommandException) {
1324 CommandException.Error error =
1325 ((CommandException) (ar.exception)).getCommandError();
1326 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1327 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1329 callback.accept(
1330 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001331 } else {
1332 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1333 }
1334 } else {
1335 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1336 }
1337 } else {
1338 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1339 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001340 }
Shuo Qian4a594052020-01-23 11:59:30 -08001341 break;
Hall Liu27d24262020-09-18 19:04:59 -07001342 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001343 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1344 ar = (AsyncResult) msg.obj;
1345 request = (MainThreadRequest) ar.userObj;
1346 CellNetworkScanResult cellScanResult;
1347 if (ar.exception == null && ar.result != null) {
1348 cellScanResult = new CellNetworkScanResult(
1349 CellNetworkScanResult.STATUS_SUCCESS,
1350 (List<OperatorInfo>) ar.result);
1351 } else {
1352 if (ar.result == null) {
1353 loge("getCellNetworkScanResults: Empty response");
1354 }
1355 if (ar.exception != null) {
1356 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1357 }
1358 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1359 if (ar.exception instanceof CommandException) {
1360 CommandException.Error error =
1361 ((CommandException) (ar.exception)).getCommandError();
1362 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1363 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1364 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1365 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1366 }
1367 }
1368 cellScanResult = new CellNetworkScanResult(errorCode, null);
1369 }
1370 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001371 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001372 break;
1373
1374 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1375 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001376 ManualNetworkSelectionArgument selArg =
1377 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001378 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1379 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001380 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1381 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001382 break;
1383
1384 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 if (ar.exception == null) {
1388 request.result = true;
1389 } else {
1390 request.result = false;
1391 loge("setNetworkSelectionModeManual " + ar.exception);
1392 }
1393 notifyRequester(request);
1394 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001395 break;
1396
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001397 case CMD_GET_MODEM_ACTIVITY_INFO:
1398 request = (MainThreadRequest) msg.obj;
1399 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001400 if (defaultPhone != null) {
1401 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001402 } else {
1403 ResultReceiver result = (ResultReceiver) request.argument;
1404 Bundle bundle = new Bundle();
1405 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001406 new ModemActivityInfo(0, 0, 0,
1407 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001408 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001409 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001410 break;
1411
Hall Liud0f208c2020-10-14 16:54:44 -07001412 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001413 ar = (AsyncResult) msg.obj;
1414 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001415 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001416 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001417 if (mLastModemActivityInfo == null) {
1418 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1419 mLastModemActivitySpecificInfo[0] =
1420 new ActivityStatsTechSpecificInfo(
1421 0,
1422 0,
1423 new int[ModemActivityInfo.getNumTxPowerLevels()],
1424 0);
1425 mLastModemActivityInfo =
1426 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1427 }
1428
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001429 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001430 // Update the last modem activity info and the result of the request.
1431 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1432 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001433 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001434 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001435 mLastModemActivityInfo =
1436 new ModemActivityInfo(
1437 mLastModemActivityInfo.getTimestampMillis(),
1438 mLastModemActivityInfo.getSleepTimeMillis(),
1439 mLastModemActivityInfo.getIdleTimeMillis(),
1440 mLastModemActivitySpecificInfo);
1441
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001442 } else {
1443 if (ar.result == null) {
1444 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001445 error = TelephonyManager.ModemActivityInfoException
1446 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001448 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001449 error = TelephonyManager.ModemActivityInfoException
1450 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001451 } else {
1452 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001453 error = TelephonyManager.ModemActivityInfoException
1454 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 }
1456 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001457 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001458 if (mLastModemActivityInfo != null) {
1459 bundle.putParcelable(
1460 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1461 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001462 } else {
1463 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1464 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001466 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001467 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001468 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001469
Meng Wang1a7c35a2016-05-05 20:56:15 -07001470 case CMD_SET_ALLOWED_CARRIERS:
1471 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001472 CarrierRestrictionRules argument =
1473 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001474 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001475 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001476 break;
1477
1478 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1479 ar = (AsyncResult) msg.obj;
1480 request = (MainThreadRequest) ar.userObj;
1481 if (ar.exception == null && ar.result != null) {
1482 request.result = ar.result;
1483 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001484 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1485 if (ar.exception instanceof CommandException) {
1486 loge("setAllowedCarriers: CommandException: " + ar.exception);
1487 CommandException.Error error =
1488 ((CommandException) (ar.exception)).getCommandError();
1489 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1490 request.result =
1491 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1492 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001493 } else {
1494 loge("setAllowedCarriers: Unknown exception");
1495 }
1496 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001497 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001498 break;
1499
1500 case CMD_GET_ALLOWED_CARRIERS:
1501 request = (MainThreadRequest) msg.obj;
1502 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001503 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001504 break;
1505
1506 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1507 ar = (AsyncResult) msg.obj;
1508 request = (MainThreadRequest) ar.userObj;
1509 if (ar.exception == null && ar.result != null) {
1510 request.result = ar.result;
1511 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001512 request.result = new IllegalStateException(
1513 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001514 if (ar.result == null) {
1515 loge("getAllowedCarriers: Empty response");
1516 } else if (ar.exception instanceof CommandException) {
1517 loge("getAllowedCarriers: CommandException: " +
1518 ar.exception);
1519 } else {
1520 loge("getAllowedCarriers: Unknown exception");
1521 }
1522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001523 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001524 break;
1525
Nathan Haroldb3014052017-01-25 15:57:32 -08001526 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1527 ar = (AsyncResult) msg.obj;
1528 request = (MainThreadRequest) ar.userObj;
1529 if (ar.exception == null && ar.result != null) {
1530 request.result = ar.result;
1531 } else {
1532 request.result = new IllegalArgumentException(
1533 "Failed to retrieve Forbidden Plmns");
1534 if (ar.result == null) {
1535 loge("getForbiddenPlmns: Empty response");
1536 } else {
1537 loge("getForbiddenPlmns: Unknown exception");
1538 }
1539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001540 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001541 break;
1542
1543 case CMD_GET_FORBIDDEN_PLMNS:
1544 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001545 uiccPort = getUiccPortFromRequest(request);
1546 if (uiccPort == null) {
1547 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001548 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001549 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001550 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001551 break;
1552 }
1553 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001554 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001555 if (uiccApp == null) {
1556 loge("getForbiddenPlmns() no app with specified type -- "
1557 + appType);
1558 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001559 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001560 break;
1561 } else {
1562 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1563 + " specified type -- " + appType);
1564 }
1565 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1566 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1567 onCompleted);
1568 break;
1569
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001570 case CMD_SWITCH_SLOTS:
1571 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001572 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001573 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001574 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001575 break;
1576
1577 case EVENT_SWITCH_SLOTS_DONE:
1578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
1580 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001581 notifyRequester(request);
1582 break;
1583 case CMD_GET_NETWORK_SELECTION_MODE:
1584 request = (MainThreadRequest) msg.obj;
1585 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1586 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1587 break;
1588
1589 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1590 ar = (AsyncResult) msg.obj;
1591 request = (MainThreadRequest) ar.userObj;
1592 if (ar.exception != null) {
1593 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1594 } else {
1595 int mode = ((int[]) ar.result)[0];
1596 if (mode == 0) {
1597 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1598 } else {
1599 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1600 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001601 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001602 notifyRequester(request);
1603 break;
1604 case CMD_GET_CDMA_ROAMING_MODE:
1605 request = (MainThreadRequest) msg.obj;
1606 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1607 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1608 break;
1609 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1610 ar = (AsyncResult) msg.obj;
1611 request = (MainThreadRequest) ar.userObj;
1612 if (ar.exception != null) {
1613 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1614 } else {
1615 request.result = ((int[]) ar.result)[0];
1616 }
1617 notifyRequester(request);
1618 break;
1619 case CMD_SET_CDMA_ROAMING_MODE:
1620 request = (MainThreadRequest) msg.obj;
1621 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1622 int mode = (int) request.argument;
1623 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1624 break;
1625 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1626 ar = (AsyncResult) msg.obj;
1627 request = (MainThreadRequest) ar.userObj;
1628 request.result = ar.exception == null;
1629 notifyRequester(request);
1630 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001631 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1632 request = (MainThreadRequest) msg.obj;
1633 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1634 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1635 break;
1636 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1637 ar = (AsyncResult) msg.obj;
1638 request = (MainThreadRequest) ar.userObj;
1639 if (ar.exception != null) {
1640 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1641 } else {
1642 request.result = ((int[]) ar.result)[0];
1643 }
1644 notifyRequester(request);
1645 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001646 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1647 request = (MainThreadRequest) msg.obj;
1648 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1649 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001650 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1651 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001652 break;
1653 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1654 ar = (AsyncResult) msg.obj;
1655 request = (MainThreadRequest) ar.userObj;
1656 request.result = ar.exception == null;
1657 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001658 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001659 case CMD_GET_ALL_CELL_INFO:
1660 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001661 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001662 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001663 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001664 case EVENT_GET_ALL_CELL_INFO_DONE:
1665 ar = (AsyncResult) msg.obj;
1666 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001667 // If a timeout occurs, the response will be null
1668 request.result = (ar.exception == null && ar.result != null)
1669 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001670 synchronized (request) {
1671 request.notifyAll();
1672 }
1673 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001674 case CMD_REQUEST_CELL_INFO_UPDATE:
1675 request = (MainThreadRequest) msg.obj;
1676 request.phone.requestCellInfoUpdate(request.workSource,
1677 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1678 break;
1679 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1680 ar = (AsyncResult) msg.obj;
1681 request = (MainThreadRequest) ar.userObj;
1682 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1683 try {
1684 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001685 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001686 cb.onError(
1687 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1688 ar.exception.getClass().getName(),
1689 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001690 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001691 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001692 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001693 } else {
1694 // use the result as returned
1695 cb.onCellInfo((List<CellInfo>) ar.result);
1696 }
1697 } catch (RemoteException re) {
1698 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1699 }
1700 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001701 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001702 request = (MainThreadRequest) msg.obj;
1703 WorkSource ws = (WorkSource) request.argument;
1704 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001705 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001706 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001707 }
1708 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001709 ar = (AsyncResult) msg.obj;
1710 request = (MainThreadRequest) ar.userObj;
1711 if (ar.exception == null) {
1712 request.result = ar.result;
1713 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001714 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001715 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001716 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001717 }
1718
1719 synchronized (request) {
1720 request.notifyAll();
1721 }
1722 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001723 }
chen xu6dac5ab2018-10-26 17:39:23 -07001724 case CMD_MODEM_REBOOT:
1725 request = (MainThreadRequest) msg.obj;
1726 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001727 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001728 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001729 case EVENT_CMD_MODEM_REBOOT_DONE:
1730 handleNullReturnEvent(msg, "rebootModem");
1731 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001732 case CMD_REQUEST_ENABLE_MODEM:
1733 request = (MainThreadRequest) msg.obj;
1734 boolean enable = (boolean) request.argument;
1735 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001736 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001737 PhoneConfigurationManager.getInstance()
1738 .enablePhone(request.phone, enable, onCompleted);
1739 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001740 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001741 ar = (AsyncResult) msg.obj;
1742 request = (MainThreadRequest) ar.userObj;
1743 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001744 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001745 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001746 if ((boolean) request.result) {
1747 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1748 updateModemStateMetrics();
1749 } else {
1750 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1751 + ar.exception);
1752 }
1753 notifyRequester(request);
1754 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001755 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001756 case CMD_GET_MODEM_STATUS:
1757 request = (MainThreadRequest) msg.obj;
1758 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1759 PhoneConfigurationManager.getInstance()
1760 .getPhoneStatusFromModem(request.phone, onCompleted);
1761 break;
1762 case EVENT_GET_MODEM_STATUS_DONE:
1763 ar = (AsyncResult) msg.obj;
1764 request = (MainThreadRequest) ar.userObj;
1765 int id = request.phone.getPhoneId();
1766 if (ar.exception == null && ar.result != null) {
1767 request.result = ar.result;
1768 //update the cache as modem status has changed
1769 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1770 (boolean) request.result);
1771 } else {
1772 // Return true if modem status cannot be retrieved. For most cases,
1773 // modem status is on. And for older version modems, GET_MODEM_STATUS
1774 // and disable modem are not supported. Modem is always on.
1775 // TODO: this should be fixed in R to support a third
1776 // status UNKNOWN b/131631629
1777 request.result = true;
1778 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1779 + ar.exception);
1780 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001781 notifyRequester(request);
1782 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001783 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1784 request = (MainThreadRequest) msg.obj;
1785 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1786 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1787 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1788 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1789 break;
1790 }
1791 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1792 ar = (AsyncResult) msg.obj;
1793 request = (MainThreadRequest) ar.userObj;
1794 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1795 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1796 args.second.accept(ar.exception == null);
1797 notifyRequester(request);
1798 break;
1799 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001800 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1801 request = (MainThreadRequest) msg.obj;
1802 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1803 Phone phone = getPhoneFromRequest(request);
1804 if (phone != null) {
1805 phone.getSystemSelectionChannels(onCompleted);
1806 } else {
1807 loge("getSystemSelectionChannels: No phone object");
1808 request.result = new ArrayList<RadioAccessSpecifier>();
1809 notifyRequester(request);
1810 }
1811 break;
1812 }
1813 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1814 ar = (AsyncResult) msg.obj;
1815 request = (MainThreadRequest) ar.userObj;
1816 if (ar.exception == null && ar.result != null) {
1817 request.result = ar.result;
1818 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001819 request.result = new IllegalStateException(
1820 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001821 if (ar.result == null) {
1822 loge("getSystemSelectionChannels: Empty response");
1823 } else {
1824 loge("getSystemSelectionChannels: Unknown exception");
1825 }
1826 }
1827 notifyRequester(request);
1828 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001829 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1830 ar = (AsyncResult) msg.obj;
1831 request = (MainThreadRequest) ar.userObj;
1832 if (ar.exception == null && ar.result != null) {
1833 request.result = ar.result;
1834 } else {
1835 request.result = -1;
1836 loge("Failed to set Forbidden Plmns");
1837 if (ar.result == null) {
1838 loge("setForbidenPlmns: Empty response");
1839 } else if (ar.exception != null) {
1840 loge("setForbiddenPlmns: Exception: " + ar.exception);
1841 request.result = -1;
1842 } else {
1843 loge("setForbiddenPlmns: Unknown exception");
1844 }
1845 }
1846 notifyRequester(request);
1847 break;
1848 case CMD_SET_FORBIDDEN_PLMNS:
1849 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001850 uiccPort = getUiccPortFromRequest(request);
1851 if (uiccPort == null) {
1852 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001853 request.result = -1;
1854 notifyRequester(request);
1855 break;
1856 }
1857 Pair<Integer, List<String>> setFplmnsArgs =
1858 (Pair<Integer, List<String>>) request.argument;
1859 appType = setFplmnsArgs.first;
1860 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001861 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001862 if (uiccApp == null) {
1863 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1864 request.result = -1;
1865 loge("Failed to get UICC App");
1866 notifyRequester(request);
1867 } else {
1868 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1869 ((SIMRecords) uiccApp.getIccRecords())
1870 .setForbiddenPlmns(onCompleted, fplmns);
1871 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001872 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001873 case CMD_ERASE_MODEM_CONFIG:
1874 request = (MainThreadRequest) msg.obj;
1875 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1876 defaultPhone.eraseModemConfig(onCompleted);
1877 break;
1878 case EVENT_ERASE_MODEM_CONFIG_DONE:
1879 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001880 break;
zoey chene02881a2019-12-30 16:11:23 +08001881
Kai Shif70f46f2021-03-03 13:59:46 -08001882 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1883 request = (MainThreadRequest) msg.obj;
1884 request.result = defaultPhone.eraseDataInSharedPreferences();
1885 notifyRequester(request);
1886 break;
1887
zoey chene02881a2019-12-30 16:11:23 +08001888 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1889 request = (MainThreadRequest) msg.obj;
1890 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1891 Pair<String, String> changed = (Pair<String, String>) request.argument;
1892 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1893 changed.first, changed.second, onCompleted);
1894 break;
1895 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1896 ar = (AsyncResult) msg.obj;
1897 request = (MainThreadRequest) ar.userObj;
1898 if (ar.exception == null) {
1899 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001900 // If the operation is successful, update the PIN storage
1901 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1902 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001903 UiccController.getInstance().getPinStorage()
1904 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001905 } else {
1906 request.result = msg.arg1;
1907 }
1908 notifyRequester(request);
1909 break;
1910
Michele Berionne5e411512020-11-13 02:36:59 +00001911 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001912 request = (MainThreadRequest) msg.obj;
1913 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1914 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1915 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1916 enabled.first, enabled.second, onCompleted);
1917 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001918 }
zoey chene02881a2019-12-30 16:11:23 +08001919 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1920 ar = (AsyncResult) msg.obj;
1921 request = (MainThreadRequest) ar.userObj;
1922 if (ar.exception == null) {
1923 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001924 // If the operation is successful, update the PIN storage
1925 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1926 int phoneId = getPhoneFromRequest(request).getPhoneId();
1927 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001928 UiccController.getInstance().getPinStorage()
1929 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001930 } else {
1931 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1932 }
zoey chene02881a2019-12-30 16:11:23 +08001933 } else {
1934 request.result = msg.arg1;
1935 }
Michele Berionne5e411512020-11-13 02:36:59 +00001936
1937
zoey chene02881a2019-12-30 16:11:23 +08001938 notifyRequester(request);
1939 break;
1940
Peter Wangdafb9ac2020-01-15 14:13:38 -08001941 case MSG_NOTIFY_USER_ACTIVITY:
1942 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001943 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001944 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1945 getDefaultPhone().getContext().sendBroadcastAsUser(
1946 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1947 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001948
1949 case CMD_SET_DATA_THROTTLING: {
1950 request = (MainThreadRequest) msg.obj;
1951 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1952 DataThrottlingRequest dataThrottlingRequest =
1953 (DataThrottlingRequest) request.argument;
1954 Phone phone = getPhoneFromRequest(request);
1955 if (phone != null) {
1956 phone.setDataThrottling(onCompleted,
1957 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1958 dataThrottlingRequest.getCompletionDurationMillis());
1959 } else {
1960 loge("setDataThrottling: No phone object");
1961 request.result =
1962 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1963 notifyRequester(request);
1964 }
1965
1966 break;
1967 }
1968 case EVENT_SET_DATA_THROTTLING_DONE:
1969 ar = (AsyncResult) msg.obj;
1970 request = (MainThreadRequest) ar.userObj;
1971
1972 if (ar.exception == null) {
1973 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1974 } else if (ar.exception instanceof CommandException) {
1975 loge("setDataThrottling: CommandException: " + ar.exception);
1976 CommandException.Error error =
1977 ((CommandException) (ar.exception)).getCommandError();
1978
1979 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1980 request.result = TelephonyManager
1981 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1982 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1983 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001984 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1985 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001986 } else {
1987 request.result =
1988 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1989 }
1990 } else {
1991 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1992 }
1993 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1994 notifyRequester(request);
1995 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001996
1997 case CMD_SET_SIM_POWER: {
1998 request = (MainThreadRequest) msg.obj;
1999 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2000 request = (MainThreadRequest) msg.obj;
2001 int stateToSet =
2002 ((Pair<Integer, IIntegerConsumer>)
2003 request.argument).first;
2004 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2005 break;
2006 }
2007 case EVENT_SET_SIM_POWER_DONE: {
2008 ar = (AsyncResult) msg.obj;
2009 request = (MainThreadRequest) ar.userObj;
2010 IIntegerConsumer callback =
2011 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2012 if (ar.exception != null) {
2013 loge("setSimPower exception: " + ar.exception);
2014 int errorCode = TelephonyManager.CallForwardingInfoCallback
2015 .RESULT_ERROR_UNKNOWN;
2016 if (ar.exception instanceof CommandException) {
2017 CommandException.Error error =
2018 ((CommandException) (ar.exception)).getCommandError();
2019 if (error == CommandException.Error.SIM_ERR) {
2020 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2021 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2022 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2023 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2024 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2025 } else {
2026 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2027 }
2028 }
2029 try {
2030 callback.accept(errorCode);
2031 } catch (RemoteException e) {
2032 // Ignore if the remote process is no longer available to call back.
2033 Log.w(LOG_TAG, "setSimPower: callback not available.");
2034 }
2035 } else {
2036 try {
2037 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2038 } catch (RemoteException e) {
2039 // Ignore if the remote process is no longer available to call back.
2040 Log.w(LOG_TAG, "setSimPower: callback not available.");
2041 }
2042 }
2043 break;
2044 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002045 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2046 request = (MainThreadRequest) msg.obj;
2047
2048 final Phone phone = getPhoneFromRequest(request);
2049 if (phone == null || phone.getServiceStateTracker() == null) {
2050 request.result = new IllegalStateException("Phone or SST is null");
2051 notifyRequester(request);
2052 break;
2053 }
2054
2055 Pair<Integer, SignalStrengthUpdateRequest> pair =
2056 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2057 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2058 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002059 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002060 request.subId, pair.first /*callingUid*/,
2061 pair.second /*request*/, onCompleted);
2062 break;
2063 }
2064 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2065 ar = (AsyncResult) msg.obj;
2066 request = (MainThreadRequest) ar.userObj;
2067 // request.result will be the exception of ar if present, true otherwise.
2068 // Be cautious not to leave result null which will wait() forever
2069 request.result = ar.exception != null ? ar.exception : true;
2070 notifyRequester(request);
2071 break;
2072 }
2073 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2074 request = (MainThreadRequest) msg.obj;
2075
2076 Phone phone = getPhoneFromRequest(request);
2077 if (phone == null || phone.getServiceStateTracker() == null) {
2078 request.result = new IllegalStateException("Phone or SST is null");
2079 notifyRequester(request);
2080 break;
2081 }
2082
2083 Pair<Integer, SignalStrengthUpdateRequest> pair =
2084 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2085 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2086 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002087 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002088 request.subId, pair.first /*callingUid*/,
2089 pair.second /*request*/, onCompleted);
2090 break;
2091 }
2092 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2093 ar = (AsyncResult) msg.obj;
2094 request = (MainThreadRequest) ar.userObj;
2095 request.result = ar.exception != null ? ar.exception : true;
2096 notifyRequester(request);
2097 break;
2098 }
Jordan Liu109698e2020-11-24 14:50:34 -08002099
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002100 case CMD_GET_SLICING_CONFIG: {
2101 request = (MainThreadRequest) msg.obj;
2102 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2103 request.phone.getSlicingConfig(onCompleted);
2104 break;
2105 }
2106 case EVENT_GET_SLICING_CONFIG_DONE: {
2107 ar = (AsyncResult) msg.obj;
2108 request = (MainThreadRequest) ar.userObj;
2109 ResultReceiver result = (ResultReceiver) request.argument;
2110
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002111 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002112 Bundle bundle = new Bundle();
2113 int resultCode = 0;
2114 if (ar.exception != null) {
2115 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2116 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002117 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002118 } else if (ar.result == null) {
2119 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002120 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002121 } else {
2122 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002123 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2124 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002125 }
2126
2127 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002128 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002129 }
2130 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2131 result.send(resultCode, bundle);
2132 notifyRequester(request);
2133 break;
2134 }
2135
Michele Berionne5e411512020-11-13 02:36:59 +00002136 case CMD_PREPARE_UNATTENDED_REBOOT:
2137 request = (MainThreadRequest) msg.obj;
2138 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002139 UiccController.getInstance().getPinStorage()
2140 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002141 notifyRequester(request);
2142 break;
2143
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 default:
2145 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2146 break;
2147 }
2148 }
Jake Hambye994d462014-02-03 13:10:13 -08002149
Pengquan Menga1bb6272018-09-06 09:59:22 -07002150 private void notifyRequester(MainThreadRequest request) {
2151 synchronized (request) {
2152 request.notifyAll();
2153 }
2154 }
2155
Jake Hambye994d462014-02-03 13:10:13 -08002156 private void handleNullReturnEvent(Message msg, String command) {
2157 AsyncResult ar = (AsyncResult) msg.obj;
2158 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2159 if (ar.exception == null) {
2160 request.result = true;
2161 } else {
2162 request.result = false;
2163 if (ar.exception instanceof CommandException) {
2164 loge(command + ": CommandException: " + ar.exception);
2165 } else {
2166 loge(command + ": Unknown exception");
2167 }
2168 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002169 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 }
2172
2173 /**
2174 * Posts the specified command to be executed on the main thread,
2175 * waits for the request to complete, and returns the result.
2176 * @see #sendRequestAsync
2177 */
2178 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002179 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2180 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002181 }
2182
2183 /**
2184 * Posts the specified command to be executed on the main thread,
2185 * waits for the request to complete, and returns the result.
2186 * @see #sendRequestAsync
2187 */
2188 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2189 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002190 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002191 }
2192
2193 /**
2194 * Posts the specified command to be executed on the main thread,
2195 * waits for the request to complete, and returns the result.
2196 * @see #sendRequestAsync
2197 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002198 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002199 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2200 }
2201
2202 /**
2203 * Posts the specified command to be executed on the main thread,
2204 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2205 * if not timeout or null otherwise.
2206 * @see #sendRequestAsync
2207 */
2208 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2209 long timeoutInMs) {
2210 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002211 }
2212
2213 /**
2214 * Posts the specified command to be executed on the main thread,
2215 * waits for the request to complete, and returns the result.
2216 * @see #sendRequestAsync
2217 */
Nathan Harold92bed182018-10-12 18:16:49 -07002218 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002219 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002220 }
2221
2222 /**
2223 * Posts the specified command to be executed on the main thread,
2224 * waits for the request to complete, and returns the result.
2225 * @see #sendRequestAsync
2226 */
2227 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002228 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2229 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002230 }
2231
2232 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002233 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2234 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2235 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002236 * @see #sendRequestAsync
2237 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002238 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2239 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2241 throw new RuntimeException("This method will deadlock if called from the main thread.");
2242 }
2243
Nathan Harold92bed182018-10-12 18:16:49 -07002244 MainThreadRequest request = null;
2245 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2246 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2247 } else if (phone != null) {
2248 request = new MainThreadRequest(argument, phone, workSource);
2249 } else {
2250 request = new MainThreadRequest(argument, subId, workSource);
2251 }
2252
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 Message msg = mMainThreadHandler.obtainMessage(command, request);
2254 msg.sendToTarget();
2255
Rambo Wang0f050d82021-02-12 11:43:36 -08002256
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002258 if (timeoutInMs >= 0) {
2259 // Wait for at least timeoutInMs before returning null request result
2260 long now = SystemClock.elapsedRealtime();
2261 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002262 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002263 try {
2264 request.wait(deadline - now);
2265 } catch (InterruptedException e) {
2266 // Do nothing, go back and check if request is completed or timeout
2267 } finally {
2268 now = SystemClock.elapsedRealtime();
2269 }
2270 }
2271 } else {
2272 // Wait for the request to complete
2273 while (request.result == null) {
2274 try {
2275 request.wait();
2276 } catch (InterruptedException e) {
2277 // Do nothing, go back and wait until the request is complete
2278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280 }
2281 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002282 if (request.result == null) {
2283 Log.wtf(LOG_TAG,
2284 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 return request.result;
2287 }
2288
2289 /**
2290 * Asynchronous ("fire and forget") version of sendRequest():
2291 * Posts the specified command to be executed on the main thread, and
2292 * returns immediately.
2293 * @see #sendRequest
2294 */
2295 private void sendRequestAsync(int command) {
2296 mMainThreadHandler.sendEmptyMessage(command);
2297 }
2298
2299 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002300 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002301 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002302 */
2303 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002304 sendRequestAsync(command, argument, null, null);
2305 }
2306
2307 /**
2308 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2309 * @see {@link #sendRequest(int,Object)}
2310 */
2311 private void sendRequestAsync(
2312 int command, Object argument, Phone phone, WorkSource workSource) {
2313 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002314 Message msg = mMainThreadHandler.obtainMessage(command, request);
2315 msg.sendToTarget();
2316 }
2317
2318 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 * Initialize the singleton PhoneInterfaceManager instance.
2320 * This is only done once, at startup, from PhoneApp.onCreate().
2321 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002322 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 synchronized (PhoneInterfaceManager.class) {
2324 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002325 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 } else {
2327 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2328 }
2329 return sInstance;
2330 }
2331 }
2332
2333 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002334 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002337 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002338 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002340 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002342 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002343 mTelephonySharedPreferences =
2344 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002345 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002346 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002347 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002348 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002349 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002350 mTelephony2gUpdater = new Telephony2gUpdater(
2351 Executors.newSingleThreadExecutor(), mApp);
2352 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 publish();
2354 }
2355
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002356 private Phone getDefaultPhone() {
2357 Phone thePhone = getPhone(getDefaultSubscription());
2358 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2359 }
2360
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 private void publish() {
2362 if (DBG) log("publish: " + this);
2363
Peter Wangc035ce42020-01-08 21:00:22 -08002364 TelephonyFrameworkInitializer
2365 .getTelephonyServiceManager()
2366 .getTelephonyServiceRegisterer()
2367 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 }
2369
Stuart Scott584921c2015-01-15 17:10:34 -08002370 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002371 if (request.phone != null) {
2372 return request.phone;
2373 } else {
2374 return getPhoneFromSubId(request.subId);
2375 }
2376 }
2377
2378 private Phone getPhoneFromSubId(int subId) {
2379 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2380 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002381 }
2382
Rambo Wange53e07d2022-05-10 13:01:13 -07002383 @Nullable
2384 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002385 Phone phone = getPhoneFromRequest(request);
2386 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002387 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002388 }
2389
Wink Saville36469e72014-06-11 15:17:00 -07002390 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002391 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002392 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394
Kai Shif70f46f2021-03-03 13:59:46 -08002395 private void sendEraseModemConfig(@NonNull Phone phone) {
2396 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2397 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2398 }
2399
2400 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2401 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2402 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002403 }
2404
Peter Wang44b186e2020-01-13 23:33:09 -08002405 private boolean isImsAvailableOnDevice() {
2406 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2407 if (pm == null) {
2408 // For some reason package manger is not available.. This will fail internally anyway,
2409 // so do not throw error and allow.
2410 return true;
2411 }
2412 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2413 }
2414
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002416 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002417 }
2418
Wink Savilleb564aae2014-10-23 10:18:09 -07002419 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 if (DBG) log("dial: " + number);
2421 // No permission check needed here: This is just a wrapper around the
2422 // ACTION_DIAL intent, which is available to any app since it puts up
2423 // the UI before it does anything.
2424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002425 final long identity = Binder.clearCallingIdentity();
2426 try {
2427 String url = createTelUrl(number);
2428 if (url == null) {
2429 return;
2430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002432 // PENDING: should we just silently fail if phone is offhook or ringing?
2433 PhoneConstants.State state = mCM.getState(subId);
2434 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2435 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2436 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2437 mApp.startActivity(intent);
2438 }
2439 } finally {
2440 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 }
2442 }
2443
2444 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002445 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002446 }
2447
Wink Savilleb564aae2014-10-23 10:18:09 -07002448 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 if (DBG) log("call: " + number);
2450
2451 // This is just a wrapper around the ACTION_CALL intent, but we still
2452 // need to do a permission check since we're calling startActivity()
2453 // from the context of the phone app.
2454 enforceCallPermission();
2455
Jordan Liu1617b712019-07-10 15:06:26 -07002456 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 != AppOpsManager.MODE_ALLOWED) {
2458 return;
2459 }
2460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002461 final long identity = Binder.clearCallingIdentity();
2462 try {
2463 String url = createTelUrl(number);
2464 if (url == null) {
2465 return;
2466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002468 boolean isValid = false;
2469 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2470 if (slist != null) {
2471 for (SubscriptionInfo subInfoRecord : slist) {
2472 if (subInfoRecord.getSubscriptionId() == subId) {
2473 isValid = true;
2474 break;
2475 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002476 }
Wink Saville08874612014-08-31 19:19:58 -07002477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 if (!isValid) {
2479 return;
2480 }
Wink Saville08874612014-08-31 19:19:58 -07002481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2483 intent.putExtra(SUBSCRIPTION_KEY, subId);
2484 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2485 mApp.startActivity(intent);
2486 } finally {
2487 Binder.restoreCallingIdentity(identity);
2488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
2490
Wink Savilleb564aae2014-10-23 10:18:09 -07002491 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002492 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002493 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2494 }
2495
Wink Savilleb564aae2014-10-23 10:18:09 -07002496 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002497 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002498 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2499 }
2500
Wink Savilleb564aae2014-10-23 10:18:09 -07002501 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002506 Phone phone = getPhone(subId);
2507 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 checkSimPin.start();
2509 return checkSimPin.unlockSim(null, pin);
2510 } finally {
2511 Binder.restoreCallingIdentity(identity);
2512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 }
2514
Wink Savilleb564aae2014-10-23 10:18:09 -07002515 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002517
2518 final long identity = Binder.clearCallingIdentity();
2519 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002520 Phone phone = getPhone(subId);
2521 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002522 checkSimPuk.start();
2523 return checkSimPuk.unlockSim(puk, pin);
2524 } finally {
2525 Binder.restoreCallingIdentity(identity);
2526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 }
2528
2529 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002530 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 * a synchronous one.
2532 */
2533 private static class UnlockSim extends Thread {
2534
2535 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002536 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537
2538 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002539 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2540 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541
2542 // For replies from SimCard interface
2543 private Handler mHandler;
2544
2545 // For async handler to identify request type
2546 private static final int SUPPLY_PIN_COMPLETE = 100;
2547
Michele Berionne5e411512020-11-13 02:36:59 +00002548 UnlockSim(int phoneId, IccCard simCard) {
2549 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 mSimCard = simCard;
2551 }
2552
2553 @Override
2554 public void run() {
2555 Looper.prepare();
2556 synchronized (UnlockSim.this) {
2557 mHandler = new Handler() {
2558 @Override
2559 public void handleMessage(Message msg) {
2560 AsyncResult ar = (AsyncResult) msg.obj;
2561 switch (msg.what) {
2562 case SUPPLY_PIN_COMPLETE:
2563 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2564 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002565 mRetryCount = msg.arg1;
2566 if (ar.exception != null) {
2567 if (ar.exception instanceof CommandException &&
2568 ((CommandException)(ar.exception)).getCommandError()
2569 == CommandException.Error.PASSWORD_INCORRECT) {
2570 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002571 } //When UiccCardApp dispose,handle message and return exception
2572 else if (ar.exception instanceof CommandException &&
2573 ((CommandException) (ar.exception)).getCommandError()
2574 == CommandException.Error.ABORTED) {
2575 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002576 } else {
2577 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2578 }
2579 } else {
2580 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 mDone = true;
2583 UnlockSim.this.notifyAll();
2584 }
2585 break;
2586 }
2587 }
2588 };
2589 UnlockSim.this.notifyAll();
2590 }
2591 Looper.loop();
2592 }
2593
2594 /*
2595 * Use PIN or PUK to unlock SIM card
2596 *
2597 * If PUK is null, unlock SIM card with PIN
2598 *
2599 * If PUK is not null, unlock SIM card with PUK and set PIN code
2600 */
Wink Saville9de0f752013-10-22 19:04:03 -07002601 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602
2603 while (mHandler == null) {
2604 try {
2605 wait();
2606 } catch (InterruptedException e) {
2607 Thread.currentThread().interrupt();
2608 }
2609 }
2610 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2611
2612 if (puk == null) {
2613 mSimCard.supplyPin(pin, callback);
2614 } else {
2615 mSimCard.supplyPuk(puk, pin, callback);
2616 }
2617
2618 while (!mDone) {
2619 try {
2620 Log.d(LOG_TAG, "wait for done");
2621 wait();
2622 } catch (InterruptedException e) {
2623 // Restore the interrupted status
2624 Thread.currentThread().interrupt();
2625 }
2626 }
2627 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002628 int[] resultArray = new int[2];
2629 resultArray[0] = mResult;
2630 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002631
2632 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002633 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002634 }
2635
Wink Saville9de0f752013-10-22 19:04:03 -07002636 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002637 }
2638 }
2639
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002640 /**
2641 * This method has been removed due to privacy and stability concerns.
2642 */
2643 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002644 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002645 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2646 return;
Wink Saville36469e72014-06-11 15:17:00 -07002647 }
2648
Nathan Harold1f889d82020-06-04 17:05:26 -07002649 @Override
2650 public void updateServiceLocationWithPackageName(String callingPackage) {
2651 mApp.getSystemService(AppOpsManager.class)
2652 .checkPackage(Binder.getCallingUid(), callingPackage);
2653
Nathan Haroldf096d982020-11-18 17:18:06 -08002654 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002655 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2656 // Callers targeting S have no business invoking this method.
2657 return;
2658 }
2659
2660 LocationAccessPolicy.LocationPermissionResult locationResult =
2661 LocationAccessPolicy.checkLocationPermission(mApp,
2662 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2663 .setCallingPackage(callingPackage)
2664 .setCallingFeatureId(null)
2665 .setCallingPid(Binder.getCallingPid())
2666 .setCallingUid(Binder.getCallingUid())
2667 .setMethod("updateServiceLocation")
2668 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2669 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2670 .build());
2671 // Apps that lack location permission have no business calling this method;
2672 // however, because no permission was declared in the public API, denials must
2673 // all be "soft".
2674 switch (locationResult) {
2675 case DENIED_HARD: /* fall through */
2676 case DENIED_SOFT:
2677 return;
2678 }
2679
2680 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 final long identity = Binder.clearCallingIdentity();
2682 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002683 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002685 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 }
2687 } finally {
2688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 }
2691
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002692 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002693 @Override
2694 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002695 return isRadioOnWithFeature(callingPackage, null);
2696 }
2697
2698
2699 @Override
2700 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2701 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2702 callingFeatureId);
2703 }
2704
2705 @Deprecated
2706 @Override
2707 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2708 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002709 }
2710
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002711 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002712 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2713 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002715 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002716 return false;
2717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718
2719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 return isRadioOnForSubscriber(subId);
2722 } finally {
2723 Binder.restoreCallingIdentity(identity);
2724 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002725 }
2726
2727 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002728 final long identity = Binder.clearCallingIdentity();
2729 try {
2730 final Phone phone = getPhone(subId);
2731 if (phone != null) {
2732 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2733 } else {
2734 return false;
2735 }
2736 } finally {
2737 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 }
2740
2741 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002742 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 }
Wink Saville36469e72014-06-11 15:17:00 -07002744
Wink Savilleb564aae2014-10-23 10:18:09 -07002745 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 final Phone phone = getPhone(subId);
2751 if (phone != null) {
2752 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2753 }
2754 } finally {
2755 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002756 }
Wink Saville36469e72014-06-11 15:17:00 -07002757 }
2758
2759 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002760 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002761 }
2762
Wink Savilleb564aae2014-10-23 10:18:09 -07002763 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002764 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765
2766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 final Phone phone = getPhone(subId);
2769 if (phone == null) {
2770 return false;
2771 }
2772 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2773 toggleRadioOnOffForSubscriber(subId);
2774 }
2775 return true;
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
Wink Saville36469e72014-06-11 15:17:00 -07002780
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002781 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002782 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002783 /*
2784 * If any of the Radios are available, it will need to be
2785 * shutdown. So return true if any Radio is available.
2786 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 final long identity = Binder.clearCallingIdentity();
2788 try {
2789 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2790 Phone phone = PhoneFactory.getPhone(i);
2791 if (phone != null && phone.isRadioAvailable()) return true;
2792 }
2793 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2794 return false;
2795 } finally {
2796 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002797 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002798 }
2799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002801 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802 enforceModifyPermission();
2803
2804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2807 logv("Shutting down Phone " + i);
2808 shutdownRadioUsingPhoneId(i);
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002812 }
2813 }
2814
2815 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002816 Phone phone = PhoneFactory.getPhone(phoneId);
2817 if (phone != null && phone.isRadioAvailable()) {
2818 phone.shutdownRadio();
2819 }
2820 }
2821
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002822 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002823 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824
2825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2828 if (defaultPhone != null) {
2829 defaultPhone.setRadioPower(turnOn);
2830 return true;
2831 } else {
2832 loge("There's no default phone.");
2833 return false;
2834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002837 }
Wink Saville36469e72014-06-11 15:17:00 -07002838 }
2839
Wink Savilleb564aae2014-10-23 10:18:09 -07002840 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842
2843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 final Phone phone = getPhone(subId);
2846 if (phone != null) {
2847 phone.setRadioPower(turnOn);
2848 return true;
2849 } else {
2850 return false;
2851 }
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002854 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 }
2856
Wink Saville36469e72014-06-11 15:17:00 -07002857 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002859 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002861
2862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 int subId = mSubscriptionController.getDefaultDataSubId();
2865 final Phone phone = getPhone(subId);
2866 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002867 phone.getDataSettingsManager().setDataEnabled(
2868 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869 return true;
2870 } else {
2871 return false;
2872 }
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 }
2877
Wink Saville36469e72014-06-11 15:17:00 -07002878 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002879 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002880 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882
2883 final long identity = Binder.clearCallingIdentity();
2884 try {
2885 int subId = mSubscriptionController.getDefaultDataSubId();
2886 final Phone phone = getPhone(subId);
2887 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002888 phone.getDataSettingsManager().setDataEnabled(
2889 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 return true;
2891 } else {
2892 return false;
2893 }
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 }
2898
Sanket Padawe356d7632015-06-22 14:03:32 -07002899 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002900 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 final Phone phone = getPhone(subId);
2904 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002905 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 } else {
2907 return false;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
2914 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002915 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002916 }
2917
pkanwarae03a6b2016-11-06 20:37:09 -08002918 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919 enforceCallPermission();
2920
2921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2924 return;
2925 }
2926 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2927 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
2930 }
pkanwar32d516d2016-10-14 19:37:38 -07002931 };
2932
Wink Savilleb564aae2014-10-23 10:18:09 -07002933 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935
2936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2939 return false;
2940 }
2941 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945 }
2946
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002947 /**
2948 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2949 * tag on getCallState Binder call.
2950 */
2951 @Deprecated
2952 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002954 if (CompatChanges.isChangeEnabled(
2955 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2956 Binder.getCallingUid())) {
2957 // Do not allow this API to be called on API version 31+, it should only be
2958 // called on old apps using this Binder call directly.
2959 throw new SecurityException("This method can only be used for applications "
2960 + "targeting API version 30 or less.");
2961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962 final long identity = Binder.clearCallingIdentity();
2963 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002964 Phone phone = getPhone(getDefaultSubscription());
2965 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2966 PhoneConstantConversions.convertCallState(phone.getState());
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 @Override
2973 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2974 if (CompatChanges.isChangeEnabled(
2975 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2976 Binder.getCallingUid())) {
2977 // Check READ_PHONE_STATE for API version 31+
2978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2979 featureId, "getCallStateForSubscription")) {
2980 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2981 + "targeting API level 31+.");
2982 }
2983 }
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2988 PhoneConstantConversions.convertCallState(phone.getState());
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002992 }
2993
Sanket Padawe356d7632015-06-22 14:03:32 -07002994 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002995 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002996 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2997 }
2998
2999 @Override
3000 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 final long identity = Binder.clearCallingIdentity();
3002 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003003 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07003005 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006 } else {
3007 return PhoneConstantConversions.convertDataState(
3008 PhoneConstants.DataState.DISCONNECTED);
3009 }
3010 } finally {
3011 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003013 }
3014
Sanket Padawe356d7632015-06-22 14:03:32 -07003015 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003016 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003017 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3018 }
3019
3020 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003021 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 final long identity = Binder.clearCallingIdentity();
3023 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003024 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003026 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003027 } else {
3028 return TelephonyManager.DATA_ACTIVITY_NONE;
3029 }
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003032 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003033 }
3034
3035 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003036 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003037 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003038 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003039
3040 LocationAccessPolicy.LocationPermissionResult locationResult =
3041 LocationAccessPolicy.checkLocationPermission(mApp,
3042 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3043 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003044 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003045 .setCallingPid(Binder.getCallingPid())
3046 .setCallingUid(Binder.getCallingUid())
3047 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003048 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003049 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3050 .build());
3051 switch (locationResult) {
3052 case DENIED_HARD:
3053 throw new SecurityException("Not allowed to access cell location");
3054 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003055 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3056 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057 }
3058
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003059 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003063 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003064 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
Svetoslav64fad262015-04-14 14:35:21 -07003068 }
3069
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003070 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003071 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003072 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3073 // registered cell info, so return a NULL country instead.
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003076 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3077 // Get default phone in this case.
3078 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3079 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003080 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003082 if (phone == null) return "";
3083 ServiceStateTracker sst = phone.getServiceStateTracker();
3084 if (sst == null) return "";
3085 LocaleTracker lt = sst.getLocaleTracker();
3086 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003087 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003091 }
3092
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003093 /**
3094 * This method was removed due to potential issues caused by performing partial
3095 * updates of service state, and lack of a credible use case.
3096 *
3097 * This has the ability to break the telephony implementation by disabling notification of
3098 * changes in device connectivity. DO NOT USE THIS!
3099 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003100 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003101 public void enableLocationUpdates() {
3102 mApp.enforceCallingOrSelfPermission(
3103 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 }
3105
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003106 /**
3107 * This method was removed due to potential issues caused by performing partial
3108 * updates of service state, and lack of a credible use case.
3109 *
3110 * This has the ability to break the telephony implementation by disabling notification of
3111 * changes in device connectivity. DO NOT USE THIS!
3112 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003113 @Override
3114 public void disableLocationUpdates() {
3115 mApp.enforceCallingOrSelfPermission(
3116 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 }
3118
3119 @Override
3120 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003121 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3122 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003123 try {
3124 mApp.getSystemService(AppOpsManager.class)
3125 .checkPackage(Binder.getCallingUid(), callingPackage);
3126 } catch (SecurityException e) {
3127 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3128 throw e;
3129 }
3130
Nathan Haroldf096d982020-11-18 17:18:06 -08003131 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003132 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3133 throw new SecurityException(
3134 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3135 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003136
Jordan Liu1617b712019-07-10 15:06:26 -07003137 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003138 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3139 return null;
3140 }
Svetoslav64fad262015-04-14 14:35:21 -07003141
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003142 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003144 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003145 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146
Nathan Haroldf180aac2018-06-01 18:43:55 -07003147 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3148 for (CellInfo ci : info) {
3149 if (ci instanceof CellInfoGsm) {
3150 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3151 } else if (ci instanceof CellInfoWcdma) {
3152 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003154 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003155 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003156 }
3157
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003158 private List<CellInfo> getCachedCellInfo() {
3159 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3160 for (Phone phone : PhoneFactory.getPhones()) {
3161 List<CellInfo> info = phone.getAllCellInfo();
3162 if (info != null) cellInfos.addAll(info);
3163 }
3164 return cellInfos;
3165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003166
3167 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003168 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003169 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003170 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003171
3172 LocationAccessPolicy.LocationPermissionResult locationResult =
3173 LocationAccessPolicy.checkLocationPermission(mApp,
3174 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3175 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003176 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003177 .setCallingPid(Binder.getCallingPid())
3178 .setCallingUid(Binder.getCallingUid())
3179 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003180 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003181 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3182 .build());
3183 switch (locationResult) {
3184 case DENIED_HARD:
3185 throw new SecurityException("Not allowed to access cell info");
3186 case DENIED_SOFT:
3187 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003188 }
3189
Nathan Haroldf096d982020-11-18 17:18:06 -08003190 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003191 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3192 return getCachedCellInfo();
3193 }
3194
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003195 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003196 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197 final long identity = Binder.clearCallingIdentity();
3198 try {
3199 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3200 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003201 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003202 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 if (info != null) cellInfos.addAll(info);
3204 }
3205 return cellInfos;
3206 } finally {
3207 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 }
3209 }
3210
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003211 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003212 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3213 String callingFeatureId) {
3214 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3215 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003216 }
3217
3218 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003219 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3220 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003221 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003222 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003223 }
3224
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003225 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3226 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003227 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003228 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003229
3230 LocationAccessPolicy.LocationPermissionResult locationResult =
3231 LocationAccessPolicy.checkLocationPermission(mApp,
3232 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3233 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003234 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003235 .setCallingPid(Binder.getCallingPid())
3236 .setCallingUid(Binder.getCallingUid())
3237 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003238 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3239 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003240 .build());
3241 switch (locationResult) {
3242 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003243 if (TelephonyPermissions
3244 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003245 // Safetynet logging for b/154934934
3246 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3247 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003248 throw new SecurityException("Not allowed to access cell info");
3249 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003250 if (TelephonyPermissions
3251 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003252 // Safetynet logging for b/154934934
3253 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3254 }
Nathan Harold5320c422019-05-09 10:26:08 -07003255 try {
3256 cb.onCellInfo(new ArrayList<CellInfo>());
3257 } catch (RemoteException re) {
3258 // Drop without consequences
3259 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003260 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003261 }
3262
Nathan Harolda939a962019-05-09 10:13:47 -07003263
3264 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003265 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3266
3267 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3268 }
3269
3270 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003271 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003272 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003273 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274
3275 final long identity = Binder.clearCallingIdentity();
3276 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003277 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278 } finally {
3279 Binder.restoreCallingIdentity(identity);
3280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003281 }
3282
Shishir Agrawala9f32182016-04-12 12:00:16 -07003283 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003284 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003285 Phone phone = PhoneFactory.getPhone(slotIndex);
3286 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003287 return null;
3288 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003289 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003290 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003291 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003292 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003293 return null;
3294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003295
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 return phone.getImei();
3299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003302 }
3303
3304 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003305 public String getTypeAllocationCodeForSlot(int slotIndex) {
3306 Phone phone = PhoneFactory.getPhone(slotIndex);
3307 String tac = null;
3308 if (phone != null) {
3309 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003310 try {
3311 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3312 } catch (IndexOutOfBoundsException e) {
3313 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3314 return null;
3315 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003316 }
3317 return tac;
3318 }
3319
3320 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003321 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003322 try {
3323 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3324 } catch (SecurityException se) {
3325 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3326 throw new SecurityException("Package " + callingPackage + " does not belong to "
3327 + Binder.getCallingUid());
3328 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003329 Phone phone = PhoneFactory.getPhone(slotIndex);
3330 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003331 return null;
3332 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003333
Jeff Davidson913390f2018-02-23 17:11:49 -08003334 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003335 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003336 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003337 return null;
3338 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339
3340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 return phone.getMeid();
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
Jack Yu2af8d712017-03-15 17:14:14 -07003346 }
3347
3348 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003349 public String getManufacturerCodeForSlot(int slotIndex) {
3350 Phone phone = PhoneFactory.getPhone(slotIndex);
3351 String manufacturerCode = null;
3352 if (phone != null) {
3353 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003354 try {
3355 manufacturerCode =
3356 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3357 } catch (IndexOutOfBoundsException e) {
3358 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3359 return null;
3360 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003361 }
3362 return manufacturerCode;
3363 }
3364
3365 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003366 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3367 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003368 Phone phone = PhoneFactory.getPhone(slotIndex);
3369 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003370 return null;
3371 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003372 int subId = phone.getSubId();
3373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003374 mApp, subId, callingPackage, callingFeatureId,
3375 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003376 return null;
3377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 return phone.getDeviceSvn();
3382 } finally {
3383 Binder.restoreCallingIdentity(identity);
3384 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003385 }
3386
fionaxu43304da2017-11-27 22:51:16 -08003387 @Override
3388 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 final Phone phone = getPhone(subId);
3392 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3393 } finally {
3394 Binder.restoreCallingIdentity(identity);
3395 }
fionaxu43304da2017-11-27 22:51:16 -08003396 }
3397
3398 @Override
3399 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 final Phone phone = getPhone(subId);
3403 return phone == null ? null : phone.getCarrierName();
3404 } finally {
3405 Binder.restoreCallingIdentity(identity);
3406 }
fionaxu43304da2017-11-27 22:51:16 -08003407 }
3408
calvinpanffe225e2018-11-01 19:43:06 +08003409 @Override
chen xu0026ca62019-03-06 15:28:50 -08003410 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003411 final long identity = Binder.clearCallingIdentity();
3412 try {
3413 final Phone phone = getPhone(subId);
3414 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003415 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003416 } finally {
3417 Binder.restoreCallingIdentity(identity);
3418 }
3419 }
3420
3421 @Override
chen xu0026ca62019-03-06 15:28:50 -08003422 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003423 final long identity = Binder.clearCallingIdentity();
3424 try {
3425 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003426 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
3430 }
3431
chen xu651eec72018-11-11 19:03:44 -08003432 @Override
chen xu864e11c2018-12-06 22:10:03 -08003433 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3434 if (!isSubscriptionMccMnc) {
3435 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3436 }
chen xu651eec72018-11-11 19:03:44 -08003437 final Phone phone = PhoneFactory.getPhone(slotIndex);
3438 if (phone == null) {
3439 return TelephonyManager.UNKNOWN_CARRIER_ID;
3440 }
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
3446 }
3447 }
3448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003449 //
3450 // Internal helper methods.
3451 //
3452
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003453 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003454 * Make sure the caller is the calling package itself
3455 *
3456 * @throws SecurityException if the caller is not the calling package
3457 */
3458 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3459 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003460 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3461 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003462 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003463 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003464 } catch (PackageManager.NameNotFoundException e) {
3465 // packageUid is -1
3466 }
3467 if (packageUid != callingUid) {
3468 throw new SecurityException(message + ": Package " + callingPackage
3469 + " does not belong to " + callingUid);
3470 }
3471 }
3472
3473 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003474 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3475 *
3476 * @throws SecurityException if the caller does not have the required permission
3477 */
3478 private void enforceModifyPermission() {
3479 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3480 }
3481
Shuo Qian3b6ee772019-11-13 17:43:31 -08003482 private void enforceActiveEmergencySessionPermission() {
3483 mApp.enforceCallingOrSelfPermission(
3484 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3485 }
3486
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003487 /**
3488 * Make sure the caller has the CALL_PHONE permission.
3489 *
3490 * @throws SecurityException if the caller does not have the required permission
3491 */
3492 private void enforceCallPermission() {
3493 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3494 }
3495
paulhu5a773602019-08-23 19:17:33 +08003496 private void enforceSettingsPermission() {
3497 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003498 }
3499
Michele Berionne5e411512020-11-13 02:36:59 +00003500 private void enforceRebootPermission() {
3501 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3502 }
3503
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003504 private String createTelUrl(String number) {
3505 if (TextUtils.isEmpty(number)) {
3506 return null;
3507 }
3508
Jake Hambye994d462014-02-03 13:10:13 -08003509 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003510 }
3511
Ihab Awadf9e92732013-12-05 18:02:52 -08003512 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003513 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3514 }
3515
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003516 private static void logv(String msg) {
3517 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3518 }
3519
Ihab Awadf9e92732013-12-05 18:02:52 -08003520 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3522 }
3523
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003524 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003526 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003527 }
3528
Sanket Padawe356d7632015-06-22 14:03:32 -07003529 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003530 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 final Phone phone = PhoneFactory.getPhone(slotIndex);
3534 if (phone == null) {
3535 return PhoneConstants.PHONE_TYPE_NONE;
3536 } else {
3537 return phone.getPhoneType();
3538 }
3539 } finally {
3540 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003542 }
3543
3544 /**
3545 * Returns the CDMA ERI icon index to display
3546 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003547 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003548 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3549 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3550 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003551 }
3552
Sanket Padawe356d7632015-06-22 14:03:32 -07003553 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003554 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3555 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003557 mApp, subId, callingPackage, callingFeatureId,
3558 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003559 return -1;
3560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003561
3562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 final Phone phone = getPhone(subId);
3565 if (phone != null) {
3566 return phone.getCdmaEriIconIndex();
3567 } else {
3568 return -1;
3569 }
3570 } finally {
3571 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003573 }
3574
3575 /**
3576 * Returns the CDMA ERI icon mode,
3577 * 0 - ON
3578 * 1 - FLASHING
3579 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003580 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003581 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3582 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3583 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003584 }
3585
Sanket Padawe356d7632015-06-22 14:03:32 -07003586 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003587 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3588 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003590 mApp, subId, callingPackage, callingFeatureId,
3591 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003592 return -1;
3593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003594
3595 final long identity = Binder.clearCallingIdentity();
3596 try {
3597 final Phone phone = getPhone(subId);
3598 if (phone != null) {
3599 return phone.getCdmaEriIconMode();
3600 } else {
3601 return -1;
3602 }
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003606 }
3607
3608 /**
3609 * Returns the CDMA ERI text,
3610 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003611 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003612 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3613 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3614 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003615 }
3616
Sanket Padawe356d7632015-06-22 14:03:32 -07003617 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003618 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3619 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003620 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003621 mApp, subId, callingPackage, callingFeatureId,
3622 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003623 return null;
3624 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003625
3626 final long identity = Binder.clearCallingIdentity();
3627 try {
3628 final Phone phone = getPhone(subId);
3629 if (phone != null) {
3630 return phone.getCdmaEriText();
3631 } else {
3632 return null;
3633 }
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003637 }
3638
3639 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003640 * Returns the CDMA MDN.
3641 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003642 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003643 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3645 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646
3647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003650 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003651 return phone.getLine1Number();
3652 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003653 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 return null;
3655 }
3656 } finally {
3657 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003658 }
3659 }
3660
3661 /**
3662 * Returns the CDMA MIN.
3663 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003664 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003665 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3667 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668
3669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 final Phone phone = getPhone(subId);
3672 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3673 return phone.getCdmaMin();
3674 } else {
3675 return null;
3676 }
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003679 }
3680 }
3681
Hall Liud892bec2018-11-30 14:51:45 -08003682 @Override
3683 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3684 INumberVerificationCallback callback, String callingPackage) {
3685 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3686 != PERMISSION_GRANTED) {
3687 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3688 }
3689 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3690
3691 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3692 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003693 throw new SecurityException("Calling package must be configured in the device config: "
3694 + "calling package: " + callingPackage
3695 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003696 }
3697
3698 if (range == null) {
3699 throw new NullPointerException("Range must be non-null");
3700 }
3701
3702 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003703 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003704
3705 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3706 }
3707
Junda Liuca05d5d2014-08-14 22:36:34 -07003708 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003709 * Returns true if CDMA provisioning needs to run.
3710 */
3711 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003712 final long identity = Binder.clearCallingIdentity();
3713 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003714 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003715 } finally {
3716 Binder.restoreCallingIdentity(identity);
3717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003718 }
3719
3720 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003721 * Sets the voice mail number of a given subId.
3722 */
3723 @Override
3724 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003725 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3726 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727
3728 final long identity = Binder.clearCallingIdentity();
3729 try {
3730 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3731 new Pair<String, String>(alphaTag, number), new Integer(subId));
3732 return success;
3733 } finally {
3734 Binder.restoreCallingIdentity(identity);
3735 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003736 }
3737
Ta-wei Yen87c49842016-05-13 21:19:52 -07003738 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003739 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3740 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003741 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3742 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003743 if (!TextUtils.equals(callingPackage, systemDialer)) {
3744 throw new SecurityException("caller must be system dialer");
3745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746
3747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3750 if (phoneAccountHandle == null) {
3751 return null;
3752 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003753 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003754 } finally {
3755 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003756 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003757 }
3758
3759 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003760 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3761 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003762 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003764 mApp, subId, callingPackage, callingFeatureId,
3765 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003766 return null;
3767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003769 final long identity = Binder.clearCallingIdentity();
3770 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003771 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003772 } finally {
3773 Binder.restoreCallingIdentity(identity);
3774 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003775 }
3776
3777 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003778 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3779 VisualVoicemailSmsFilterSettings settings) {
3780 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003781
3782 final long identity = Binder.clearCallingIdentity();
3783 try {
3784 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003785 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786 } finally {
3787 Binder.restoreCallingIdentity(identity);
3788 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003789 }
3790
3791 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003792 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3793 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794
3795 final long identity = Binder.clearCallingIdentity();
3796 try {
3797 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003798 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799 } finally {
3800 Binder.restoreCallingIdentity(identity);
3801 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003802 }
3803
3804 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003805 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3806 String callingPackage, int subId) {
3807 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808
3809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003812 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 } finally {
3814 Binder.restoreCallingIdentity(identity);
3815 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003816 }
3817
3818 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003819 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003820 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821
3822 final long identity = Binder.clearCallingIdentity();
3823 try {
3824 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003825 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826 } finally {
3827 Binder.restoreCallingIdentity(identity);
3828 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003829 }
3830
3831 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003832 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3833 String callingAttributionTag, int subId, String number, int port, String text,
3834 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003835 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003836 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003837 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003838 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003839 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3840 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003841 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003842
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003843 /**
fionaxu0152e512016-11-14 13:36:14 -08003844 * Sets the voice activation state of a given subId.
3845 */
3846 @Override
3847 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3849 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003850
3851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 final Phone phone = getPhone(subId);
3854 if (phone != null) {
3855 phone.setVoiceActivationState(activationState);
3856 } else {
3857 loge("setVoiceActivationState fails with invalid subId: " + subId);
3858 }
3859 } finally {
3860 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003861 }
3862 }
3863
3864 /**
3865 * Sets the data activation state of a given subId.
3866 */
3867 @Override
3868 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3870 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871
3872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 final Phone phone = getPhone(subId);
3875 if (phone != null) {
3876 phone.setDataActivationState(activationState);
3877 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003878 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003879 }
3880 } finally {
3881 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003882 }
3883 }
3884
3885 /**
3886 * Returns the voice activation state of a given subId.
3887 */
3888 @Override
3889 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003890 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891
fionaxu0152e512016-11-14 13:36:14 -08003892 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 if (phone != null) {
3896 return phone.getVoiceActivationState();
3897 } else {
3898 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3899 }
3900 } finally {
3901 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003902 }
3903 }
3904
3905 /**
3906 * Returns the data activation state of a given subId.
3907 */
3908 @Override
3909 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003911
fionaxu0152e512016-11-14 13:36:14 -08003912 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 if (phone != null) {
3916 return phone.getDataActivationState();
3917 } else {
3918 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3919 }
3920 } finally {
3921 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003922 }
3923 }
3924
3925 /**
Wink Saville36469e72014-06-11 15:17:00 -07003926 * Returns the unread count of voicemails for a subId
3927 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003928 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003929 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3930 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003931 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003932 mApp, subId, callingPackage, callingFeatureId,
3933 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003934 return 0;
3935 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003936 final long identity = Binder.clearCallingIdentity();
3937 try {
3938 final Phone phone = getPhone(subId);
3939 if (phone != null) {
3940 return phone.getVoiceMessageCount();
3941 } else {
3942 return 0;
3943 }
3944 } finally {
3945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003947 }
3948
3949 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003950 * returns true, if the device is in a state where both voice and data
3951 * are supported simultaneously. This can change based on location or network condition.
3952 */
3953 @Override
3954 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 final Phone phone = getPhone(subId);
3958 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3959 } finally {
3960 Binder.restoreCallingIdentity(identity);
3961 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003962 }
3963
3964 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003965 * Send the dialer code if called from the current default dialer or the caller has
3966 * carrier privilege.
3967 * @param inputCode The dialer code to send
3968 */
3969 @Override
3970 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003971 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003972 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003973 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3974 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003975 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003976 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003977 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003979
3980 final long identity = Binder.clearCallingIdentity();
3981 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003982 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003983 } finally {
3984 Binder.restoreCallingIdentity(identity);
3985 }
fionaxu235cc5e2017-03-06 22:25:57 -08003986 }
3987
Pengquan Menga1bb6272018-09-06 09:59:22 -07003988 @Override
3989 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003990 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003991 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003992 mApp, subId, "getNetworkSelectionMode");
3993 final long identity = Binder.clearCallingIdentity();
3994 try {
3995 if (!isActiveSubscription(subId)) {
3996 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3997 }
3998 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3999 } finally {
4000 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004001 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004002 }
4003
Brad Ebinger35c841c2018-10-01 10:40:55 -07004004 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004005 public boolean isInEmergencySmsMode() {
4006 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4007 final long identity = Binder.clearCallingIdentity();
4008 try {
4009 for (Phone phone : PhoneFactory.getPhones()) {
4010 if (phone.isInEmergencySmsMode()) {
4011 return true;
4012 }
4013 }
4014 } finally {
4015 Binder.restoreCallingIdentity(identity);
4016 }
4017 return false;
4018 }
4019
shilu366312e2019-12-17 09:28:10 -08004020 /**
4021 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4022 * @param subId The subscription to use to check the configuration.
4023 * @param c The callback that will be used to send the result.
4024 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004025 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004026 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4027 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004028 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004029 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004030
4031 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4032 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4033 "IMS not available on device.");
4034 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 final long token = Binder.clearCallingIdentity();
4036 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004037 int slotId = getSlotIndexOrException(subId);
4038 verifyImsMmTelConfiguredOrThrow(slotId);
4039 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004040 } catch (ImsException e) {
4041 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 } finally {
4043 Binder.restoreCallingIdentity(token);
4044 }
4045 }
4046
shilu366312e2019-12-17 09:28:10 -08004047 /**
4048 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4049 * @param subId The subscription to use to check the configuration.
4050 * @param c The callback that will be used to send the result.
4051 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004053 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004054 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004055 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004056 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4057 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4058 }
Meng Wangafbc5852019-09-19 17:37:13 -07004059 final long token = Binder.clearCallingIdentity();
4060 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004061 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4062 .removeRegistrationCallbackForSubscription(c, subId);
4063 } catch (ImsException e) {
4064 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4065 + "is inactive, ignoring unregister.");
4066 // If the subscription is no longer active, just return, since the callback
4067 // will already have been removed internally.
4068 } finally {
4069 Binder.restoreCallingIdentity(token);
4070 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 }
4072
Brad Ebingera34a6c22019-10-22 17:36:18 -07004073 /**
4074 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4075 */
4076 @Override
4077 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4078 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4079 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4080 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4081 "IMS not available on device.");
4082 }
4083 final long token = Binder.clearCallingIdentity();
4084 try {
4085 Phone phone = getPhone(subId);
4086 if (phone == null) {
4087 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4088 + subId + "'");
4089 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4090 }
4091 phone.getImsRegistrationState(regState -> {
4092 try {
4093 consumer.accept((regState == null)
4094 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4095 } catch (RemoteException e) {
4096 // Ignore if the remote process is no longer available to call back.
4097 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4098 }
4099 });
4100 } finally {
4101 Binder.restoreCallingIdentity(token);
4102 }
4103 }
4104
4105 /**
4106 * Get the transport type for the IMS service registration state.
4107 */
4108 @Override
4109 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004110 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004111 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004112 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4113 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4114 "IMS not available on device.");
4115 }
4116 final long token = Binder.clearCallingIdentity();
4117 try {
4118 Phone phone = getPhone(subId);
4119 if (phone == null) {
4120 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4121 + subId + "'");
4122 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4123 }
4124 phone.getImsRegistrationTech(regTech -> {
4125 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4126 int regTechConverted = (regTech == null)
4127 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4128 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4129 regTechConverted);
4130 try {
4131 consumer.accept(regTechConverted);
4132 } catch (RemoteException e) {
4133 // Ignore if the remote process is no longer available to call back.
4134 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4135 }
4136 });
4137 } finally {
4138 Binder.restoreCallingIdentity(token);
4139 }
4140 }
4141
shilu366312e2019-12-17 09:28:10 -08004142 /**
4143 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4144 * @param subId The subscription to use to check the configuration.
4145 * @param c The callback that will be used to send the result.
4146 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004147 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004148 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4149 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004150 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004151 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004152 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4153 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4154 "IMS not available on device.");
4155 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004156 final long token = Binder.clearCallingIdentity();
4157 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004158 int slotId = getSlotIndexOrException(subId);
4159 verifyImsMmTelConfiguredOrThrow(slotId);
4160 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004161 } catch (ImsException e) {
4162 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004163 } finally {
4164 Binder.restoreCallingIdentity(token);
4165 }
4166 }
4167
shilu366312e2019-12-17 09:28:10 -08004168 /**
4169 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4170 * @param subId The subscription to use to check the configuration.
4171 * @param c The callback that will be used to send the result.
4172 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004174 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004175 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004176 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004177 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4178 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4179 }
Meng Wangafbc5852019-09-19 17:37:13 -07004180
4181 final long token = Binder.clearCallingIdentity();
4182 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004183 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004184 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004185 } catch (ImsException e) {
4186 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4187 + "is inactive, ignoring unregister.");
4188 // If the subscription is no longer active, just return, since the callback
4189 // will already have been removed internally.
4190 } finally {
4191 Binder.restoreCallingIdentity(token);
4192 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004193 }
4194
4195 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004196 public boolean isCapable(int subId, int capability, int regTech) {
4197 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 final long token = Binder.clearCallingIdentity();
4199 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004200 int slotId = getSlotIndexOrException(subId);
4201 verifyImsMmTelConfiguredOrThrow(slotId);
4202 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4203 } catch (com.android.ims.ImsException e) {
4204 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4205 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004206 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004207 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4208 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 } finally {
4210 Binder.restoreCallingIdentity(token);
4211 }
4212 }
4213
4214 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004215 public boolean isAvailable(int subId, int capability, int regTech) {
4216 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 final long token = Binder.clearCallingIdentity();
4218 try {
4219 Phone phone = getPhone(subId);
4220 if (phone == null) return false;
4221 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004222 } catch (com.android.ims.ImsException e) {
4223 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4224 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 } finally {
4226 Binder.restoreCallingIdentity(token);
4227 }
4228 }
4229
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004230 /**
4231 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4232 * subscription.
4233 * @param subId The subscription to use to check the configuration.
4234 * @param callback The callback that will be used to send the result.
4235 * @param capability The MmTelFeature capability that will be used to send the result.
4236 * @param transportType The transport type of the MmTelFeature capability.
4237 */
4238 @Override
4239 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4240 int transportType) {
4241 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004242 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4243 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4244 "IMS not available on device.");
4245 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004246 final long token = Binder.clearCallingIdentity();
4247 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004248 int slotId = getSlotIndex(subId);
4249 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4250 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4251 + subId + "'");
4252 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4253 }
4254 verifyImsMmTelConfiguredOrThrow(slotId);
4255 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4256 transportType, aBoolean -> {
4257 try {
4258 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4259 } catch (RemoteException e) {
4260 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4261 + "running. Ignore");
4262 }
4263 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004264 } catch (ImsException e) {
4265 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004266 } finally {
4267 Binder.restoreCallingIdentity(token);
4268 }
4269 }
4270
shilu366312e2019-12-17 09:28:10 -08004271 /**
4272 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4273 * @param subId The subscription to use to check the configuration.
4274 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 @Override
4276 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004277 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004278 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004279
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 final long token = Binder.clearCallingIdentity();
4281 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004282 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004283 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004284 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004285 } catch (ImsException e) {
4286 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004287 } finally {
4288 Binder.restoreCallingIdentity(token);
4289 }
4290 }
4291
4292 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004293 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004295 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 final long identity = Binder.clearCallingIdentity();
4297 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004299 // This setting doesn't require an active ImsService connection, so do not verify. The
4300 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004301 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004302 } catch (ImsException e) {
4303 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 } finally {
4305 Binder.restoreCallingIdentity(identity);
4306 }
4307 }
4308
shilu366312e2019-12-17 09:28:10 -08004309 /**
4310 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4311 * @param subId The subscription to use to check the configuration.
4312 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004313 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004314 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004315 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004316 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004317 final long identity = Binder.clearCallingIdentity();
4318 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004319 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004320 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004321 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004322 } catch (ImsException e) {
4323 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
4327 }
4328
4329 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004330 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004332 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004333 final long identity = Binder.clearCallingIdentity();
4334 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004335 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004336 // This setting doesn't require an active ImsService connection, so do not verify. The
4337 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004338 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004339 } catch (ImsException e) {
4340 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
4344 }
4345
shilu366312e2019-12-17 09:28:10 -08004346 /**
4347 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4348 * @param subId The subscription to use to check the configuration.
4349 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004350 @Override
4351 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004352 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004353 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 final long identity = Binder.clearCallingIdentity();
4355 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004356 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004357 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004358 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004359 } catch (ImsException e) {
4360 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004361 } finally {
4362 Binder.restoreCallingIdentity(identity);
4363 }
4364 }
4365
4366 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004367 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004369 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 final long identity = Binder.clearCallingIdentity();
4371 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004372 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004373 // This setting doesn't require an active ImsService connection, so do not verify. The
4374 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004375 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004376 } catch (ImsException e) {
4377 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 } finally {
4379 Binder.restoreCallingIdentity(identity);
4380 }
4381 }
4382
shilu366312e2019-12-17 09:28:10 -08004383 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004384 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4385 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4386 * @param subId The subscription to use to check the configuration.
4387 */
4388 @Override
4389 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004390 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004391 mApp, subId, "isCrossSimCallingEnabledByUser");
4392 final long identity = Binder.clearCallingIdentity();
4393 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004394 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004395 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004396 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004397 } catch (ImsException e) {
4398 throw new ServiceSpecificException(e.getCode());
4399 } finally {
4400 Binder.restoreCallingIdentity(identity);
4401 }
4402 }
4403
4404 /**
4405 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4406 * Requires MODIFY_PHONE_STATE permission.
4407 * @param subId The subscription to use to check the configuration.
4408 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4409 * false otherwise
4410 */
4411 @Override
4412 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4414 "setCrossSimCallingEnabled");
4415 final long identity = Binder.clearCallingIdentity();
4416 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004417 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004418 // This setting doesn't require an active ImsService connection, so do not verify. The
4419 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004420 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004421 } catch (ImsException e) {
4422 throw new ServiceSpecificException(e.getCode());
4423 } finally {
4424 Binder.restoreCallingIdentity(identity);
4425 }
4426 }
4427
4428 /**
shilu366312e2019-12-17 09:28:10 -08004429 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4430 * @param subId The subscription to use to check the configuration.
4431 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004432 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004433
Brad Ebinger35c841c2018-10-01 10:40:55 -07004434 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004435 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004436 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004437 final long identity = Binder.clearCallingIdentity();
4438 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004439 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004440 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004441 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004442 } catch (ImsException e) {
4443 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004444 } finally {
4445 Binder.restoreCallingIdentity(identity);
4446 }
4447 }
4448
4449 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004450 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004452 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004453 final long identity = Binder.clearCallingIdentity();
4454 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004455 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004456 // This setting doesn't require an active ImsService connection, so do not verify. The
4457 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004458 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004459 } catch (ImsException e) {
4460 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004461 } finally {
4462 Binder.restoreCallingIdentity(identity);
4463 }
4464 }
4465
4466 @Override
4467 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4469 "setVoWiFiNonPersistent");
4470 final long identity = Binder.clearCallingIdentity();
4471 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004472 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004473 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004474 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004475 } catch (ImsException e) {
4476 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004477 } finally {
4478 Binder.restoreCallingIdentity(identity);
4479 }
4480 }
4481
shilu366312e2019-12-17 09:28:10 -08004482 /**
4483 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4484 * @param subId The subscription to use to check the configuration.
4485 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 @Override
4487 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004488 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004489 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 final long identity = Binder.clearCallingIdentity();
4491 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004492 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004493 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004494 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004495 } catch (ImsException e) {
4496 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 } finally {
4498 Binder.restoreCallingIdentity(identity);
4499 }
4500 }
4501
4502 @Override
4503 public void setVoWiFiModeSetting(int subId, int mode) {
4504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4505 "setVoWiFiModeSetting");
4506 final long identity = Binder.clearCallingIdentity();
4507 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004508 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004509 // This setting doesn't require an active ImsService connection, so do not verify. The
4510 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004511 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004512 } catch (ImsException e) {
4513 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004514 } finally {
4515 Binder.restoreCallingIdentity(identity);
4516 }
4517 }
4518
4519 @Override
4520 public int getVoWiFiRoamingModeSetting(int subId) {
4521 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4522 final long identity = Binder.clearCallingIdentity();
4523 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004524 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004525 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004526 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004527 } catch (ImsException e) {
4528 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
4532 }
4533
4534 @Override
4535 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4537 "setVoWiFiRoamingModeSetting");
4538 final long identity = Binder.clearCallingIdentity();
4539 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004540 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004541 // This setting doesn't require an active ImsService connection, so do not verify. The
4542 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004543 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004544 } catch (ImsException e) {
4545 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004546 } finally {
4547 Binder.restoreCallingIdentity(identity);
4548 }
4549 }
4550
4551 @Override
4552 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4554 "setRttCapabilityEnabled");
4555 final long identity = Binder.clearCallingIdentity();
4556 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004557 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004558 // This setting doesn't require an active ImsService connection, so do not verify. The
4559 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004560 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004561 } catch (ImsException e) {
4562 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
4566 }
4567
shilu366312e2019-12-17 09:28:10 -08004568 /**
4569 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4570 * @param subId The subscription to use to check the configuration.
4571 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004572 @Override
4573 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004574 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004575 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004576 final long identity = Binder.clearCallingIdentity();
4577 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004578 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004579 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004580 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004581 } catch (ImsException e) {
4582 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004583 } finally {
4584 Binder.restoreCallingIdentity(identity);
4585 }
4586 }
4587
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004588 @Override
4589 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4590 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004591
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004592 final long identity = Binder.clearCallingIdentity();
4593 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004594 if (!isImsAvailableOnDevice()) {
4595 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4596 "IMS not available on device.");
4597 }
4598 int slotId = getSlotIndexOrException(subId);
4599 verifyImsMmTelConfiguredOrThrow(slotId);
4600 ImsManager.getInstance(mApp, slotId)
4601 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004602 } catch (ImsException e) {
4603 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004604 } finally {
4605 Binder.restoreCallingIdentity(identity);
4606 }
4607 }
4608
4609 @Override
4610 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4611 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004612
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004613 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004614 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4615 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4616 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004617 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004618 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004619 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004620 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004621 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4622 + "is inactive, ignoring unregister.");
4623 // If the subscription is no longer active, just return, since the callback will already
4624 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004625 } finally {
4626 Binder.restoreCallingIdentity(identity);
4627 }
4628 }
4629
joonhunshincffb7fc2021-11-28 07:32:01 +00004630 @Override
4631 public void registerFeatureProvisioningChangedCallback(int subId,
4632 IFeatureProvisioningCallback callback) {
4633 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4634 mApp, subId, "registerFeatureProvisioningChangedCallback");
4635
4636 final long identity = Binder.clearCallingIdentity();
4637 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4638 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4639 }
4640
joonhunshin91bc1952022-04-29 08:47:15 +00004641 try {
4642 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4643 if (controller == null) {
4644 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4645 "Device does not support IMS");
4646 }
4647 controller.addFeatureProvisioningChangedCallback(subId, callback);
4648 } finally {
4649 Binder.restoreCallingIdentity(identity);
4650 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004651 }
4652
4653 @Override
4654 public void unregisterFeatureProvisioningChangedCallback(int subId,
4655 IFeatureProvisioningCallback callback) {
4656 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4657 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4658
4659 final long identity = Binder.clearCallingIdentity();
4660 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4661 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4662 }
4663
joonhunshin91bc1952022-04-29 08:47:15 +00004664 try {
4665 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4666 if (controller == null) {
4667 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4668 return;
4669 }
4670 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4671 } finally {
4672 Binder.restoreCallingIdentity(identity);
4673 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004674 }
allenwtsu99c623b2020-01-03 18:24:23 +08004675
4676 private void checkModifyPhoneStatePermission(int subId, String message) {
4677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4678 message);
4679 }
4680
allenwtsu99c623b2020-01-03 18:24:23 +08004681 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004682 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004683 boolean isProvisioned) {
4684 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4685
4686 final long identity = Binder.clearCallingIdentity();
4687 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004688 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4689 if (controller == null) {
4690 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4691 return;
4692 }
4693 controller.setRcsProvisioningStatusForCapability(
4694 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
allenwtsu99c623b2020-01-03 18:24:23 +08004698 }
4699
4700
4701 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004702 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4703 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4704 mApp, subId, "getRcsProvisioningStatusForCapability");
4705
allenwtsu99c623b2020-01-03 18:24:23 +08004706 final long identity = Binder.clearCallingIdentity();
4707 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004708 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4709 if (controller == null) {
4710 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4711
4712 // device does not support IMS, this method will return true always.
4713 return true;
4714 }
4715 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004716 } finally {
4717 Binder.restoreCallingIdentity(identity);
4718 }
4719 }
4720
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004721 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004722 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4723 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004724 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004725
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004726 final long identity = Binder.clearCallingIdentity();
4727 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004728 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4729 if (controller == null) {
4730 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4731 return;
4732 }
4733 controller.setImsProvisioningStatusForCapability(
4734 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004735 } finally {
4736 Binder.restoreCallingIdentity(identity);
4737 }
4738 }
4739
4740 @Override
4741 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004742 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4743 mApp, subId, "getProvisioningStatusForCapability");
4744
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004745 final long identity = Binder.clearCallingIdentity();
4746 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004747 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4748 if (controller == null) {
4749 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004750
joonhunshin91bc1952022-04-29 08:47:15 +00004751 // device does not support IMS, this method will return true always.
4752 return true;
4753 }
4754 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004755 } finally {
4756 Binder.restoreCallingIdentity(identity);
4757 }
4758 }
4759
4760 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004761 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4762 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4763 mApp, subId, "isProvisioningRequiredForCapability");
4764
4765 final long identity = Binder.clearCallingIdentity();
4766 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004767 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4768 if (controller == null) {
4769 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4770
4771 // device does not support IMS, this method will return false
4772 return false;
4773 }
4774 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004775 } finally {
4776 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004777 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004778 }
4779
4780 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004781 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4782 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4783 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004784
joonhunshincffb7fc2021-11-28 07:32:01 +00004785 final long identity = Binder.clearCallingIdentity();
4786 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004787 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4788 if (controller == null) {
4789 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4790
4791 // device does not support IMS, this method will return false
4792 return false;
4793 }
4794 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004795 } finally {
4796 Binder.restoreCallingIdentity(identity);
4797 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004798 }
4799
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004800 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004801 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004802 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4803 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4804 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004805 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4806 mApp, subId, "getImsProvisioningInt");
4807
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004808 final long identity = Binder.clearCallingIdentity();
4809 try {
4810 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004811 int slotId = getSlotIndex(subId);
4812 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4813 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4814 + subId + "' for key:" + key);
4815 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4816 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004817
joonhunshin91bc1952022-04-29 08:47:15 +00004818 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4819 if (controller == null) {
4820 loge("getImsProvisioningInt: Device does not support IMS");
4821
4822 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4823 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4824 }
4825 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004826 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4827 return retVal;
4828 }
4829
calvinpanb5a34062021-02-08 19:59:36 +08004830 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004831 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004832 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4833 + subId + "' for key:" + key);
4834 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004835 } finally {
4836 Binder.restoreCallingIdentity(identity);
4837 }
4838 }
4839
4840 @Override
4841 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004842 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4843 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4844 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004845 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4846 mApp, subId, "getImsProvisioningString");
4847
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004848 final long identity = Binder.clearCallingIdentity();
4849 try {
4850 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004851 int slotId = getSlotIndex(subId);
4852 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4853 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4854 + subId + "' for key:" + key);
4855 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4856 }
calvinpanb5a34062021-02-08 19:59:36 +08004857 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004858 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004859 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4860 + subId + "' for key:" + key);
4861 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004862 } finally {
4863 Binder.restoreCallingIdentity(identity);
4864 }
4865 }
4866
4867 @Override
4868 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004869 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4870 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4871 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4873 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004874
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004875 final long identity = Binder.clearCallingIdentity();
4876 try {
4877 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004878 int slotId = getSlotIndex(subId);
4879 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4880 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4881 + subId + "' for key:" + key);
4882 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4883 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004884
joonhunshin91bc1952022-04-29 08:47:15 +00004885 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4886 if (controller == null) {
4887 loge("setImsProvisioningInt: Device does not support IMS");
4888
4889 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
4890 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4891 }
4892 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00004893 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4894 return retVal;
4895 }
4896
calvinpanb5a34062021-02-08 19:59:36 +08004897 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4898 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004899 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004900 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004901 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004902 } finally {
4903 Binder.restoreCallingIdentity(identity);
4904 }
4905 }
4906
4907 @Override
4908 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004909 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4910 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4911 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4913 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004914 final long identity = Binder.clearCallingIdentity();
4915 try {
4916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 int slotId = getSlotIndex(subId);
4918 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4919 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4920 + subId + "' for key:" + key);
4921 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4922 }
calvinpanb5a34062021-02-08 19:59:36 +08004923 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4924 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004925 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004926 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004927 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004928 } finally {
4929 Binder.restoreCallingIdentity(identity);
4930 }
4931 }
4932
Brad Ebinger919631e2021-06-02 17:46:35 -07004933 /**
4934 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4935 * for the given slot ID or no ImsResolver instance has been created.
4936 * @param slotId The slot ID that the IMS service is created for.
4937 * @throws ImsException If there is no ImsService configured for this slot.
4938 */
4939 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4940 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4941 ImsFeature.FEATURE_MMTEL)) {
4942 throw new ImsException("This subscription does not support MMTEL over IMS",
4943 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4944 }
4945 }
4946
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004947 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004948 int slotId = SubscriptionManager.getSlotIndex(subId);
4949 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004950 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4951 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004952 }
4953 return slotId;
4954 }
4955
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004956 private int getSlotIndex(int subId) {
4957 int slotId = SubscriptionManager.getSlotIndex(subId);
4958 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4959 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4960 }
4961 return slotId;
4962 }
4963
Wink Saville36469e72014-06-11 15:17:00 -07004964 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004965 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004966 */
4967 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004968 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4969 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004970 try {
4971 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4972 } catch (SecurityException se) {
4973 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4974 throw new SecurityException("Package " + callingPackage + " does not belong to "
4975 + Binder.getCallingUid());
4976 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004977 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004978 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004979 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004980 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004981 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004982 mApp, subId, callingPackage, callingFeatureId,
4983 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004984 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4985 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004987 final long identity = Binder.clearCallingIdentity();
4988 try {
4989 final Phone phone = getPhone(subId);
4990 if (phone != null) {
4991 return phone.getServiceState().getDataNetworkType();
4992 } else {
4993 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4994 }
4995 } finally {
4996 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004998 }
4999
5000 /**
5001 * Returns the data network type
5002 */
5003 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005004 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005005 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5006 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005007 }
5008
5009 /**
5010 * Returns the data network type for a subId
5011 */
5012 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005013 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5014 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005015 String functionName = "getDataNetworkTypeForSubscriber";
5016 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5017 mApp, functionName)) {
5018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5019 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5020 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5021 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005022 }
5023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 final long identity = Binder.clearCallingIdentity();
5025 try {
5026 final Phone phone = getPhone(subId);
5027 if (phone != null) {
5028 return phone.getServiceState().getDataNetworkType();
5029 } else {
5030 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5031 }
5032 } finally {
5033 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005034 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005035 }
5036
5037 /**
Wink Saville36469e72014-06-11 15:17:00 -07005038 * Returns the Voice network type for a subId
5039 */
5040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005041 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5042 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005043 String functionName = "getVoiceNetworkTypeForSubscriber";
5044 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5045 mApp, functionName)) {
5046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5047 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5048 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5049 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005050 }
5051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 final long identity = Binder.clearCallingIdentity();
5053 try {
5054 final Phone phone = getPhone(subId);
5055 if (phone != null) {
5056 return phone.getServiceState().getVoiceNetworkType();
5057 } else {
5058 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5059 }
5060 } finally {
5061 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005062 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005063 }
5064
5065 /**
5066 * @return true if a ICC card is present
5067 */
5068 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005069 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005070 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5071 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005072 }
5073
5074 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005075 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005076 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005077 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005078 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 final long identity = Binder.clearCallingIdentity();
5080 try {
5081 final Phone phone = PhoneFactory.getPhone(slotIndex);
5082 if (phone != null) {
5083 return phone.getIccCard().hasIccCard();
5084 } else {
5085 return false;
5086 }
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005090 }
5091
5092 /**
5093 * Return if the current radio is LTE on CDMA. This
5094 * is a tri-state return value as for a period of time
5095 * the mode may be unknown.
5096 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005097 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005098 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005099 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005100 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005101 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005102 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5103 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5104 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005105 }
5106
Sanket Padawe356d7632015-06-22 14:03:32 -07005107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005108 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5109 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005110 try {
5111 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5112 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005113 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5114 }
5115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 final long identity = Binder.clearCallingIdentity();
5117 try {
5118 final Phone phone = getPhone(subId);
5119 if (phone == null) {
5120 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5121 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005122 return TelephonyProperties.lte_on_cdma_device()
5123 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124 }
5125 } finally {
5126 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005127 }
Wink Saville36469e72014-06-11 15:17:00 -07005128 }
5129
Wink Saville36469e72014-06-11 15:17:00 -07005130 /**
5131 * {@hide}
5132 * Returns Default subId, 0 in the case of single standby.
5133 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005134 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005135 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005136 }
5137
Shishir Agrawala9f32182016-04-12 12:00:16 -07005138 private int getSlotForDefaultSubscription() {
5139 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5140 }
5141
Wink Savilleb564aae2014-10-23 10:18:09 -07005142 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005143 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005144 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005145
Pengquan Menge92a50d2018-09-21 15:54:48 -07005146 private boolean isActiveSubscription(int subId) {
5147 return mSubscriptionController.isActiveSubId(subId);
5148 }
5149
Ihab Awadf2177b72013-11-25 13:33:23 -08005150 /**
5151 * @see android.telephony.TelephonyManager.WifiCallingChoices
5152 */
5153 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 final long identity = Binder.clearCallingIdentity();
5155 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005156 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005157 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5158 getWhenToMakeWifiCallsDefaultPreference());
5159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005162 }
5163
5164 /**
5165 * @see android.telephony.TelephonyManager.WifiCallingChoices
5166 */
5167 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 final long identity = Binder.clearCallingIdentity();
5169 try {
5170 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005171 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5173 } finally {
5174 Binder.restoreCallingIdentity(identity);
5175 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005176 }
5177
Sailesh Nepald1e68152013-12-12 19:08:02 -08005178 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005179 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005180 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005181 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005182
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005183 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5184 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5185 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005186 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005187 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5188 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005189 }
5190 return PhoneFactory.getPhone(phoneId);
5191 }
5192
Shishir Agrawal566b7612013-10-28 14:41:00 -07005193 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005194 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005195 @NonNull IccLogicalChannelRequest request) {
5196 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5197 /*message=*/ "iccOpenLogicalChannel");
5198
5199 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5200 // Verify that the callingPackage in the request belongs to the calling UID
5201 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5202
5203 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005204 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005205
Rambo Wanga1782702021-11-10 20:15:19 -08005206 private Phone getPhoneFromValidIccLogicalChannelRequest(
5207 @NonNull IccLogicalChannelRequest request, String message) {
5208 Phone phone;
5209 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5211 mApp, request.subId, message);
5212 phone = getPhoneFromSubId(request.subId);
5213 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5214 enforceModifyPermission();
5215 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5216 } else {
5217 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005218 }
Rambo Wanga1782702021-11-10 20:15:19 -08005219 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005220 }
5221
5222 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005223 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 final long identity = Binder.clearCallingIdentity();
5225 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005226 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005228 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5229 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005230 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5231 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 loge("The calling package is not allowed to access ISD-R.");
5233 throw new SecurityException(
5234 "The calling package is not allowed to access ISD-R.");
5235 }
Derek Tan740e1672017-06-27 14:56:27 -07005236 }
Derek Tan740e1672017-06-27 14:56:27 -07005237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005239 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5240 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 return response;
5242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005245 }
5246
5247 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005248 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5249 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5250 /*message=*/"iccCloseLogicalChannel");
5251
5252 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5253
5254 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005255 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005256
Rambo Wanga1782702021-11-10 20:15:19 -08005257 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5258 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005259 // before this feature is enabled, this API should only return false if
5260 // the operation fails instead of throwing runtime exception for
5261 // backward-compatibility.
5262 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5263 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264 final long identity = Binder.clearCallingIdentity();
5265 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005266 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005267 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 }
Chen Xue9d737e2022-01-01 23:41:31 -08005269 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005270 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005271 Boolean success = false;
5272 if (result instanceof RuntimeException) {
5273 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005274 if (shouldThrowExceptionOnFailure) {
5275 throw (RuntimeException) result;
5276 } else {
5277 return false;
5278 }
Chen Xue9d737e2022-01-01 23:41:31 -08005279 } else if (result instanceof Boolean) {
5280 success = (Boolean) result;
5281 } else {
5282 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5283 }
Rambo Wanga1782702021-11-10 20:15:19 -08005284 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 return success;
5286 } finally {
5287 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005288 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005289 }
5290
5291 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005292 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005293 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5295 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005296 if (DBG) {
5297 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5298 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5299 + p3 + " data=" + data);
5300 }
5301 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5302 command, p1, p2, p3, data);
5303 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005304
Jordan Liu4c733742019-02-28 12:03:40 -08005305 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005306 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5307 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005308 enforceModifyPermission();
5309 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005310 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5311 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5312 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005313 }
5314 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005315 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5316 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005317 }
5318
5319 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5320 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 final long identity = Binder.clearCallingIdentity();
5322 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005323 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 return "";
5325 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005328 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5329 null /* workSource */);
5330 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 // Append the returned status code to the end of the response payload.
5333 String s = Integer.toHexString(
5334 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5335 if (response.payload != null) {
5336 s = IccUtils.bytesToHexString(response.payload) + s;
5337 }
5338 return s;
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005341 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005342 }
Jake Hambye994d462014-02-03 13:10:13 -08005343
Evan Charltonc66da362014-05-16 14:06:40 -07005344 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005345 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5346 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5348 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005350 if (DBG) {
5351 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5352 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5353 }
5354 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5355 cla, command, p1, p2, p3, data);
5356 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005357
Jordan Liu4c733742019-02-28 12:03:40 -08005358 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005359 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5360 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005361 enforceModifyPermission();
5362 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5363 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005364 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5365 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5366 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005367 }
5368
5369 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005370 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5371 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005372 }
5373
5374 // open APDU basic channel assuming the caller has sufficient permissions
5375 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5376 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 final long identity = Binder.clearCallingIdentity();
5378 try {
5379 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5380 && TextUtils.equals(ISDR_AID, data)) {
5381 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005382 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5383 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384 if (bestComponent == null
5385 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5386 loge("The calling package is not allowed to select ISD-R.");
5387 throw new SecurityException(
5388 "The calling package is not allowed to select ISD-R.");
5389 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005390 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005391
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005392 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005393 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5394 null /* workSource */);
5395 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 // Append the returned status code to the end of the response payload.
5398 String s = Integer.toHexString(
5399 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5400 if (response.payload != null) {
5401 s = IccUtils.bytesToHexString(response.payload) + s;
5402 }
5403 return s;
5404 } finally {
5405 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005406 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005407 }
5408
5409 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005410 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005411 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5413 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 final long identity = Binder.clearCallingIdentity();
5416 try {
5417 if (DBG) {
5418 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5419 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5420 }
5421
5422 IccIoResult response =
5423 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5424 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5425 subId);
5426
5427 if (DBG) {
5428 log("Exchange SIM_IO [R]" + response);
5429 }
5430
5431 byte[] result = null;
5432 int length = 2;
5433 if (response.payload != null) {
5434 length = 2 + response.payload.length;
5435 result = new byte[length];
5436 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5437 } else {
5438 result = new byte[length];
5439 }
5440
5441 result[length - 1] = (byte) response.sw2;
5442 result[length - 2] = (byte) response.sw1;
5443 return result;
5444 } finally {
5445 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005446 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005447 }
5448
Nathan Haroldb3014052017-01-25 15:57:32 -08005449 /**
5450 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5451 * on a particular subscription
5452 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005453 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5454 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005455 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005456 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005457 return null;
5458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459
5460 final long identity = Binder.clearCallingIdentity();
5461 try {
5462 if (appType != TelephonyManager.APPTYPE_USIM
5463 && appType != TelephonyManager.APPTYPE_SIM) {
5464 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5465 return null;
5466 }
5467 Object response = sendRequest(
5468 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5469 if (response instanceof String[]) {
5470 return (String[]) response;
5471 }
yincheng zhao2737e882019-09-06 17:06:54 -07005472 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005474 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 } finally {
5476 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005477 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005478 }
5479
yincheng zhao2737e882019-09-06 17:06:54 -07005480 /**
5481 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5482 * subscription.
5483 *
5484 * @param subId the id of the subscription.
5485 * @param appType the uicc app type, must be USIM or SIM.
5486 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5487 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005488 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005489 * @return number of fplmns that is successfully written to the SIM.
5490 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005491 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5492 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5494 mApp, subId, "setForbiddenPlmns");
5495
yincheng zhao2737e882019-09-06 17:06:54 -07005496 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5497 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5498 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5499 }
5500 if (fplmns == null) {
5501 throw new IllegalArgumentException("Fplmn List provided is null");
5502 }
5503 for (String fplmn : fplmns) {
5504 if (!CellIdentity.isValidPlmn(fplmn)) {
5505 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5506 }
5507 }
5508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 Object response = sendRequest(
5511 CMD_SET_FORBIDDEN_PLMNS,
5512 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5513 subId);
5514 return (int) response;
5515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
5518 }
5519
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005520 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005521 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5523 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005524
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 final long identity = Binder.clearCallingIdentity();
5526 try {
5527 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5528 if (response.payload == null) {
5529 return "";
5530 }
Evan Charltonc66da362014-05-16 14:06:40 -07005531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 // Append the returned status code to the end of the response payload.
5533 String s = Integer.toHexString(
5534 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5535 s = IccUtils.bytesToHexString(response.payload) + s;
5536 return s;
5537 } finally {
5538 Binder.restoreCallingIdentity(identity);
5539 }
Evan Charltonc66da362014-05-16 14:06:40 -07005540 }
5541
Jake Hambye994d462014-02-03 13:10:13 -08005542 /**
5543 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5544 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5545 *
5546 * @param itemID the ID of the item to read
5547 * @return the NV item as a String, or null on error.
5548 */
5549 @Override
5550 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005551 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5553 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554
5555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005558 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5560 return value;
5561 } finally {
5562 Binder.restoreCallingIdentity(identity);
5563 }
Jake Hambye994d462014-02-03 13:10:13 -08005564 }
5565
5566 /**
5567 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5568 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5569 *
5570 * @param itemID the ID of the item to read
5571 * @param itemValue the value to write, as a String
5572 * @return true on success; false on any failure
5573 */
5574 @Override
5575 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005576 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5578 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579
5580 final long identity = Binder.clearCallingIdentity();
5581 try {
5582 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5583 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005584 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5586 return success;
5587 } finally {
5588 Binder.restoreCallingIdentity(identity);
5589 }
Jake Hambye994d462014-02-03 13:10:13 -08005590 }
5591
5592 /**
5593 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5594 * Used for device configuration by some CDMA operators.
5595 *
5596 * @param preferredRoamingList byte array containing the new PRL
5597 * @return true on success; false on any failure
5598 */
5599 @Override
5600 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5602 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603
5604 final long identity = Binder.clearCallingIdentity();
5605 try {
5606 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5607 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5608 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5609 return success;
5610 } finally {
5611 Binder.restoreCallingIdentity(identity);
5612 }
Jake Hambye994d462014-02-03 13:10:13 -08005613 }
5614
5615 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005616 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005617 * Used for device configuration by some CDMA operators.
5618 *
chen xu6dac5ab2018-10-26 17:39:23 -07005619 * @param slotIndex - device slot.
5620 *
Jake Hambye994d462014-02-03 13:10:13 -08005621 * @return true on success; false on any failure
5622 */
5623 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005624 public boolean resetModemConfig(int slotIndex) {
5625 Phone phone = PhoneFactory.getPhone(slotIndex);
5626 if (phone != null) {
5627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5628 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629
chen xu6dac5ab2018-10-26 17:39:23 -07005630 final long identity = Binder.clearCallingIdentity();
5631 try {
5632 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5633 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5634 return success;
5635 } finally {
5636 Binder.restoreCallingIdentity(identity);
5637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 }
chen xu6dac5ab2018-10-26 17:39:23 -07005639 return false;
5640 }
5641
5642 /**
5643 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5644 *
5645 * @param slotIndex - device slot.
5646 *
5647 * @return true on success; false on any failure
5648 */
5649 @Override
5650 public boolean rebootModem(int slotIndex) {
5651 Phone phone = PhoneFactory.getPhone(slotIndex);
5652 if (phone != null) {
5653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5654 mApp, phone.getSubId(), "rebootModem");
5655
5656 final long identity = Binder.clearCallingIdentity();
5657 try {
5658 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5659 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5660 return success;
5661 } finally {
5662 Binder.restoreCallingIdentity(identity);
5663 }
5664 }
5665 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005666 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005667
Brad Ebinger51f743a2017-01-23 13:50:20 -08005668 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005669 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5670 * {@link #disableIms(int)}.
5671 * @param slotIndex device slot.
5672 */
5673 public void resetIms(int slotIndex) {
5674 enforceModifyPermission();
5675
5676 final long identity = Binder.clearCallingIdentity();
5677 try {
5678 if (mImsResolver == null) {
5679 // may happen if the does not support IMS.
5680 return;
5681 }
5682 mImsResolver.disableIms(slotIndex);
5683 mImsResolver.enableIms(slotIndex);
5684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
5687 }
5688
5689 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005690 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5691 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005692 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005693 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005694 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695
5696 final long identity = Binder.clearCallingIdentity();
5697 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005698 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005699 // may happen if the device does not support IMS.
5700 return;
5701 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005702 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 } finally {
5704 Binder.restoreCallingIdentity(identity);
5705 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005706 }
5707
5708 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005709 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5710 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005711 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005712 public void disableIms(int slotId) {
5713 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714
5715 final long identity = Binder.clearCallingIdentity();
5716 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005717 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005718 // may happen if the device does not support IMS.
5719 return;
5720 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005721 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 } finally {
5723 Binder.restoreCallingIdentity(identity);
5724 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005725 }
5726
5727 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005728 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5729 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005730 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005731 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005732 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005733 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734
5735 final long identity = Binder.clearCallingIdentity();
5736 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005737 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005738 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5739 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005740 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005741 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005745 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005746 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005747 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5748 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005749 @Override
5750 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005751 enforceModifyPermission();
5752
5753 final long identity = Binder.clearCallingIdentity();
5754 try {
5755 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005756 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005757 } finally {
5758 Binder.restoreCallingIdentity(identity);
5759 }
5760 }
5761
5762 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005763 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005764 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005765 */
5766 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5767 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768
5769 final long identity = Binder.clearCallingIdentity();
5770 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005771 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005772 // may happen if the device does not support IMS.
5773 return null;
5774 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005775 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005779 }
5780
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005781 /**
5782 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005783 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005784 */
5785 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5786 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787
5788 final long identity = Binder.clearCallingIdentity();
5789 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005790 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005791 // may happen if the device does not support IMS.
5792 return null;
5793 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005794 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005798 }
5799
Brad Ebinger884c07b2018-02-15 16:17:40 -08005800 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005801 * Sets the ImsService Package Name that Telephony will bind to.
5802 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005803 * @param slotIndex the slot ID that the ImsService should bind for.
5804 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005805 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005806 * @param featureTypes An integer array of feature types associated with a packageName.
5807 * @param packageName The name of the package that the current configuration will be replaced
5808 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005809 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005810 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005811 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5812 int[] featureTypes, String packageName) {
5813 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5814 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5816 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005817 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005818
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819 final long identity = Binder.clearCallingIdentity();
5820 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005821 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005822 // may happen if the device does not support IMS.
5823 return false;
5824 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005825 Map<Integer, String> featureConfig = new HashMap<>();
5826 for (int featureType : featureTypes) {
5827 featureConfig.put(featureType, packageName);
5828 }
5829 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5830 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831 } finally {
5832 Binder.restoreCallingIdentity(identity);
5833 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005834 }
5835
5836 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005837 * Clears any carrier ImsService overrides for the slot index specified that were previously
5838 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5839 *
5840 * This should only be used for testing.
5841 *
5842 * @param slotIndex the slot ID that the ImsService should bind for.
5843 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5844 */
5845 @Override
5846 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5847 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5848 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5849 "clearCarrierImsServiceOverride");
5850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5851 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5852 "clearCarrierImsServiceOverride");
5853
5854 final long identity = Binder.clearCallingIdentity();
5855 try {
5856 if (mImsResolver == null) {
5857 // may happen if the device does not support IMS.
5858 return false;
5859 }
5860 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5861 } finally {
5862 Binder.restoreCallingIdentity(identity);
5863 }
5864 }
5865
5866 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005868 *
5869 * @param slotId The slot that the ImsService is associated with.
5870 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5871 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005872 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005873 * @return the package name of the ImsService configuration.
5874 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005875 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5876 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005877 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005878 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005879 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005880 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5881 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 final long identity = Binder.clearCallingIdentity();
5884 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005885 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005886 // may happen if the device does not support IMS.
5887 return "";
5888 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005889 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005890 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5891 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892 } finally {
5893 Binder.restoreCallingIdentity(identity);
5894 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005895 }
5896
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005897 /**
5898 * Get the MmTelFeature state associated with the requested subscription id.
5899 * @param subId The subscription that the MmTelFeature is associated with.
5900 * @param callback A callback with an integer containing the
5901 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5902 */
5903 @Override
5904 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5905 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005906 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5907 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5908 "IMS not available on device.");
5909 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005910 final long token = Binder.clearCallingIdentity();
5911 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005912 int slotId = getSlotIndex(subId);
5913 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5914 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5915 + subId + "'");
5916 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5917 }
5918 verifyImsMmTelConfiguredOrThrow(slotId);
5919 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5920 try {
5921 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5922 } catch (RemoteException e) {
5923 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5924 + "Ignore");
5925 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005926 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005927 } catch (ImsException e) {
5928 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005929 } finally {
5930 Binder.restoreCallingIdentity(token);
5931 }
5932 }
5933
Daniel Brightbb5840b2021-01-12 15:48:18 -08005934 /**
5935 * Sets the ims registration state on all valid {@link Phone}s.
5936 */
5937 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005938 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939
5940 final long identity = Binder.clearCallingIdentity();
5941 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005942 // NOTE: Before S, this method only set the default phone.
5943 for (final Phone phone : PhoneFactory.getPhones()) {
5944 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5945 phone.setImsRegistrationState(registered);
5946 }
5947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
Wink Saville36469e72014-06-11 15:17:00 -07005951 }
5952
5953 /**
Stuart Scott54788802015-03-30 13:18:01 -07005954 * Set the network selection mode to automatic.
5955 *
5956 */
5957 @Override
5958 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5960 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961
5962 final long identity = Binder.clearCallingIdentity();
5963 try {
shilufc958392020-01-20 11:36:01 -08005964 if (!isActiveSubscription(subId)) {
5965 return;
5966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005968 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5969 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 } finally {
5971 Binder.restoreCallingIdentity(identity);
5972 }
Stuart Scott54788802015-03-30 13:18:01 -07005973 }
5974
Jack Yud10cdd42020-09-28 20:28:01 -07005975 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005976 * Ask the radio to connect to the input network and change selection mode to manual.
5977 *
5978 * @param subId the id of the subscription.
5979 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5980 * the operator to attach to.
5981 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5982 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5983 * normal network selection next time.
5984 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005985 */
5986 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005987 public boolean setNetworkSelectionModeManual(
5988 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5990 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005991
5992 if (!isActiveSubscription(subId)) {
5993 return false;
5994 }
5995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 final long identity = Binder.clearCallingIdentity();
5997 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005998 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006000 if (DBG) {
6001 log("setNetworkSelectionModeManual: subId: " + subId
6002 + " operator: " + operatorInfo);
6003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6005 } finally {
6006 Binder.restoreCallingIdentity(identity);
6007 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006008 }
shilu84f6e8b2019-12-19 13:58:01 -08006009 /**
6010 * Get the manual network selection
6011 *
6012 * @param subId the id of the subscription.
6013 *
6014 * @return the previously saved user selected PLMN
6015 */
6016 @Override
6017 public String getManualNetworkSelectionPlmn(int subId) {
6018 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006019 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006020 mApp, subId, "getManualNetworkSelectionPlmn");
6021
6022 final long identity = Binder.clearCallingIdentity();
6023 try {
6024 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006025 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006026 }
6027
6028 final Phone phone = getPhone(subId);
6029 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006030 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006031 }
6032 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6033 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6034 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6035 } finally {
6036 Binder.restoreCallingIdentity(identity);
6037 }
6038 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006039
6040 /**
6041 * Scans for available networks.
6042 */
6043 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006044 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6045 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6047 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006048 LocationAccessPolicy.LocationPermissionResult locationResult =
6049 LocationAccessPolicy.checkLocationPermission(mApp,
6050 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6051 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006052 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006053 .setCallingPid(Binder.getCallingPid())
6054 .setCallingUid(Binder.getCallingUid())
6055 .setMethod("getCellNetworkScanResults")
6056 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006057 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6058 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006059 .build());
6060 switch (locationResult) {
6061 case DENIED_HARD:
6062 throw new SecurityException("Not allowed to access scan results -- location");
6063 case DENIED_SOFT:
6064 return null;
6065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066
Pengquan Menga1bb6272018-09-06 09:59:22 -07006067 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 try {
6069 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006070 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 } finally {
6073 Binder.restoreCallingIdentity(identity);
6074 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006075 }
6076
6077 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006078 * Get the call forwarding info, given the call forwarding reason.
6079 */
6080 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006081 public void getCallForwarding(int subId, int callForwardingReason,
6082 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006083 enforceReadPrivilegedPermission("getCallForwarding");
6084 long identity = Binder.clearCallingIdentity();
6085 try {
6086 if (DBG) {
6087 log("getCallForwarding: subId " + subId
6088 + " callForwardingReason" + callForwardingReason);
6089 }
Hall Liu27d24262020-09-18 19:04:59 -07006090
6091 Phone phone = getPhone(subId);
6092 if (phone == null) {
6093 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006094 callback.onError(
6095 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006096 } catch (RemoteException e) {
6097 // ignore
6098 }
6099 return;
6100 }
6101
6102 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6103 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6104 @Override
6105 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6106 try {
6107 callback.onCallForwardingInfoAvailable(info);
6108 } catch (RemoteException e) {
6109 // ignore
6110 }
6111 }
6112
6113 @Override
6114 public void onError(int error) {
6115 try {
6116 callback.onError(error);
6117 } catch (RemoteException e) {
6118 // ignore
6119 }
6120 }
6121 });
6122 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006123 } finally {
6124 Binder.restoreCallingIdentity(identity);
6125 }
6126 }
6127
6128 /**
6129 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6130 * reason, the number to forward, and the timeout before the forwarding is attempted.
6131 */
6132 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006133 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6134 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006135 enforceModifyPermission();
6136 long identity = Binder.clearCallingIdentity();
6137 try {
6138 if (DBG) {
6139 log("setCallForwarding: subId " + subId
6140 + " callForwardingInfo" + callForwardingInfo);
6141 }
Hall Liu27d24262020-09-18 19:04:59 -07006142
6143 Phone phone = getPhone(subId);
6144 if (phone == null) {
6145 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006146 callback.accept(
6147 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006148 } catch (RemoteException e) {
6149 // ignore
6150 }
6151 return;
6152 }
6153
6154 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6155 FunctionalUtils.ignoreRemoteException(callback::accept));
6156
6157 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006158 } finally {
6159 Binder.restoreCallingIdentity(identity);
6160 }
6161 }
6162
6163 /**
Hall Liu27d24262020-09-18 19:04:59 -07006164 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006165 */
6166 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006167 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006168 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006169 long identity = Binder.clearCallingIdentity();
6170 try {
Hall Liu27d24262020-09-18 19:04:59 -07006171 Phone phone = getPhone(subId);
6172 if (phone == null) {
6173 try {
6174 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6175 } catch (RemoteException e) {
6176 // ignore
6177 }
6178 return;
6179 }
SongFerngWang0e767992021-03-31 22:08:45 +08006180 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6181 PersistableBundle c = configManager.getConfigForSubId(subId);
6182 boolean requireUssd = c.getBoolean(
6183 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006184
Shuo Qian4a594052020-01-23 11:59:30 -08006185 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006186 if (requireUssd) {
6187 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6188 getSubscriptionCarrierId(subId));
6189 String newUssdCommand = "";
6190 try {
6191 newUssdCommand = carrierXmlParser.getFeature(
6192 CarrierXmlParser.FEATURE_CALL_WAITING)
6193 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6194 } catch (NullPointerException e) {
6195 loge("Failed to generate USSD number" + e);
6196 }
6197 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6198 mMainThreadHandler, callback, carrierXmlParser,
6199 CarrierXmlParser.SsEntry.SSAction.QUERY);
6200 final String ussdCommand = newUssdCommand;
6201 Executors.newSingleThreadExecutor().execute(() -> {
6202 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6203 });
6204 } else {
6205 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6206 callback::accept);
6207 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6208 }
Shuo Qian4a594052020-01-23 11:59:30 -08006209 } finally {
6210 Binder.restoreCallingIdentity(identity);
6211 }
6212 }
6213
6214 /**
Hall Liu27d24262020-09-18 19:04:59 -07006215 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006216 */
6217 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006218 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006219 enforceModifyPermission();
6220 long identity = Binder.clearCallingIdentity();
6221 try {
Hall Liu27d24262020-09-18 19:04:59 -07006222 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6223
6224 Phone phone = getPhone(subId);
6225 if (phone == null) {
6226 try {
6227 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6228 } catch (RemoteException e) {
6229 // ignore
6230 }
6231 return;
6232 }
6233
SongFerngWang0e767992021-03-31 22:08:45 +08006234 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6235 PersistableBundle c = configManager.getConfigForSubId(subId);
6236 boolean requireUssd = c.getBoolean(
6237 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006238
SongFerngWang0e767992021-03-31 22:08:45 +08006239 if (DBG) log("getCallWaitingStatus: subId " + subId);
6240 if (requireUssd) {
6241 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6242 getSubscriptionCarrierId(subId));
6243 CarrierXmlParser.SsEntry.SSAction ssAction =
6244 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6245 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6246 String newUssdCommand = "";
6247 try {
6248 newUssdCommand = carrierXmlParser.getFeature(
6249 CarrierXmlParser.FEATURE_CALL_WAITING)
6250 .makeCommand(ssAction, null);
6251 } catch (NullPointerException e) {
6252 loge("Failed to generate USSD number" + e);
6253 }
6254 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6255 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6256 final String ussdCommand = newUssdCommand;
6257 Executors.newSingleThreadExecutor().execute(() -> {
6258 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6259 });
6260 } else {
6261 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6262 FunctionalUtils.ignoreRemoteException(callback::accept));
6263
6264 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6265 }
Shuo Qian4a594052020-01-23 11:59:30 -08006266 } finally {
6267 Binder.restoreCallingIdentity(identity);
6268 }
6269 }
6270
6271 /**
yinxub1bed742017-04-17 11:45:04 -07006272 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006273 *
yinxub1bed742017-04-17 11:45:04 -07006274 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006275 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6276 * location related information which will be sent if the caller already possess
6277 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006278 * @param request contains the radio access networks with bands/channels to scan
6279 * @param messenger callback messenger for scan results or errors
6280 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006281 * @return the id of the requested scan which can be used to stop the scan.
6282 */
6283 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006284 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6285 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006286 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006287 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6288 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006289 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006290 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6291 if (!renounceFineLocationAccess) {
6292 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6293 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6294 .setCallingPackage(callingPackage)
6295 .setCallingFeatureId(callingFeatureId)
6296 .setCallingPid(Binder.getCallingPid())
6297 .setCallingUid(Binder.getCallingUid())
6298 .setMethod("requestNetworkScan")
6299 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6300 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6301 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6302 .build());
6303 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006304 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006305 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6306 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006307 if (e != null) {
6308 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6309 throw e;
6310 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006311 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006312 return TelephonyScanManager.INVALID_SCAN_ID;
6313 }
6314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 }
Hall Liu912dfd32019-04-25 14:02:26 -07006316 int callingUid = Binder.getCallingUid();
6317 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006318 final long identity = Binder.clearCallingIdentity();
6319 try {
6320 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006321 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006322 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
yinxu504e1392017-04-12 16:03:22 -07006326 }
6327
Hall Liub2ac8ef2019-02-28 15:56:23 -08006328 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006329 NetworkScanRequest request, int subId, String callingPackage) {
6330 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006331 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6332 boolean hasNetworkScanPermission =
6333 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6334 == PERMISSION_GRANTED;
6335
6336 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6337 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6338 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006339 }
6340
6341 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6342 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006343 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6344 return new SecurityException("Specific channels must not be"
6345 + " scanned without location access.");
6346 }
6347 }
6348 }
6349
Hall Liub2ac8ef2019-02-28 15:56:23 -08006350 return null;
6351 }
6352
yinxu504e1392017-04-12 16:03:22 -07006353 /**
6354 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006355 *
6356 * @param subId id of the subscription
6357 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006358 */
6359 @Override
6360 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6362 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363
Hall Liu912dfd32019-04-25 14:02:26 -07006364 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365 final long identity = Binder.clearCallingIdentity();
6366 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006367 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 } finally {
6369 Binder.restoreCallingIdentity(identity);
6370 }
yinxu504e1392017-04-12 16:03:22 -07006371 }
6372
6373 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006374 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006375 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006376 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006377 */
6378 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006379 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006380 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006381 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006382 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383
6384 final long identity = Binder.clearCallingIdentity();
6385 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006386 if (DBG) log("getAllowedNetworkTypesBitmask");
6387 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6388 int networkTypesBitmask = (result != null ? result[0] : -1);
6389 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6390 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006394 }
6395
6396 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006397 * Get the allowed network types for certain reason.
6398 *
6399 * @param subId the id of the subscription.
6400 * @param reason the reason the allowed network type change is taking place
6401 * @return the allowed network types.
6402 */
6403 @Override
6404 public long getAllowedNetworkTypesForReason(int subId,
6405 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006406 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006407 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006408 final long identity = Binder.clearCallingIdentity();
6409 try {
6410 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
6414 }
6415
6416 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006417 * Enable/Disable E-UTRA-NR Dual Connectivity
6418 * @param subId subscription id of the sim card
6419 * @param nrDualConnectivityState expected NR dual connectivity state
6420 * This can be passed following states
6421 * <ol>
6422 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6423 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6424 * <li>Disable NR dual connectivity and force secondary cell to be released
6425 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6426 * </ol>
6427 * @return operation result.
6428 */
6429 @Override
6430 public int setNrDualConnectivityState(int subId,
6431 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6433 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006434 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006435 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6436 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6437 }
6438
Sooraj Sasindran37444802020-08-11 10:40:43 -07006439 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6440 final long identity = Binder.clearCallingIdentity();
6441 try {
6442 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6443 nrDualConnectivityState, subId,
6444 workSource);
6445 if (DBG) log("enableNRDualConnectivity result: " + result);
6446 return result;
6447 } finally {
6448 Binder.restoreCallingIdentity(identity);
6449 }
6450 }
6451
6452 /**
6453 * Is E-UTRA-NR Dual Connectivity enabled
6454 * @return true if dual connectivity is enabled else false
6455 */
6456 @Override
6457 public boolean isNrDualConnectivityEnabled(int subId) {
6458 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006459 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006460 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006461 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006462 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6463 return false;
6464 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006465 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6466 final long identity = Binder.clearCallingIdentity();
6467 try {
6468 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6469 null, subId, workSource);
6470 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6471 return isEnabled;
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
6475 }
6476
6477 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006478 * Set the allowed network types of the device and
6479 * provide the reason triggering the allowed network change.
6480 *
6481 * @param subId the id of the subscription.
6482 * @param reason the reason the allowed network type change is taking place
6483 * @param allowedNetworkTypes the allowed network types.
6484 * @return true on success; false on any failure.
6485 */
6486 @Override
6487 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006488 @TelephonyManager.AllowedNetworkTypesReason int reason,
6489 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6491 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006492 // If the caller only has carrier privileges, then they should not be able to override
6493 // any network types which were set for security reasons.
6494 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6495 != PERMISSION_GRANTED
6496 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6497 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6498 throw new SecurityException(
6499 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6500 + " reason "
6501 + reason);
6502 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006503 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006504 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6505 return false;
6506 }
6507 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6508 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006509 return false;
6510 }
6511
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006512 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6513 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6514
6515
6516 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6517 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6518 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006519 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006520
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006521 final long identity = Binder.clearCallingIdentity();
6522 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006523 Boolean success = (Boolean) sendRequest(
6524 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6525 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6526
6527 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6528 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006529 } finally {
6530 Binder.restoreCallingIdentity(identity);
6531 }
6532 }
6533
6534 /**
Miaoa84611c2019-03-15 09:21:10 +08006535 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006536 *
Miaoa84611c2019-03-15 09:21:10 +08006537 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006538 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006539 * @hide
6540 */
6541 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006542 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006543 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006545 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006546 try {
Miaoa84611c2019-03-15 09:21:10 +08006547 if (phone != null) {
6548 return phone.hasMatchedTetherApnSetting();
6549 } else {
6550 return false;
6551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552 } finally {
6553 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006554 }
Junda Liu475951f2014-11-07 16:45:03 -08006555 }
6556
6557 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006558 * Get the user enabled state of Mobile Data.
6559 *
6560 * TODO: remove and use isUserDataEnabled.
6561 * This can't be removed now because some vendor codes
6562 * calls through ITelephony directly while they should
6563 * use TelephonyManager.
6564 *
6565 * @return true on enabled
6566 */
6567 @Override
6568 public boolean getDataEnabled(int subId) {
6569 return isUserDataEnabled(subId);
6570 }
6571
6572 /**
6573 * Get whether mobile data is enabled per user setting.
6574 *
6575 * There are other factors deciding whether mobile data is actually enabled, but they are
6576 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006577 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006578 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6579 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006580 *
6581 * @return {@code true} if data is enabled else {@code false}
6582 */
6583 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006584 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006585 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006586 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006587 try {
6588 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6589 functionName);
6590 } catch (Exception e) {
6591 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6592 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006593 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006595 mApp, subId, functionName);
6596
Robert Greenwalt646120a2014-05-23 11:54:03 -07006597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598
6599 final long identity = Binder.clearCallingIdentity();
6600 try {
6601 int phoneId = mSubscriptionController.getPhoneId(subId);
6602 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6603 Phone phone = PhoneFactory.getPhone(phoneId);
6604 if (phone != null) {
6605 boolean retVal = phone.isUserDataEnabled();
6606 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6607 return retVal;
6608 } else {
6609 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6610 return false;
6611 }
6612 } finally {
6613 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006614 }
6615 }
6616
6617 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006618 * Checks if the device is capable of mobile data by considering whether whether the
6619 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6620 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006621 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006622 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006623 */
6624 @Override
6625 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006626 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006627 try {
6628 try {
6629 mApp.enforceCallingOrSelfPermission(
6630 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006631 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006632 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006633 try {
6634 mApp.enforceCallingOrSelfPermission(
6635 android.Manifest.permission.READ_PHONE_STATE,
6636 functionName);
6637 } catch (Exception e2) {
6638 mApp.enforceCallingOrSelfPermission(
6639 permission.READ_BASIC_PHONE_STATE, functionName);
6640 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006641 }
6642 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006643 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645
6646 final long identity = Binder.clearCallingIdentity();
6647 try {
6648 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 Phone phone = PhoneFactory.getPhone(phoneId);
6650 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006651 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006652 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006653 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 return retVal;
6655 } else {
6656 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6657 return false;
6658 }
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006661 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006662 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006663
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006664 /**
6665 * Check if data is enabled for a specific reason
6666 * @param subId Subscription index
6667 * @param reason the reason the data enable change is taking place
6668 * @return {@code true} if the overall data is enabled; {@code false} if not.
6669 */
6670 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006671 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006672 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006673 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006674 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006675 try {
6676 mApp.enforceCallingOrSelfPermission(
6677 android.Manifest.permission.ACCESS_NETWORK_STATE,
6678 functionName);
6679 } catch (Exception e) {
6680 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6681 functionName);
6682 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006683 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006684 try {
6685 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006686 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006687 } catch (Exception e2) {
6688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006689 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006690 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006691 }
6692
6693
6694 final long identity = Binder.clearCallingIdentity();
6695 try {
6696 int phoneId = mSubscriptionController.getPhoneId(subId);
6697 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006698 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006699 + " reason=" + reason);
6700 }
6701 Phone phone = PhoneFactory.getPhone(phoneId);
6702 if (phone != null) {
6703 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006704 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006705 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006706 return retVal;
6707 } else {
6708 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006709 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006710 + subId + " retVal=false");
6711 }
6712 return false;
6713 }
6714 } finally {
6715 Binder.restoreCallingIdentity(identity);
6716 }
6717 }
6718
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006719 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006720 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006721 // No permission needed; this only lets the caller inspect their own status.
6722 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006723 }
Junda Liu29340342014-07-10 15:23:27 -07006724
6725 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006726 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006727 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006728 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6729 }
6730
6731 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6732 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006733 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006734 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006735 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6736 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006737 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6738 if (cpt == null) {
6739 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006740 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6741 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006742 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006743 }
6744
6745 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006746 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006747 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006748 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006749 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006750 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006751 Phone phone = getPhone(subId);
6752 if (phone == null) {
6753 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6754 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6755 }
6756 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6757 if (cpt == null) {
6758 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006759 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6760 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006761 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006762 }
6763
6764 @Override
6765 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006766 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006767 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6768 }
6769
6770 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006771 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006772 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006773 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006774 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006775 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6776 Phone phone = PhoneFactory.getPhone(phoneId);
6777 if (phone == null) {
6778 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006779 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006780 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6781 if (cpt == null) {
6782 continue;
6783 }
6784 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006785 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6786 break;
6787 }
6788 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006789 return result;
Junda Liu29340342014-07-10 15:23:27 -07006790 }
Derek Tan89e89d42014-07-08 17:00:10 -07006791
6792 @Override
Junda Liue64de782015-04-16 17:19:16 -07006793 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006794 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006795 Phone phone = PhoneFactory.getPhone(phoneId);
6796 if (phone == null) {
6797 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006798 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006799 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6800 if (cpt == null) {
6801 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006802 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006803 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006804 }
6805
Amith Yamasani6e118872016-02-19 12:53:51 -08006806 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006807 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006808 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006809 Phone phone = PhoneFactory.getPhone(phoneId);
6810 if (phone == null) {
6811 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006812 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006813 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6814 if (cpt == null) {
6815 return Collections.emptyList();
6816 }
6817 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006818 }
6819
chen xuf7e9fe82019-05-09 19:31:02 -07006820 @Override
6821 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006822 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006823 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006824 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006825 try {
6826 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6827 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6828 }
6829 } finally {
6830 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006831 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006832 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006833 }
6834
Rambo Wang6812ffb2022-03-15 16:54:17 -07006835 @Override
6836 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6837 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6838
6839 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6840 if (phone == null) {
6841 return null;
6842 }
6843 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6844 if (cpt == null) {
6845 return null;
6846 }
6847 return cpt.getCarrierServicePackageName();
6848 }
6849
Wink Savilleb564aae2014-10-23 10:18:09 -07006850 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006851 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006852 UiccPort port = phone == null ? null : phone.getUiccPort();
6853 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006854 return null;
6855 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006856 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006857 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006858 return null;
6859 }
6860 return iccId;
6861 }
6862
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006863 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006864 public void setCallComposerStatus(int subId, int status) {
6865 enforceModifyPermission();
6866
6867 final long identity = Binder.clearCallingIdentity();
6868 try {
6869 Phone phone = getPhone(subId);
6870 if (phone != null) {
6871 Phone defaultPhone = phone.getImsPhone();
6872 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6873 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6874 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006875 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6876 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006877 }
6878 }
Shuo Qian284ae752020-12-22 19:10:14 -08006879 } catch (ImsException e) {
6880 throw new ServiceSpecificException(e.getCode());
6881 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006882 Binder.restoreCallingIdentity(identity);
6883 }
6884 }
6885
6886 @Override
6887 public int getCallComposerStatus(int subId) {
6888 enforceReadPrivilegedPermission("getCallComposerStatus");
6889
6890 final long identity = Binder.clearCallingIdentity();
6891 try {
6892 Phone phone = getPhone(subId);
6893 if (phone != null) {
6894 Phone defaultPhone = phone.getImsPhone();
6895 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6896 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6897 return imsPhone.getCallComposerStatus();
6898 }
6899 }
6900 } finally {
6901 Binder.restoreCallingIdentity(identity);
6902 }
6903 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6904 }
6905
6906 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006907 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6908 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006909 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006910 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006912 final long identity = Binder.clearCallingIdentity();
6913 try {
6914 final String iccId = getIccId(subId);
6915 final Phone phone = getPhone(subId);
6916 if (phone == null) {
6917 return false;
6918 }
6919 final String subscriberId = phone.getSubscriberId();
6920
6921 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006922 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 + subscriberId + " to " + number);
6924 }
6925
6926 if (TextUtils.isEmpty(iccId)) {
6927 return false;
6928 }
6929
6930 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6931
6932 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6933 if (alphaTag == null) {
6934 editor.remove(alphaTagPrefKey);
6935 } else {
6936 editor.putString(alphaTagPrefKey, alphaTag);
6937 }
6938
6939 // Record both the line number and IMSI for this ICCID, since we need to
6940 // track all merged IMSIs based on line number
6941 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6942 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6943 if (number == null) {
6944 editor.remove(numberPrefKey);
6945 editor.remove(subscriberPrefKey);
6946 } else {
6947 editor.putString(numberPrefKey, number);
6948 editor.putString(subscriberPrefKey, subscriberId);
6949 }
6950
6951 editor.commit();
6952 return true;
6953 } finally {
6954 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006955 }
Derek Tan7226c842014-07-02 17:42:23 -07006956 }
6957
6958 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006959 public String getLine1NumberForDisplay(int subId, String callingPackage,
6960 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006961 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006963 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006964 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006965 return null;
6966 }
Derek Tan97ebb422014-09-05 16:55:38 -07006967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 final long identity = Binder.clearCallingIdentity();
6969 try {
6970 String iccId = getIccId(subId);
6971 if (iccId != null) {
6972 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6973 if (DBG_MERGE) {
6974 log("getLine1NumberForDisplay returning "
6975 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6976 }
6977 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006979 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6980 return null;
6981 } finally {
6982 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006983 }
Derek Tan7226c842014-07-02 17:42:23 -07006984 }
6985
6986 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006987 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6988 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006990 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006991 return null;
6992 }
Derek Tan97ebb422014-09-05 16:55:38 -07006993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994 final long identity = Binder.clearCallingIdentity();
6995 try {
6996 String iccId = getIccId(subId);
6997 if (iccId != null) {
6998 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6999 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7000 }
7001 return null;
7002 } finally {
7003 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007004 }
Derek Tan7226c842014-07-02 17:42:23 -07007005 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007006
7007 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007008 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7009 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007010 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7011 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007013 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007014 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007015 return null;
7016 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007017
Jordan Liub49b04b2019-05-06 14:45:15 -07007018 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7019 // the process, where TelephonyManager was instantiated.
7020 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007021 final long identity = Binder.clearCallingIdentity();
7022 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007023 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 final TelephonyManager tele = TelephonyManager.from(context);
7025 final SubscriptionManager sub = SubscriptionManager.from(context);
7026
7027 // Figure out what subscribers are currently active
7028 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029
Jordan Liub49b04b2019-05-06 14:45:15 -07007030 // Only consider subs which match the current subId
7031 // This logic can be simplified. See b/131189269 for progress.
7032 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007033 activeSubscriberIds.add(tele.getSubscriberId(subId));
7034 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035
7036 // First pass, find a number override for an active subscriber
7037 String mergeNumber = null;
7038 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7039 for (String key : prefs.keySet()) {
7040 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7041 final String subscriberId = (String) prefs.get(key);
7042 if (activeSubscriberIds.contains(subscriberId)) {
7043 final String iccId = key.substring(
7044 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7045 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7046 mergeNumber = (String) prefs.get(numberKey);
7047 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007048 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 + " for active subscriber " + subscriberId);
7050 }
7051 if (!TextUtils.isEmpty(mergeNumber)) {
7052 break;
7053 }
7054 }
7055 }
7056 }
7057
7058 // Shortcut when no active merged subscribers
7059 if (TextUtils.isEmpty(mergeNumber)) {
7060 return null;
7061 }
7062
7063 // Second pass, find all subscribers under that line override
7064 final ArraySet<String> result = new ArraySet<>();
7065 for (String key : prefs.keySet()) {
7066 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7067 final String number = (String) prefs.get(key);
7068 if (mergeNumber.equals(number)) {
7069 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7070 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7071 final String subscriberId = (String) prefs.get(subscriberKey);
7072 if (!TextUtils.isEmpty(subscriberId)) {
7073 result.add(subscriberId);
7074 }
7075 }
7076 }
7077 }
7078
7079 final String[] resultArray = result.toArray(new String[result.size()]);
7080 Arrays.sort(resultArray);
7081 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007082 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7084 }
7085 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007086 } finally {
7087 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007088 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007089 }
7090
7091 @Override
zoey chen38003472019-12-13 17:16:31 +08007092 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7093 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007094
7095 final long identity = Binder.clearCallingIdentity();
7096 try {
7097 final TelephonyManager telephonyManager = mApp.getSystemService(
7098 TelephonyManager.class);
7099 String subscriberId = telephonyManager.getSubscriberId(subId);
7100 if (subscriberId == null) {
7101 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007102 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007103 + subId);
7104 }
7105 return null;
7106 }
7107
7108 final SubscriptionInfo info = SubscriptionController.getInstance()
7109 .getSubscriptionInfo(subId);
7110 final ParcelUuid groupUuid = info.getGroupUuid();
7111 // If it doesn't belong to any group, return just subscriberId of itself.
7112 if (groupUuid == null) {
7113 return new String[]{subscriberId};
7114 }
7115
7116 // Get all subscriberIds from the group.
7117 final List<String> mergedSubscriberIds = new ArrayList<>();
7118 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007119 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007120 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007121 for (SubscriptionInfo subInfo : groupInfos) {
7122 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7123 if (subscriberId != null) {
7124 mergedSubscriberIds.add(subscriberId);
7125 }
7126 }
7127
7128 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7129 } finally {
7130 Binder.restoreCallingIdentity(identity);
7131
7132 }
7133 }
7134
7135 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007136 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007137 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007138 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139
7140 final long identity = Binder.clearCallingIdentity();
7141 try {
7142 final Phone phone = getPhone(subId);
7143 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7144 } finally {
7145 Binder.restoreCallingIdentity(identity);
7146 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007147 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007148
7149 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007150 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007151 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7152 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007153 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7154 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155
7156 final long identity = Binder.clearCallingIdentity();
7157 try {
7158 final Phone phone = getPhone(subId);
7159 if (phone == null) {
7160 return false;
7161 }
7162 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7163 cdmaNonRoamingList);
7164 } finally {
7165 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007166 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007167 }
7168
7169 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007170 @Deprecated
7171 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7172 enforceModifyPermission();
7173
7174 int returnValue = 0;
7175 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007176 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007177 if(result.exception == null) {
7178 if (result.result != null) {
7179 byte[] responseData = (byte[])(result.result);
7180 if(responseData.length > oemResp.length) {
7181 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7182 responseData.length + "bytes. Buffer Size is " +
7183 oemResp.length + "bytes.");
7184 }
7185 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7186 returnValue = responseData.length;
7187 }
7188 } else {
7189 CommandException ex = (CommandException) result.exception;
7190 returnValue = ex.getCommandError().ordinal();
7191 if(returnValue > 0) returnValue *= -1;
7192 }
7193 } catch (RuntimeException e) {
7194 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7195 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7196 if(returnValue > 0) returnValue *= -1;
7197 }
7198
7199 return returnValue;
7200 }
7201
7202 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007203 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007204 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007205 try {
7206 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007207 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007208 mApp, phone.getSubId(), "getRadioAccessFamily");
7209 } catch (SecurityException e) {
7210 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7211 throw e;
7212 }
chen xub97461a2018-10-26 14:17:57 -07007213 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007214 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007215 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007216 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217 final long identity = Binder.clearCallingIdentity();
7218 try {
chen xub97461a2018-10-26 14:17:57 -07007219 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007220 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007221 mApp, phone.getSubId(), "getRadioAccessFamily");
7222 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007223 } finally {
7224 Binder.restoreCallingIdentity(identity);
7225 }
chen xub97461a2018-10-26 14:17:57 -07007226 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007227 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007228
7229 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007230 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007231 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007232 try {
7233 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7234 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007235 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007236 }
7237 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007238 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007239 }
7240 RoleManager rm = mApp.getSystemService(RoleManager.class);
7241 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7242 if (!dialerRoleHolders.contains(callingPackage)) {
7243 throw new SecurityException("App must be the dialer role holder to"
7244 + " upload a call composer pic");
7245 }
7246
7247 Executors.newSingleThreadExecutor().execute(() -> {
7248 ByteArrayOutputStream output = new ByteArrayOutputStream(
7249 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7250 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7251 boolean readUntilEnd = false;
7252 int totalBytesRead = 0;
7253 byte[] buffer = new byte[16 * 1024];
7254 while (true) {
7255 int numRead;
7256 try {
7257 numRead = input.read(buffer);
7258 } catch (IOException e) {
7259 try {
7260 fd.checkError();
7261 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7262 null);
7263 } catch (IOException e1) {
7264 // This means that the other side closed explicitly with an error. If this
7265 // happens, log and ignore.
7266 loge("Remote end of call composer picture pipe closed: " + e1);
7267 }
7268 break;
7269 }
7270 if (numRead == -1) {
7271 readUntilEnd = true;
7272 break;
7273 }
7274 totalBytesRead += numRead;
7275 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7276 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7277 try {
7278 input.close();
7279 } catch (IOException e) {
7280 // ignore
7281 }
7282 break;
7283 }
7284 output.write(buffer, 0, numRead);
7285 }
7286 // Generally, the remote end will close the file descriptors. The only case where we
7287 // close is above, where the picture size is too big.
7288
7289 try {
7290 fd.checkError();
7291 } catch (IOException e) {
7292 loge("Remote end for call composer closed with an error: " + e);
7293 return;
7294 }
7295
Hall Liuaa4211e2021-01-20 15:43:39 -08007296 if (!readUntilEnd) {
7297 loge("Did not finish reading entire image; aborting");
7298 return;
7299 }
Hall Liu82694d52020-12-11 18:22:04 -08007300
Hall Liuaa4211e2021-01-20 15:43:39 -08007301 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7302 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7303 new CallComposerPictureTransfer.Factory() {},
7304 imageData,
7305 (result) -> {
7306 if (result.first != null) {
7307 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7308 Bundle outputResult = new Bundle();
7309 outputResult.putParcelable(
7310 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7311 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7312 outputResult);
7313 } else {
7314 callback.send(result.second, null);
7315 }
7316 }
7317 );
Hall Liu82694d52020-12-11 18:22:04 -08007318 });
7319 }
7320
7321 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007322 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007323 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007324 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325
7326 final long identity = Binder.clearCallingIdentity();
7327 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007328 ImsManager.getInstance(defaultPhone.getContext(),
7329 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 } finally {
7331 Binder.restoreCallingIdentity(identity);
7332 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007333 }
7334
7335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007336 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007337 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007338 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7339 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007340 return false;
7341 }
Svet Ganovb320e182015-04-16 12:30:10 -07007342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007343 final long identity = Binder.clearCallingIdentity();
7344 try {
7345 // Check the user preference and the system-level IMS setting. Even if the user has
7346 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7347 // In the long run, we may instead need to check if there exists a connection service
7348 // which can support video calling.
7349 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007350 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351 return imsManager.isVtEnabledByPlatform()
7352 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7353 && imsManager.isVtEnabledByUser();
7354 } finally {
7355 Binder.restoreCallingIdentity(identity);
7356 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007357 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007358
Andrew Leea1239f22015-03-02 17:44:07 -08007359 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007360 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7361 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007363 mApp, subId, callingPackage, callingFeatureId,
7364 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 return false;
7366 }
7367
7368 final long identity = Binder.clearCallingIdentity();
7369 try {
7370 CarrierConfigManager configManager =
7371 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007372 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7374 } finally {
7375 Binder.restoreCallingIdentity(identity);
7376 }
Andrew Leea1239f22015-03-02 17:44:07 -08007377 }
7378
7379 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007380 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007382 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 return false;
7384 }
7385
7386 final long identity = Binder.clearCallingIdentity();
7387 try {
7388 CarrierConfigManager configManager =
7389 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007390 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7392 } finally {
7393 Binder.restoreCallingIdentity(identity);
7394 }
Andrew Leea1239f22015-03-02 17:44:07 -08007395 }
7396
Andrew Lee9431b832015-03-09 18:46:45 -07007397 @Override
7398 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007399 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007400 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007401 }
7402
7403 @Override
7404 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 final long identity = Binder.clearCallingIdentity();
7406 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007407 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007408 } finally {
7409 Binder.restoreCallingIdentity(identity);
7410 }
Andrew Lee9431b832015-03-09 18:46:45 -07007411 }
7412
Hall Liuf6668912018-10-31 17:05:23 -07007413 /**
7414 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7415 * support for the feature and device firmware support.
7416 *
7417 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7418 */
7419 @Override
7420 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007422 final Phone phone = getPhone(subscriptionId);
7423 if (phone == null) {
7424 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7425 return false;
7426 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007428 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7430 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007431 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 return isCarrierSupported && isDeviceSupported;
7433 } finally {
7434 Binder.restoreCallingIdentity(identity);
7435 }
Hall Liu98187582018-01-22 19:15:32 -08007436 }
7437
Hall Liuf6668912018-10-31 17:05:23 -07007438 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007439 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7440 * RTT setting, will return true if the device and carrier both support RTT.
7441 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007442 */
7443 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 final long identity = Binder.clearCallingIdentity();
7445 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007446 boolean isRttSupported = isRttSupported(subscriptionId);
7447 boolean isUserRttSettingOn = Settings.Secure.getInt(
7448 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7449 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7450 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7451 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452 } finally {
7453 Binder.restoreCallingIdentity(identity);
7454 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007455 }
7456
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007457 @Deprecated
7458 @Override
7459 public String getDeviceId(String callingPackage) {
7460 return getDeviceIdWithFeature(callingPackage, null);
7461 }
7462
Sanket Padawe7310cc72015-01-14 09:53:20 -08007463 /**
7464 * Returns the unique device ID of phone, for example, the IMEI for
7465 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7466 *
7467 * <p>Requires Permission:
7468 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7469 */
7470 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007471 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007472 try {
7473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7474 } catch (SecurityException se) {
7475 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7476 throw new SecurityException("Package " + callingPackage + " does not belong to "
7477 + Binder.getCallingUid());
7478 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007479 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007480 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007481 return null;
7482 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007483 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007484 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007485 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007486 return null;
7487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488
7489 final long identity = Binder.clearCallingIdentity();
7490 try {
7491 return phone.getDeviceId();
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007495 }
7496
Ping Sunc67b7c22016-03-02 19:16:45 +08007497 /**
7498 * {@hide}
7499 * Returns the IMS Registration Status on a particular subid
7500 *
7501 * @param subId
7502 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007503 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007504 Phone phone = getPhone(subId);
7505 if (phone != null) {
7506 return phone.isImsRegistered();
7507 } else {
7508 return false;
7509 }
7510 }
7511
Santos Cordon7a1885b2015-02-03 11:15:19 -08007512 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007513 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007514 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007515 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007516 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007517 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7518 }
7519 final long identity = Binder.clearCallingIdentity();
7520 try {
7521 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7522 } finally {
7523 Binder.restoreCallingIdentity(identity);
7524 }
7525 }
7526
7527 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007528 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007529 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007530 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007531 mApp,
7532 subscriptionId,
7533 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007534 final long identity = Binder.clearCallingIdentity();
7535 try {
7536 Phone phone = getPhone(subscriptionId);
7537 if (phone == null) {
7538 return null;
7539 }
7540 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
7544 }
7545
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007546 /**
7547 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007548 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007549 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 final long identity = Binder.clearCallingIdentity();
7551 try {
7552 Phone phone = getPhone(subId);
7553 if (phone != null) {
7554 return phone.isWifiCallingEnabled();
7555 } else {
7556 return false;
7557 }
7558 } finally {
7559 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007560 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007561 }
7562
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007563 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007564 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007565 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007566 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007567 final long identity = Binder.clearCallingIdentity();
7568 try {
7569 Phone phone = getPhone(subId);
7570 if (phone != null) {
7571 return phone.isVideoEnabled();
7572 } else {
7573 return false;
7574 }
7575 } finally {
7576 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007577 }
7578 }
7579
7580 /**
7581 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7582 * defined in {@link ImsRegistrationImplBase}.
7583 */
7584 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007585 final long identity = Binder.clearCallingIdentity();
7586 try {
7587 Phone phone = getPhone(subId);
7588 if (phone != null) {
7589 return phone.getImsRegistrationTech();
7590 } else {
7591 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7592 }
7593 } finally {
7594 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007595 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007596 }
7597
Stuart Scott8eef64f2015-04-08 15:13:54 -07007598 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007599 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007600 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007601 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7602 return;
7603 }
Kai Shif70f46f2021-03-03 13:59:46 -08007604 Phone defaultPhone = getDefaultPhone();
7605 if (defaultPhone != null) {
7606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7607 mApp, getDefaultPhone().getSubId(), "factoryReset");
7608 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007609 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007610
Svet Ganovcc087f82015-05-12 20:35:54 -07007611 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007612 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7613 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007614 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007615 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007616 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007617 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007618 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007619 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007620 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007621 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007622 // There has been issues when Sms raw table somehow stores orphan
7623 // fragments. They lead to garbled message when new fragments come
7624 // in and combined with those stale ones. In case this happens again,
7625 // user can reset all network settings which will clean up this table.
7626 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007627 // Clean up IMS settings as well here.
7628 int slotId = getSlotIndex(subId);
7629 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7630 ImsManager.getInstance(mApp, slotId).factoryReset();
7631 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007632
Kai Shif70f46f2021-03-03 13:59:46 -08007633 if (defaultPhone == null) {
7634 return;
7635 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007636 // Erase modem config if erase modem on network setting is enabled.
7637 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7638 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7639 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007640 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007641 }
Kai Shif70f46f2021-03-03 13:59:46 -08007642
7643 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007644 } finally {
7645 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007646 }
7647 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007648
SongFerngWangfd89b102021-05-27 22:44:54 +08007649 @VisibleForTesting
7650 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7651 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7652 return;
7653 }
7654 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7655 RILConstants.PREFERRED_NETWORK_MODE);
7656 SubscriptionManager.setSubscriptionProperty(subId,
7657 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7658 "user=" + defaultNetworkType);
7659 phone.loadAllowedNetworksFromSubscriptionDatabase();
7660 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7661 defaultNetworkType, null);
7662 }
7663
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007664 private void cleanUpSmsRawTable(Context context) {
7665 ContentResolver resolver = context.getContentResolver();
7666 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7667 resolver.delete(uri, null, null);
7668 }
7669
Narayan Kamath1c496c22015-04-16 14:40:19 +01007670 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007671 public String getSimLocaleForSubscriber(int subId) {
7672 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7673 final Phone phone = getPhone(subId);
7674 if (phone == null) {
7675 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007676 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007677 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678 final long identity = Binder.clearCallingIdentity();
7679 try {
chen xu5d3637b2019-01-21 23:31:38 -08007680 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007681 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007682 if (info == null) {
7683 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7684 return null;
7685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 // Try and fetch the locale from the carrier properties or from the SIM language
7687 // preferences (EF-PL and EF-LI)...
7688 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007689 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007690 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7691 if (localeFromDefaultSim != null) {
7692 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7693 if (DBG) log("Using locale from subId: " + subId + " locale: "
7694 + localeFromDefaultSim);
7695 return localeFromDefaultSim.toLanguageTag();
7696 } else {
7697 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698 }
7699 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 // The SIM language preferences only store a language (e.g. fr = French), not an
7702 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7703 // the SIM and carrier preferences does not include a country we add the country
7704 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007705 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007706 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007707 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 return mccLocale.toLanguageTag();
7709 }
7710
7711 if (DBG) log("No locale found - returning null");
7712 return null;
7713 } finally {
7714 Binder.restoreCallingIdentity(identity);
7715 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007716 }
7717
7718 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007719 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007720 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007721 }
7722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 /**
7724 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7725 */
7726 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007727 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007728 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007729 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007730
Gary Jian3aa9a762022-01-24 16:41:19 +08007731 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7732 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007733
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007734 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007735 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7736 * representing the state of the modem.
7737 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007738 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7739 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007740 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007741 */
7742 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007743 public void requestModemActivityInfo(ResultReceiver result) {
7744 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007745 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746
7747 final long identity = Binder.clearCallingIdentity();
7748 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007749 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007750 } finally {
7751 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007752 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007753 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007754
Siddharth Rayb8114062018-06-17 15:02:38 -07007755 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7756 // less than total activity duration.
7757 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7758 if (info == null) {
7759 return false;
7760 }
7761 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007762 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7763 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7764
Siddharth Rayb8114062018-06-17 15:02:38 -07007765 return (info.isValid()
7766 && (info.getSleepTimeMillis() <= activityDurationMs)
7767 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007768 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007769 && (totalTxTimeMs <= activityDurationMs));
7770 }
7771
Gary Jian3aa9a762022-01-24 16:41:19 +08007772 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7773 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7774 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7775 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7776
7777 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7778 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7779 }
7780
7781 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7782 mLastModemActivityInfo.setReceiveTimeMillis(
7783 rat,
7784 freq,
7785 info.getReceiveTimeMillis(rat, freq)
7786 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7787 }
7788
7789 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7790 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7791 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7792 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7793
7794 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7795 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7796 }
7797 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7798 mLastModemActivityInfo.setReceiveTimeMillis(
7799 rat,
7800 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7801 }
7802
7803 /**
7804 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7805 * @param info recent ModemActivityInfo
7806 */
7807 private void mergeModemActivityInfo(ModemActivityInfo info) {
7808 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7809 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7810 boolean matched;
7811 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7812 matched = false;
7813 int rat = info.getSpecificInfoRat(i);
7814 int freq = info.getSpecificInfoFrequencyRange(i);
7815 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7816 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7817 //if it already exists
7818 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7819 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7820 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7821 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7822 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7823 updateLastModemActivityInfo(info, rat, freq);
7824 matched = true;
7825 }
7826 } else {
7827 updateLastModemActivityInfo(info, rat);
7828 matched = true;
7829 }
7830 }
7831 }
7832
7833 if (!matched) {
7834 mDeltaSpecificInfo =
7835 new ActivityStatsTechSpecificInfo(
7836 rat,
7837 freq,
7838 info.getTransmitTimeMillis(rat, freq),
7839 (int) info.getReceiveTimeMillis(rat, freq));
7840 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7841 }
7842 }
7843 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7844 mLastModemActivitySpecificInfo =
7845 new ActivityStatsTechSpecificInfo[merged.size()];
7846 merged.toArray(mLastModemActivitySpecificInfo);
7847
7848 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7849 mLastModemActivityInfo.setSleepTimeMillis(
7850 info.getSleepTimeMillis()
7851 + mLastModemActivityInfo.getSleepTimeMillis());
7852 mLastModemActivityInfo.setIdleTimeMillis(
7853 info.getIdleTimeMillis()
7854 + mLastModemActivityInfo.getIdleTimeMillis());
7855 }
7856
Jack Yu85bd38a2015-11-09 11:34:32 -08007857 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007858 * Returns the service state information on specified subscription.
7859 */
7860 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007861 public ServiceState getServiceStateForSubscriber(int subId,
7862 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7863 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007864 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007865 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007866 return null;
7867 }
7868
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007869 boolean hasFinePermission = false;
7870 boolean hasCoarsePermission = false;
7871 if (!renounceFineLocationAccess) {
7872 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7873 LocationAccessPolicy.checkLocationPermission(mApp,
7874 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7875 .setCallingPackage(callingPackage)
7876 .setCallingFeatureId(callingFeatureId)
7877 .setCallingPid(Binder.getCallingPid())
7878 .setCallingUid(Binder.getCallingUid())
7879 .setMethod("getServiceStateForSubscriber")
7880 .setLogAsInfo(true)
7881 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7882 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7883 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7884 .build());
7885 hasFinePermission =
7886 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7887 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007888
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007889 if (!renounceCoarseLocationAccess) {
7890 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7891 LocationAccessPolicy.checkLocationPermission(mApp,
7892 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7893 .setCallingPackage(callingPackage)
7894 .setCallingFeatureId(callingFeatureId)
7895 .setCallingPid(Binder.getCallingPid())
7896 .setCallingUid(Binder.getCallingUid())
7897 .setMethod("getServiceStateForSubscriber")
7898 .setLogAsInfo(true)
7899 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7900 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7901 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7902 .build());
7903 hasCoarsePermission =
7904 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7905 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007906
Jack Yu479f40e2020-10-27 21:29:25 -07007907 final Phone phone = getPhone(subId);
7908 if (phone == null) {
7909 return null;
7910 }
7911
Jordan Liu0f2bc442020-11-18 16:47:37 -08007912 final long identity = Binder.clearCallingIdentity();
7913
Jack Yu479f40e2020-10-27 21:29:25 -07007914 boolean isCallingPackageDataService = phone.getDataServicePackages()
7915 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007916 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007917 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7918 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7919 Rlog.d(LOG_TAG,
7920 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7921 return null;
7922 }
7923
Hall Liuf19c44f2018-11-27 14:38:17 -08007924 ServiceState ss = phone.getServiceState();
7925
7926 // Scrub out the location info in ServiceState depending on what level of access
7927 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007928 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007929 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7930 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 } finally {
7932 Binder.restoreCallingIdentity(identity);
7933 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007934 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007935
7936 /**
7937 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7938 *
7939 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7940 * voicemail ringtone.
7941 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7942 * PhoneAccount.
7943 */
7944 @Override
7945 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007946 final long identity = Binder.clearCallingIdentity();
7947 try {
7948 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7949 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007950 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007953 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7954 } finally {
7955 Binder.restoreCallingIdentity(identity);
7956 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007957 }
7958
7959 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007960 * Sets the per-account voicemail ringtone.
7961 *
7962 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7963 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7964 *
7965 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7966 * voicemail ringtone.
7967 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7968 * PhoneAccount.
7969 */
7970 @Override
7971 public void setVoicemailRingtoneUri(String callingPackage,
7972 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007973 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007974 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007975 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7976 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7978 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7979 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007981
7982 final long identity = Binder.clearCallingIdentity();
7983 try {
7984 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7985 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007986 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987 }
7988 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7989 } finally {
7990 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007991 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007992 }
7993
7994 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007995 * Returns whether vibration is set for voicemail notification in Phone settings.
7996 *
7997 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7998 * voicemail vibration setting.
7999 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8000 */
8001 @Override
8002 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008003 final long identity = Binder.clearCallingIdentity();
8004 try {
8005 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8006 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008007 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008008 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8011 } finally {
8012 Binder.restoreCallingIdentity(identity);
8013 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008014 }
8015
Youhan Wange64578a2016-05-02 15:32:42 -07008016 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008017 * Sets the per-account voicemail vibration.
8018 *
8019 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8020 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8021 *
8022 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8023 * voicemail vibration setting.
8024 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8025 * specific PhoneAccount.
8026 */
8027 @Override
8028 public void setVoicemailVibrationEnabled(String callingPackage,
8029 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008030 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008032 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8033 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8035 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8036 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008037 }
8038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008039 final long identity = Binder.clearCallingIdentity();
8040 try {
8041 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8042 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008043 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008044 }
8045 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8046 } finally {
8047 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008048 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008049 }
8050
8051 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008052 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8053 *
8054 * @throws SecurityException if the caller does not have the required permission
8055 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008056 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008057 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008058 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008059 }
8060
8061 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008062 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8063 * permission.
8064 *
8065 * @throws SecurityException if the caller does not have the required permission
8066 */
8067 private void enforceSendSmsPermission() {
8068 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8069 }
8070
8071 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008072 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008073 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008074 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008075 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008076 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008077 final long identity = Binder.clearCallingIdentity();
8078 try {
8079 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008080 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 if (componentName == null) {
8082 throw new SecurityException(
8083 "Caller not current active visual voicemail package[null]");
8084 }
8085 String vvmPackage = componentName.getPackageName();
8086 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008087 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008088 }
8089 } finally {
8090 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008091 }
8092 }
8093
8094 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008095 * Return the application ID for the app type.
8096 *
8097 * @param subId the subscription ID that this request applies to.
8098 * @param appType the uicc app type.
8099 * @return Application ID for specificied app type, or null if no uicc.
8100 */
8101 @Override
8102 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008103 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008104 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008105
8106 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008107 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 if (phone == null) {
8109 return null;
8110 }
8111 String aid = null;
8112 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008113 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008114 .getApplicationByType(appType).getAid();
8115 } catch (Exception e) {
8116 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8117 }
8118 return aid;
8119 } finally {
8120 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008121 }
Youhan Wange64578a2016-05-02 15:32:42 -07008122 }
8123
Youhan Wang4001d252016-05-11 10:29:41 -07008124 /**
8125 * Return the Electronic Serial Number.
8126 *
8127 * @param subId the subscription ID that this request applies to.
8128 * @return ESN or null if error.
8129 */
8130 @Override
8131 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008132 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008133 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008134
8135 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008136 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008137 if (phone == null) {
8138 return null;
8139 }
8140 String esn = null;
8141 try {
8142 esn = phone.getEsn();
8143 } catch (Exception e) {
8144 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8145 }
8146 return esn;
8147 } finally {
8148 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008149 }
Youhan Wang4001d252016-05-11 10:29:41 -07008150 }
8151
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008152 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008153 * Return the Preferred Roaming List Version.
8154 *
8155 * @param subId the subscription ID that this request applies to.
8156 * @return PRLVersion or null if error.
8157 */
8158 @Override
8159 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008160 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008161 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162
8163 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008164 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008165 if (phone == null) {
8166 return null;
8167 }
8168 String cdmaPrlVersion = null;
8169 try {
8170 cdmaPrlVersion = phone.getCdmaPrlVersion();
8171 } catch (Exception e) {
8172 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8173 }
8174 return cdmaPrlVersion;
8175 } finally {
8176 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008177 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008178 }
8179
8180 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008181 * Get snapshot of Telephony histograms
8182 * @return List of Telephony histograms
8183 * @hide
8184 */
8185 @Override
8186 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8188 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189
8190 final long identity = Binder.clearCallingIdentity();
8191 try {
8192 return RIL.getTelephonyRILTimingHistograms();
8193 } finally {
8194 Binder.restoreCallingIdentity(identity);
8195 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008196 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008197
8198 /**
8199 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008200 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8201 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008202 * Require system privileges. In the future we may add this to carrier APIs.
8203 *
Michele Berionne482f8202018-11-27 18:57:59 -08008204 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008205 */
8206 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008207 @TelephonyManager.SetCarrierRestrictionResult
8208 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008209 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008210 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008211
Michele Berionne482f8202018-11-27 18:57:59 -08008212 if (carrierRestrictionRules == null) {
8213 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008214 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008216 final long identity = Binder.clearCallingIdentity();
8217 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008218 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008219 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008220 } finally {
8221 Binder.restoreCallingIdentity(identity);
8222 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008223 }
8224
8225 /**
8226 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008227 * Get the allowed carrier list and the excluded carrier list, including the priority between
8228 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008229 * Require system privileges. In the future we may add this to carrier APIs.
8230 *
Michele Berionne482f8202018-11-27 18:57:59 -08008231 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008232 */
8233 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008234 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008235 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008236 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008237
8238 final long identity = Binder.clearCallingIdentity();
8239 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008240 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8241 if (response instanceof CarrierRestrictionRules) {
8242 return (CarrierRestrictionRules) response;
8243 }
8244 // Response is an Exception of some kind,
8245 // which is signalled to the user as a NULL retval
8246 return null;
8247 } catch (Exception e) {
8248 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8249 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008250 } finally {
8251 Binder.restoreCallingIdentity(identity);
8252 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008253 }
8254
fionaxu59545b42016-05-25 15:53:37 -07008255 /**
fionaxu59545b42016-05-25 15:53:37 -07008256 * Action set from carrier signalling broadcast receivers to enable/disable radio
8257 * @param subId the subscription ID that this action applies to.
8258 * @param enabled control enable or disable radio.
8259 * {@hide}
8260 */
8261 @Override
8262 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8263 enforceModifyPermission();
8264 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265
8266 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008267 if (phone == null) {
8268 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8269 return;
8270 }
8271 try {
8272 phone.carrierActionSetRadioEnabled(enabled);
8273 } catch (Exception e) {
8274 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275 } finally {
8276 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008277 }
8278 }
8279
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008280 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008281 * Enable or disable Voice over NR (VoNR)
8282 * @param subId the subscription ID that this action applies to.
8283 * @param enabled enable or disable VoNR.
8284 * @return operation result.
8285 */
8286 @Override
8287 public int setVoNrEnabled(int subId, boolean enabled) {
8288 enforceModifyPermission();
8289 final Phone phone = getPhone(subId);
8290
8291 final long identity = Binder.clearCallingIdentity();
8292 if (phone == null) {
8293 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8294 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8295 }
8296
8297 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8298 try {
8299 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8300 workSource);
8301 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008302
8303 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8304 if (DBG) {
8305 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8306 }
8307 SubscriptionManager.setSubscriptionProperty(
8308 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8309 (enabled ? "1" : "0"));
8310 }
8311
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008312 return result;
8313 } finally {
8314 Binder.restoreCallingIdentity(identity);
8315 }
8316 }
8317
8318 /**
8319 * Is voice over NR enabled
8320 * @return true if VoNR is enabled else false
8321 */
8322 @Override
8323 public boolean isVoNrEnabled(int subId) {
8324 enforceReadPrivilegedPermission("isVoNrEnabled");
8325 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8326 final long identity = Binder.clearCallingIdentity();
8327 try {
8328 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8329 null, subId, workSource);
8330 if (DBG) log("isVoNrEnabled: " + isEnabled);
8331 return isEnabled;
8332 } finally {
8333 Binder.restoreCallingIdentity(identity);
8334 }
8335 }
8336
8337 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008338 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8339 * network status based on which carrier apps could apply actions accordingly,
8340 * enable/disable default url handler for example.
8341 *
8342 * @param subId the subscription ID that this action applies to.
8343 * @param report control start/stop reporting the default network status.
8344 * {@hide}
8345 */
8346 @Override
8347 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8348 enforceModifyPermission();
8349 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008350
8351 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008352 if (phone == null) {
8353 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8354 return;
8355 }
8356 try {
8357 phone.carrierActionReportDefaultNetworkStatus(report);
8358 } catch (Exception e) {
8359 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008360 } finally {
8361 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008362 }
8363 }
8364
8365 /**
fionaxud9622282017-07-17 17:51:30 -07008366 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8367 * @param subId the subscription ID that this action applies to.
8368 * {@hide}
8369 */
8370 @Override
8371 public void carrierActionResetAll(int subId) {
8372 enforceModifyPermission();
8373 final Phone phone = getPhone(subId);
8374 if (phone == null) {
8375 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8376 return;
8377 }
8378 try {
8379 phone.carrierActionResetAll();
8380 } catch (Exception e) {
8381 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8382 }
8383 }
8384
8385 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008386 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8387 * bug report is being generated.
8388 */
8389 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008390 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008391 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8392 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008393 writer.println("Permission Denial: can't dump Phone from pid="
8394 + Binder.getCallingPid()
8395 + ", uid=" + Binder.getCallingUid()
8396 + "without permission "
8397 + android.Manifest.permission.DUMP);
8398 return;
8399 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008400 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008401 }
Jack Yueb89b242016-06-22 13:27:47 -07008402
Brad Ebingerdac2f002018-04-03 15:17:52 -07008403 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008404 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8405 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8406 @NonNull String[] args) {
8407 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8408 this, in.getFileDescriptor(), out.getFileDescriptor(),
8409 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008410 }
8411
Jack Yueb89b242016-06-22 13:27:47 -07008412 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008413 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008414 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008415 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008416 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008417 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008418 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008419 */
8420 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008421 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008422 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008423 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8424 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8425 try {
8426 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008427 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008428 } catch (SecurityException se) {
8429 enforceModifyPermission();
8430 }
8431 } else {
8432 enforceModifyPermission();
8433 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008434
8435 final long identity = Binder.clearCallingIdentity();
8436 try {
8437 Phone phone = getPhone(subId);
8438 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008439 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8440 phone.carrierActionSetMeteredApnsEnabled(enabled);
8441 } else {
Jack Yuabb10902022-07-31 00:43:21 -07008442 phone.getDataSettingsManager().setDataEnabled(
8443 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008445 }
8446 } finally {
8447 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008448 }
8449 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008450
8451 /**
8452 * Get Client request stats
8453 * @return List of Client Request Stats
8454 * @hide
8455 */
8456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008457 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8458 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008460 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008461 return null;
8462 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008463 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008465 final long identity = Binder.clearCallingIdentity();
8466 try {
8467 if (phone != null) {
8468 return phone.getClientRequestStats();
8469 }
8470
8471 return null;
8472 } finally {
8473 Binder.restoreCallingIdentity(identity);
8474 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008475 }
8476
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008477 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008478 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008479 if (uid == Process.ROOT_UID && packageName == null) {
8480 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8481 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8482 // exception. ROOT_UID seems not to have a valid package name returned by
8483 // PackageManager, so just fake it here to avoid issues when running telephony shell
8484 // commands that plumb through the RIL as root, like so:
8485 // $ adb root
8486 // $ adb shell cmd phone ...
8487 packageName = "root";
8488 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008489 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008490 }
Jack Yueb4124c2017-02-16 15:32:43 -08008491
8492 /**
Grace Chen70990072017-03-24 17:21:30 -07008493 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008494 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008495 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008496 * @param state State of SIM (power down, power up, pass through)
8497 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8498 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8499 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008500 *
8501 **/
8502 @Override
Grace Chen70990072017-03-24 17:21:30 -07008503 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008504 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008505 Phone phone = PhoneFactory.getPhone(slotIndex);
8506
vagdeviaf9a5b92018-08-15 16:01:53 -07008507 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8508
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008509 final long identity = Binder.clearCallingIdentity();
8510 try {
8511 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008512 phone.setSimPowerState(state, null, workSource);
8513 }
8514 } finally {
8515 Binder.restoreCallingIdentity(identity);
8516 }
8517 }
8518
8519 /**
8520 * Set SIM card power state.
8521 *
8522 * @param slotIndex SIM slot id.
8523 * @param state State of SIM (power down, power up, pass through)
8524 * @param callback callback to trigger after success or failure
8525 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8526 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8527 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8528 *
8529 **/
8530 @Override
8531 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8532 IIntegerConsumer callback) {
8533 enforceModifyPermission();
8534 Phone phone = PhoneFactory.getPhone(slotIndex);
8535
8536 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8537
8538 final long identity = Binder.clearCallingIdentity();
8539 try {
8540 if (phone != null) {
8541 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8542 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008543 }
8544 } finally {
8545 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008546 }
8547 }
Shuo Qiandd210312017-04-12 22:11:33 +00008548
Tyler Gunn65d45c22017-06-05 11:22:26 -07008549 private boolean isUssdApiAllowed(int subId) {
8550 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008551 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008552 if (configManager == null) {
8553 return false;
8554 }
8555 PersistableBundle pb = configManager.getConfigForSubId(subId);
8556 if (pb == null) {
8557 return false;
8558 }
8559 return pb.getBoolean(
8560 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8561 }
8562
Shuo Qiandd210312017-04-12 22:11:33 +00008563 /**
8564 * Check if phone is in emergency callback mode
8565 * @return true if phone is in emergency callback mode
8566 * @param subId sub id
8567 */
goneil9c5f4872017-12-05 14:07:56 -08008568 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008569 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008570 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008571 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008572
8573 final long identity = Binder.clearCallingIdentity();
8574 try {
8575 if (phone != null) {
8576 return phone.isInEcm();
8577 } else {
8578 return false;
8579 }
8580 } finally {
8581 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008582 }
8583 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008584
8585 /**
8586 * Get the current signal strength information for the given subscription.
8587 * Because this information is not updated when the device is in a low power state
8588 * it should not be relied-upon to be current.
8589 * @param subId Subscription index
8590 * @return the most recent cached signal strength info from the modem
8591 */
8592 @Override
8593 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008594 final long identity = Binder.clearCallingIdentity();
8595 try {
8596 Phone p = getPhone(subId);
8597 if (p == null) {
8598 return null;
8599 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008601 return p.getSignalStrength();
8602 } finally {
8603 Binder.restoreCallingIdentity(identity);
8604 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008605 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008606
Pengquan Meng77b7f132018-08-22 14:49:57 -07008607 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008608 * Get the current modem radio state for the given slot.
8609 * @param slotIndex slot index.
8610 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008611 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008612 * @return the current radio power state from the modem
8613 */
8614 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008615 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008616 Phone phone = PhoneFactory.getPhone(slotIndex);
8617 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008618 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8619 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008620 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8621 }
8622
8623 final long identity = Binder.clearCallingIdentity();
8624 try {
8625 return phone.getRadioPowerState();
8626 } finally {
8627 Binder.restoreCallingIdentity(identity);
8628 }
8629 }
8630 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8631 }
8632
8633 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008634 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8635 *
8636 * <p>Requires one of the following permissions:
8637 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008638 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008639 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8640 * privileges.
8641 *
8642 * @param subId subscription id
8643 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8644 * {@code false}.
8645 */
8646 @Override
8647 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008648 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008649 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008650 try {
8651 mApp.enforceCallingOrSelfPermission(
8652 android.Manifest.permission.ACCESS_NETWORK_STATE,
8653 functionName);
8654 } catch (Exception e) {
8655 mApp.enforceCallingOrSelfPermission(
8656 permission.READ_BASIC_PHONE_STATE, functionName);
8657 }
Shuo Qian093013d2020-08-13 15:42:55 -07008658 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008659 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008660 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008661 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008662
Pengquan Menga1bb6272018-09-06 09:59:22 -07008663 boolean isEnabled = false;
8664 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008665 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008666 Phone phone = getPhone(subId);
8667 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008668 } finally {
8669 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008670 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008671 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008672 }
8673
8674
8675 /**
8676 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8677 *
8678 * <p> Requires permission:
8679 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8680 * privileges.
8681 *
8682 * @param subId subscription id
8683 * @param isEnabled {@code true} means enable, {@code false} means disable.
8684 */
8685 @Override
8686 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8688 mApp, subId, "setDataRoamingEnabled");
8689
Pengquan Menga1bb6272018-09-06 09:59:22 -07008690 final long identity = Binder.clearCallingIdentity();
8691 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008692 Phone phone = getPhone(subId);
8693 if (phone != null) {
8694 phone.setDataRoamingEnabled(isEnabled);
8695 }
8696 } finally {
8697 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008698 }
8699 }
8700
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008701 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008702 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008703 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008704 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008705 mApp, subId, "isManualNetworkSelectionAllowed");
8706
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008707 boolean isAllowed = true;
8708 final long identity = Binder.clearCallingIdentity();
8709 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008710 Phone phone = getPhone(subId);
8711 if (phone != null) {
8712 isAllowed = phone.isCspPlmnEnabled();
8713 }
8714 } finally {
8715 Binder.restoreCallingIdentity(identity);
8716 }
8717 return isAllowed;
8718 }
8719
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008720 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8721 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008722 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008723 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008724 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008725 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8726 if (phone == null) {
8727 return false;
8728 }
8729 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8730 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8731 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008732 }
8733
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008734 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008735 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008736 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008737 mApp.getSystemService(AppOpsManager.class)
8738 .checkPackage(Binder.getCallingUid(), callingPackage);
8739
Jordan Liu1e142fc2019-04-22 15:10:43 -07008740 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008741 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008742 try {
8743 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008744 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008745 } catch (SecurityException e) {
8746 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8747 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008748 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008749 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008750 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008751 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008752 }
sandeepjsb6c87872021-09-27 15:34:44 +00008753 // checking compatibility, if calling app's target SDK is T and beyond.
8754 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8755 Binder.getCallingUid())) {
8756 isIccIdAccessRestricted = true;
8757 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008758 final long identity = Binder.clearCallingIdentity();
8759 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008760 UiccController uiccController = UiccController.getInstance();
8761 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008762 if (hasReadPermission) {
8763 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008764 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008765
8766 // Remove private info if the caller doesn't have access
8767 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8768 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008769 //setting the value after compatibility check
8770 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008771 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8772 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008773 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008774 if (card == null) {
8775 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008776 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008777 continue;
8778 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008779 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8780 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008781 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008782 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008783 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008784 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8785 for (UiccPortInfo portInfo : portInfos) {
8786 UiccPort port = uiccController.getUiccPortForSlot(
8787 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8788 if (port == null) {
8789 // assume no access if port is null
8790 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8791 continue;
8792 }
8793 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8794 uiccPortInfos.add(portInfo);
8795 } else {
8796 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8797 }
8798 }
8799 filteredInfos.add(new UiccCardInfo(
8800 cardInfo.isEuicc(),
8801 cardInfo.getCardId(),
8802 null,
8803 cardInfo.getPhysicalSlotIndex(),
8804 cardInfo.isRemovable(),
8805 cardInfo.isMultipleEnabledProfilesSupported(),
8806 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008807 }
8808 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008809 } finally {
8810 Binder.restoreCallingIdentity(identity);
8811 }
8812 }
8813
sandeepjsb6c87872021-09-27 15:34:44 +00008814 /**
8815 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8816 * generally private and require carrier privileges to view.
8817 *
8818 * @hide
8819 */
8820 @NonNull
8821 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8822 List<UiccPortInfo> portinfo = new ArrayList<>();
8823 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8824 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8825 }
8826 return new UiccCardInfo(
8827 cardInfo.isEuicc(),
8828 cardInfo.getCardId(),
8829 null,
8830 cardInfo.getPhysicalSlotIndex(),
8831 cardInfo.isRemovable(),
8832 cardInfo.isMultipleEnabledProfilesSupported(),
8833 portinfo
8834 );
8835 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008836
sandeepjsb6c87872021-09-27 15:34:44 +00008837 /**
8838 * @hide
8839 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8840 * These values are generally private and require carrier privileges to view.
8841 */
8842 @NonNull
8843 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8844 return new UiccPortInfo(
8845 UiccPortInfo.ICCID_REDACTED,
8846 portInfo.getPortIndex(),
8847 portInfo.getLogicalSlotIndex(),
8848 portInfo.isActive()
8849 );
8850 }
8851 @Override
8852 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008853 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008854 mApp.getSystemService(AppOpsManager.class)
8855 .checkPackage(Binder.getCallingUid(), callingPackage);
8856
sandeepjsb6c87872021-09-27 15:34:44 +00008857 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008858
Aman Guptaf3c90b32022-03-17 04:54:16 +00008859 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8860 // we are reading iccId which is PII data.
8861 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008862
8863 // checking compatibility, if calling app's target SDK is T and beyond.
8864 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8865 Binder.getCallingUid())) {
8866 isLogicalSlotAccessRestricted = true;
8867 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008868 final long identity = Binder.clearCallingIdentity();
8869 try {
8870 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008871 if (slots == null || slots.length == 0) {
8872 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008873 return null;
8874 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008875 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8876 for (int i = 0; i < slots.length; i++) {
8877 UiccSlot slot = slots[i];
8878 if (slot == null) {
8879 continue;
8880 }
8881
Jordan Liu7be7e652019-05-06 18:55:02 +00008882 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008883 UiccCard card = slot.getUiccCard();
8884 if (card != null) {
8885 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008886 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008887 cardId = slot.getEid();
8888 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008889 // If cardId is null, use iccId of default port as cardId.
8890 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008891 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008892 }
8893
Jordan Liu857451f2019-05-09 16:35:35 -07008894 if (cardId != null) {
8895 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8896 // if cardId is an EID, it's all digits so this is fine
8897 cardId = IccUtils.stripTrailingFs(cardId);
8898 }
8899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008900 int cardState = 0;
8901 switch (slot.getCardState()) {
8902 case CARDSTATE_ABSENT:
8903 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8904 break;
8905 case CARDSTATE_PRESENT:
8906 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8907 break;
8908 case CARDSTATE_ERROR:
8909 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8910 break;
8911 case CARDSTATE_RESTRICTED:
8912 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8913 break;
8914 default:
8915 break;
8916
8917 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008918 List<UiccPortInfo> portInfos = new ArrayList<>();
8919 int[] portIndexes = slot.getPortList();
8920 for (int portIdx : portIndexes) {
8921 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00008922 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008923 portInfos.add(new UiccPortInfo(iccId, portIdx,
8924 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008926 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008927 slot.isEuicc(),
8928 cardId,
8929 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008930 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008931 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008932 //setting the value after compatibility check
8933 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008934 }
8935 return infos;
8936 } finally {
8937 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008938 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008939 }
8940
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008941 /* Returns null if doesn't have read permission or carrier privilege access. */
8942 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8943 boolean hasReadPermission) {
8944 String iccId = slot.getIccId(portIndex);
8945 if (hasReadPermission) { // if has read permission
8946 return iccId;
8947 } else {
8948 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8949 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8950 // if no read permission, checking carrier privilege access
8951 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8952 return iccId;
8953 }
8954 }
8955 }
8956 // No read permission or carrier privilege access.
8957 return UiccPortInfo.ICCID_REDACTED;
8958 }
8959
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008960 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008961 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008962 public boolean switchSlots(int[] physicalSlots) {
8963 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008964
8965 final long identity = Binder.clearCallingIdentity();
8966 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008967 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8968 for (int i = 0; i < physicalSlots.length; i++) {
8969 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8970 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8971 physicalSlots[i], i));
8972 }
8973 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008974 } finally {
8975 Binder.restoreCallingIdentity(identity);
8976 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008977 }
Jack Yu4c988042018-02-27 15:30:01 -08008978
8979 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008980 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8981 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8982 enforceModifyPermission();
8983
8984 final long identity = Binder.clearCallingIdentity();
8985 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008986 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00008987 } finally {
8988 Binder.restoreCallingIdentity(identity);
8989 }
8990 }
8991
8992 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008993 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008994 final long identity = Binder.clearCallingIdentity();
8995 try {
8996 return UiccController.getInstance().getCardIdForDefaultEuicc();
8997 } finally {
8998 Binder.restoreCallingIdentity(identity);
8999 }
9000 }
9001
Pengquan Meng85728fb2018-03-12 16:31:21 -07009002 /**
goneil47ffb6e2018-04-06 15:40:58 -07009003 * A test API to reload the UICC profile.
9004 *
9005 * <p>Requires that the calling app has permission
9006 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9007 * @hide
9008 */
9009 @Override
9010 public void refreshUiccProfile(int subId) {
9011 enforceModifyPermission();
9012
9013 final long identity = Binder.clearCallingIdentity();
9014 try {
9015 Phone phone = getPhone(subId);
9016 if (phone == null) {
9017 return;
9018 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009019 UiccPort uiccPort = phone.getUiccPort();
9020 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009021 return;
9022 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009023 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009024 if (uiccProfile == null) {
9025 return;
9026 }
9027 uiccProfile.refresh();
9028 } finally {
9029 Binder.restoreCallingIdentity(identity);
9030 }
9031 }
9032
9033 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009034 * Returns false if the mobile data is disabled by default, otherwise return true.
9035 */
9036 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009037 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009038 }
9039
9040 /**
9041 * Returns true if the data roaming is enabled by default, i.e the system property
9042 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9043 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9044 */
9045 private boolean getDefaultDataRoamingEnabled(int subId) {
9046 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009047 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009048 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009049 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9050 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9051 return isDataRoamingEnabled;
9052 }
9053
9054 /**
9055 * Returns the default network type for the given {@code subId}, if the default network type is
9056 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9057 */
9058 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009059 List<Integer> list = TelephonyProperties.default_network();
9060 int phoneId = mSubscriptionController.getPhoneId(subId);
9061 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9062 return list.get(phoneId);
9063 }
9064 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009065 }
fionaxua13278b2018-03-21 00:08:13 -07009066
9067 @Override
9068 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009069 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009070 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009071
9072 final long identity = Binder.clearCallingIdentity();
9073 try {
9074 final Phone phone = getPhone(subId);
9075 if (phone == null) {
9076 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9077 return;
9078 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009079 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9080 if (cpt != null) {
9081 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9082 }
9083 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009084 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9085 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009086 if (carrierPrivilegeRules == null) {
9087 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9088 } else {
9089 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009091 } finally {
9092 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009093 }
fionaxua13278b2018-03-21 00:08:13 -07009094 }
9095
9096 @Override
9097 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009098 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009099
9100 final long identity = Binder.clearCallingIdentity();
9101 try {
9102 final Phone phone = getPhone(subId);
9103 if (phone == null) {
9104 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9105 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9106 }
9107 return phone.getCarrierIdListVersion();
9108 } finally {
9109 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009110 }
fionaxua13278b2018-03-21 00:08:13 -07009111 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009112
9113 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009114 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9115 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009116 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009117 mApp, subId, callingPackage, callingFeatureId,
9118 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009119 return -1;
9120 }
9121
9122 final long identity = Binder.clearCallingIdentity();
9123 try {
9124 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9125 } finally {
9126 Binder.restoreCallingIdentity(identity);
9127 }
9128 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009129
9130 @Override
9131 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009132 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009133 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009134 mApp, subId, "getCdmaRoamingMode");
9135
9136 final long identity = Binder.clearCallingIdentity();
9137 try {
9138 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9139 } finally {
9140 Binder.restoreCallingIdentity(identity);
9141 }
9142 }
9143
9144 @Override
9145 public boolean setCdmaRoamingMode(int subId, int mode) {
9146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9147 mApp, subId, "setCdmaRoamingMode");
9148
9149 final long identity = Binder.clearCallingIdentity();
9150 try {
9151 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9152 } finally {
9153 Binder.restoreCallingIdentity(identity);
9154 }
9155 }
9156
9157 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009158 public int getCdmaSubscriptionMode(int subId) {
9159 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009160 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009161 mApp, subId, "getCdmaSubscriptionMode");
9162
9163 final long identity = Binder.clearCallingIdentity();
9164 try {
9165 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9166 } finally {
9167 Binder.restoreCallingIdentity(identity);
9168 }
9169 }
9170
9171 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009172 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9174 mApp, subId, "setCdmaSubscriptionMode");
9175
9176 final long identity = Binder.clearCallingIdentity();
9177 try {
9178 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9179 } finally {
9180 Binder.restoreCallingIdentity(identity);
9181 }
9182 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009183
sqianc5eccab2018-10-19 18:46:41 -07009184 @Override
sqian8c685422019-02-22 15:55:18 -08009185 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009186 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009188 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9189 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009190 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9191 }
9192 final long identity = Binder.clearCallingIdentity();
9193 try {
sqian854d44b2018-12-12 16:48:18 -08009194 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9195 for (Phone phone: PhoneFactory.getPhones()) {
9196 if (phone.getEmergencyNumberTracker() != null
9197 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9198 emergencyNumberListInternal.put(
9199 phone.getSubId(),
9200 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9201 }
sqian11b7a0e2018-12-05 18:48:28 -08009202 }
sqian854d44b2018-12-12 16:48:18 -08009203 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009204 } finally {
9205 Binder.restoreCallingIdentity(identity);
9206 }
sqianc5eccab2018-10-19 18:46:41 -07009207 }
9208
9209 @Override
sqian8c685422019-02-22 15:55:18 -08009210 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009211 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009212 if (!exactMatch) {
9213 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009214 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009215 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009216 }
9217 final long identity = Binder.clearCallingIdentity();
9218 try {
sqian854d44b2018-12-12 16:48:18 -08009219 for (Phone phone: PhoneFactory.getPhones()) {
9220 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009221 && phone.getEmergencyNumberTracker()
9222 .isEmergencyNumber(number, exactMatch)) {
9223 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009224 }
sqian11b7a0e2018-12-05 18:48:28 -08009225 }
9226 return false;
9227 } finally {
9228 Binder.restoreCallingIdentity(identity);
9229 }
9230 }
9231
sqianf4ca7ed2019-01-15 18:32:07 -08009232 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009233 * Start emergency callback mode for GsmCdmaPhone for testing.
9234 */
9235 @Override
9236 public void startEmergencyCallbackMode() {
9237 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9238 "startEmergencyCallbackMode");
9239 enforceModifyPermission();
9240 final long identity = Binder.clearCallingIdentity();
9241 try {
9242 for (Phone phone : PhoneFactory.getPhones()) {
9243 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9244 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9245 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9246 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9247 gsmCdmaPhone.obtainMessage(
9248 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9249 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9250 }
9251 }
9252 } finally {
9253 Binder.restoreCallingIdentity(identity);
9254 }
9255 }
9256
9257 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009258 * Update emergency number list for test mode.
9259 */
9260 @Override
9261 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9262 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9263 "updateEmergencyNumberListTestMode");
9264
9265 final long identity = Binder.clearCallingIdentity();
9266 try {
9267 for (Phone phone: PhoneFactory.getPhones()) {
9268 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9269 if (tracker != null) {
9270 tracker.executeEmergencyNumberTestModeCommand(action, num);
9271 }
9272 }
9273 } finally {
9274 Binder.restoreCallingIdentity(identity);
9275 }
9276 }
9277
9278 /**
9279 * Get the full emergency number list for test mode.
9280 */
9281 @Override
9282 public List<String> getEmergencyNumberListTestMode() {
9283 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9284 "getEmergencyNumberListTestMode");
9285
9286 final long identity = Binder.clearCallingIdentity();
9287 try {
9288 Set<String> emergencyNumbers = new HashSet<>();
9289 for (Phone phone: PhoneFactory.getPhones()) {
9290 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9291 if (tracker != null) {
9292 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9293 emergencyNumbers.add(num.getNumber());
9294 }
9295 }
9296 }
9297 return new ArrayList<>(emergencyNumbers);
9298 } finally {
9299 Binder.restoreCallingIdentity(identity);
9300 }
9301 }
9302
chen xud6b45bd2018-10-30 22:27:10 -07009303 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009304 public int getEmergencyNumberDbVersion(int subId) {
9305 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9306
9307 final long identity = Binder.clearCallingIdentity();
9308 try {
9309 final Phone phone = getPhone(subId);
9310 if (phone == null) {
9311 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9312 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9313 }
9314 return phone.getEmergencyNumberDbVersion();
9315 } finally {
9316 Binder.restoreCallingIdentity(identity);
9317 }
9318 }
9319
9320 @Override
9321 public void notifyOtaEmergencyNumberDbInstalled() {
9322 enforceModifyPermission();
9323
9324 final long identity = Binder.clearCallingIdentity();
9325 try {
9326 for (Phone phone: PhoneFactory.getPhones()) {
9327 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9328 if (tracker != null) {
9329 tracker.updateOtaEmergencyNumberDatabase();
9330 }
9331 }
9332 } finally {
9333 Binder.restoreCallingIdentity(identity);
9334 }
9335 }
9336
9337 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009338 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009339 enforceActiveEmergencySessionPermission();
9340
9341 final long identity = Binder.clearCallingIdentity();
9342 try {
9343 for (Phone phone: PhoneFactory.getPhones()) {
9344 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9345 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009346 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9347 }
9348 }
9349 } finally {
9350 Binder.restoreCallingIdentity(identity);
9351 }
9352 }
9353
9354 @Override
9355 public void resetOtaEmergencyNumberDbFilePath() {
9356 enforceActiveEmergencySessionPermission();
9357
9358 final long identity = Binder.clearCallingIdentity();
9359 try {
9360 for (Phone phone: PhoneFactory.getPhones()) {
9361 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9362 if (tracker != null) {
9363 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009364 }
9365 }
9366 } finally {
9367 Binder.restoreCallingIdentity(identity);
9368 }
9369 }
9370
9371 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009372 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9373 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9374 Phone phone = getPhone(subId);
9375 if (phone == null) {
9376 return null;
9377 }
9378 final long identity = Binder.clearCallingIdentity();
9379 try {
9380 UiccProfile profile = UiccController.getInstance()
9381 .getUiccProfileForPhone(phone.getPhoneId());
9382 if (profile != null) {
9383 return profile.getCertsFromCarrierPrivilegeAccessRules();
9384 }
9385 } finally {
9386 Binder.restoreCallingIdentity(identity);
9387 }
9388 return null;
9389 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009390
9391 /**
9392 * Enable or disable a modem stack.
9393 */
9394 @Override
9395 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9396 enforceModifyPermission();
9397
9398 final long identity = Binder.clearCallingIdentity();
9399 try {
9400 Phone phone = PhoneFactory.getPhone(slotIndex);
9401 if (phone == null) {
9402 return false;
9403 } else {
9404 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9405 }
9406 } finally {
9407 Binder.restoreCallingIdentity(identity);
9408 }
9409 }
Michelecea4cf22018-12-21 15:00:11 -08009410
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009411 /**
9412 * Whether a modem stack is enabled or not.
9413 */
9414 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009415 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9416 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009417 Phone phone = PhoneFactory.getPhone(slotIndex);
9418 if (phone == null) return false;
9419
9420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009421 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9422 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009423 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9424 }
9425
9426 final long identity = Binder.clearCallingIdentity();
9427 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009428 try {
9429 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9430 } catch (NoSuchElementException ex) {
9431 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9432 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009433 } finally {
9434 Binder.restoreCallingIdentity(identity);
9435 }
9436 }
9437
Michelecea4cf22018-12-21 15:00:11 -08009438 @Override
Michele0ea7d782019-03-19 14:58:42 -07009439 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009440 enforceModifyPermission();
9441
9442 final long identity = Binder.clearCallingIdentity();
9443 try {
9444 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009445 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009446 .commit();
9447 } finally {
9448 Binder.restoreCallingIdentity(identity);
9449 }
9450 }
9451
9452 @Override
Michele0ea7d782019-03-19 14:58:42 -07009453 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009454 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009455 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009456 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9457 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009458 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009459 }
Michelecea4cf22018-12-21 15:00:11 -08009460
9461 final long identity = Binder.clearCallingIdentity();
9462 try {
Michele0ea7d782019-03-19 14:58:42 -07009463 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009468
Michele0ea7d782019-03-19 14:58:42 -07009469 @TelephonyManager.IsMultiSimSupportedResult
9470 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009471 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9472 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9473 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009474 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9475 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009476 }
9477 // Check if the hardware supports multisim functionality. If usage of multisim is not
9478 // supported by the modem, indicate that it is restricted.
9479 PhoneCapability staticCapability =
9480 mPhoneConfigurationManager.getStaticPhoneCapability();
9481 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009482 loge("isMultiSimSupportedInternal: no static configuration available");
9483 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009484 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009485 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009486 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9487 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009488 }
9489 // Check if support of multiple SIMs is restricted by carrier
9490 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009491 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009492 }
9493
Michele0ea7d782019-03-19 14:58:42 -07009494 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009495 }
9496
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009497 /**
9498 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009499 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9500 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9501 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009502 * @param numOfSims number of active sims we want to switch to
9503 */
9504 @Override
9505 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009506 if (numOfSims == 1) {
9507 enforceModifyPermission();
9508 } else {
9509 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9510 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9511 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009512 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009513
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009514 try {
Michele30b57b22019-03-01 12:01:14 -08009515 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009516 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009517 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9518 return;
9519 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009520 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9521 } finally {
9522 Binder.restoreCallingIdentity(identity);
9523 }
9524 }
9525
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009526 @Override
9527 public boolean isApplicationOnUicc(int subId, int appType) {
9528 enforceReadPrivilegedPermission("isApplicationOnUicc");
9529 Phone phone = getPhone(subId);
9530 if (phone == null) {
9531 return false;
9532 }
9533 final long identity = Binder.clearCallingIdentity();
9534 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009535 UiccPort uiccPort = phone.getUiccPort();
9536 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009537 return false;
9538 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009539 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009540 if (uiccProfile == null) {
9541 return false;
9542 }
9543 if (TelephonyManager.APPTYPE_SIM <= appType
9544 && appType <= TelephonyManager.APPTYPE_ISIM) {
9545 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9546 }
9547 return false;
9548 } finally {
9549 Binder.restoreCallingIdentity(identity);
9550 }
9551 }
9552
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009553 /**
chen xub4baa772019-04-03 10:23:41 -07009554 * Get whether making changes to modem configurations will trigger reboot.
9555 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009556 */
9557 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009558 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9559 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009561 mApp, subId, callingPackage, callingFeatureId,
9562 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009563 return false;
9564 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009565 final long identity = Binder.clearCallingIdentity();
9566 try {
9567 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9568 } finally {
9569 Binder.restoreCallingIdentity(identity);
9570 }
9571 }
9572
Nathan Harold29f5f052019-02-15 13:41:57 -08009573 private void updateModemStateMetrics() {
9574 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9575 // TODO: check the state for each modem if the api is ready.
9576 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9577 }
9578
Pengquan Meng3889a572019-01-23 11:16:29 -08009579 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009580 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009581 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009582 // Verify that the callingPackage belongs to the calling UID
9583 mApp.getSystemService(AppOpsManager.class)
9584 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009585 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009586 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009587 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009588 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9589 if (slotInfos != null) {
9590 for (int i = 0; i < slotInfos.length; i++) {
9591 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9592 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9593 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9594 portInfo.getLogicalSlotIndex()));
9595 }
9596 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009597 }
9598 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009599 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009600 } finally {
9601 Binder.restoreCallingIdentity(identity);
9602 }
9603 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009604
9605 /**
9606 * Get the IRadio HAL Version
9607 */
9608 @Override
9609 public int getRadioHalVersion() {
9610 Phone phone = getDefaultPhone();
9611 if (phone == null) return -1;
9612 HalVersion hv = phone.getHalVersion();
9613 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9614 return hv.major * 100 + hv.minor;
9615 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009616
9617 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009618 * Get the current calling package name.
9619 * @return the current calling package name
9620 */
9621 @Override
9622 public String getCurrentPackageName() {
9623 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9624 }
9625
9626 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009627 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9628 * corresponding network requests on a subId.
9629 *
9630 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009631 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009632 * 2) APN is un-metered for this subscription, or
9633 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009634 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009635 *
9636 * @return whether data is allowed for a apn type.
9637 *
9638 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009639 */
9640 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009641 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009642 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9643 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009644
9645 // Now that all security checks passes, perform the operation as ourselves.
9646 final long identity = Binder.clearCallingIdentity();
9647 try {
9648 Phone phone = getPhone(subId);
9649 if (phone == null) return false;
9650
Jack Yu27422a52022-03-21 10:38:05 -07009651 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009652 boolean isDataEnabled;
Jack Yuabb10902022-07-31 00:43:21 -07009653 isMetered = phone.getDataNetworkController().getDataConfigManager()
9654 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9655 phone.getServiceState().getDataRoaming());
9656 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009657 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009658 } finally {
9659 Binder.restoreCallingIdentity(identity);
9660 }
9661 }
9662
9663 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009664 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009665 enforceReadPrivilegedPermission("isApnMetered");
9666
9667 // Now that all security checks passes, perform the operation as ourselves.
9668 final long identity = Binder.clearCallingIdentity();
9669 try {
9670 Phone phone = getPhone(subId);
9671 if (phone == null) return true; // By default return true.
Jack Yuabb10902022-07-31 00:43:21 -07009672 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9673 DataUtils.apnTypeToNetworkCapability(apnType),
9674 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009679
9680 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009681 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9682 int subscriptionId, IBooleanConsumer resultCallback) {
9683 enforceModifyPermission();
9684 long token = Binder.clearCallingIdentity();
9685 try {
9686 Phone phone = getPhone(subscriptionId);
9687 if (phone == null) {
9688 try {
9689 if (resultCallback != null) {
9690 resultCallback.accept(false);
9691 }
9692 } catch (RemoteException e) {
9693 // ignore
9694 }
9695 return;
9696 }
9697 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9698 Pair.create(specifiers, (x) -> {
9699 try {
9700 if (resultCallback != null) {
9701 resultCallback.accept(x);
9702 }
9703 } catch (RemoteException e) {
9704 // ignore
9705 }
9706 });
9707 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9708 } finally {
9709 Binder.restoreCallingIdentity(token);
9710 }
9711 }
9712
9713 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009714 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9715 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009716 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009717 mApp, subId, "getSystemSelectionChannels");
9718 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9719 final long identity = Binder.clearCallingIdentity();
9720 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009721 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9722 if (result instanceof IllegalStateException) {
9723 throw (IllegalStateException) result;
9724 }
9725 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009726 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9727 return specifiers;
9728 } finally {
9729 Binder.restoreCallingIdentity(identity);
9730 }
9731 }
9732
9733 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009734 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009735 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009736 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009737 }
9738
9739 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009740 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9741 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009742 if (callingPackage == null) {
9743 callingPackage = getCurrentPackageName();
9744 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009745 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9746 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009747 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9748 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009749 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9750 }
9751 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9752 Intent intent = new Intent();
9753 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9754 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9755 // Bring up choose default SMS subscription dialog right now
9756 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9757 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9758 mApp.startActivity(intent);
9759 }
chen xud5ca2d52019-05-28 15:20:57 -07009760
9761 @Override
9762 public String getMmsUAProfUrl(int subId) {
9763 //TODO investigate if this API should require proper permission check in R b/133791609
9764 final long identity = Binder.clearCallingIdentity();
9765 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009766 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9767 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9768 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9769 return carrierUAProfUrl;
9770 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009771 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9772 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009773 } finally {
9774 Binder.restoreCallingIdentity(identity);
9775 }
9776 }
9777
9778 @Override
9779 public String getMmsUserAgent(int subId) {
9780 //TODO investigate if this API should require proper permission check in R b/133791609
9781 final long identity = Binder.clearCallingIdentity();
9782 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009783 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9784 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9785 if (!TextUtils.isEmpty(carrierUserAgent)) {
9786 return carrierUserAgent;
9787 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009788 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9789 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009790 } finally {
9791 Binder.restoreCallingIdentity(identity);
9792 }
9793 }
Jack Yub07d4972019-05-28 16:12:25 -07009794
9795 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009796 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9797 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009798
Jack Yub07d4972019-05-28 16:12:25 -07009799 final long identity = Binder.clearCallingIdentity();
9800 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009801 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009802 if (phone == null) return false;
9803
Hall Liua62f5da2020-09-25 10:42:19 -07009804 switch (policy) {
9805 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yuabb10902022-07-31 00:43:21 -07009806 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
Hall Liua62f5da2020-09-25 10:42:19 -07009807 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yuabb10902022-07-31 00:43:21 -07009808 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
Hall Liua62f5da2020-09-25 10:42:19 -07009809 default:
9810 throw new IllegalArgumentException(policy + " is not a valid policy");
9811 }
Jack Yub07d4972019-05-28 16:12:25 -07009812 } finally {
9813 Binder.restoreCallingIdentity(identity);
9814 }
9815 }
9816
9817 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009818 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009819 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009820 enforceModifyPermission();
9821
changbettyd5c246e2019-12-24 15:40:37 +08009822 final long identity = Binder.clearCallingIdentity();
9823 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009824 Phone phone = getPhone(subscriptionId);
9825 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009826
Hall Liua62f5da2020-09-25 10:42:19 -07009827 switch (policy) {
9828 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yuabb10902022-07-31 00:43:21 -07009829 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
Hall Liua62f5da2020-09-25 10:42:19 -07009830 break;
9831 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yuabb10902022-07-31 00:43:21 -07009832 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
Hall Liua62f5da2020-09-25 10:42:19 -07009833 break;
9834 default:
9835 throw new IllegalArgumentException(policy + " is not a valid policy");
9836 }
changbettyd5c246e2019-12-24 15:40:37 +08009837 } finally {
9838 Binder.restoreCallingIdentity(identity);
9839 }
9840 }
9841
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009842 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009843 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009844 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9845 * otherwise.
9846 */
9847 @Override
9848 public void setCepEnabled(boolean isCepEnabled) {
9849 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9850
9851 final long identity = Binder.clearCallingIdentity();
9852 try {
9853 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9854 for (Phone phone : PhoneFactory.getPhones()) {
9855 Phone defaultPhone = phone.getImsPhone();
9856 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9857 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9858 ImsPhoneCallTracker imsPhoneCallTracker =
9859 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9860 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9861 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9862 + imsPhone.getMsisdn());
9863 }
9864 }
9865 } finally {
9866 Binder.restoreCallingIdentity(identity);
9867 }
9868 }
allenwtsu46dcc572020-01-08 18:24:03 +08009869
9870 /**
9871 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9872 *
9873 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9874 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9875 * before being read.
9876 */
9877 @Override
9878 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9879 isCompressed) {
9880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9881 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009882 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9883 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9884 }
9885 if (!isImsAvailableOnDevice()) {
9886 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9887 "IMS not available on device.");
9888 }
9889
9890 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009891 try {
Hui Wang761a6682020-10-31 05:12:53 +00009892 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9893 } finally {
9894 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009895 }
9896 }
zoey chene02881a2019-12-30 16:11:23 +08009897
9898 @Override
9899 public boolean isIccLockEnabled(int subId) {
9900 enforceReadPrivilegedPermission("isIccLockEnabled");
9901
9902 // Now that all security checks passes, perform the operation as ourselves.
9903 final long identity = Binder.clearCallingIdentity();
9904 try {
9905 Phone phone = getPhone(subId);
9906 if (phone != null && phone.getIccCard() != null) {
9907 return phone.getIccCard().getIccLockEnabled();
9908 } else {
9909 return false;
9910 }
9911 } finally {
9912 Binder.restoreCallingIdentity(identity);
9913 }
9914 }
9915
9916 /**
9917 * Set the ICC pin lock enabled or disabled.
9918 *
9919 * @return an integer representing the status of IccLock enabled or disabled in the following
9920 * three cases:
9921 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9922 * successfully.
9923 * - Positive number and zero for remaining password attempts.
9924 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9925 *
9926 */
9927 @Override
9928 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9929 enforceModifyPermission();
9930
9931 Phone phone = getPhone(subId);
9932 if (phone == null) {
9933 return 0;
9934 }
9935 // Now that all security checks passes, perform the operation as ourselves.
9936 final long identity = Binder.clearCallingIdentity();
9937 try {
9938 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9939 new Pair<Boolean, String>(enabled, password), phone, null);
9940 return attemptsRemaining;
9941
9942 } catch (Exception e) {
9943 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9944 } finally {
9945 Binder.restoreCallingIdentity(identity);
9946 }
9947 return 0;
9948 }
9949
9950 /**
9951 * Change the ICC password used in ICC pin lock.
9952 *
9953 * @return an integer representing the status of IccLock changed in the following three cases:
9954 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9955 * - Positive number and zero for remaining password attempts.
9956 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9957 *
9958 */
9959 @Override
9960 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9961 enforceModifyPermission();
9962
9963 Phone phone = getPhone(subId);
9964 if (phone == null) {
9965 return 0;
9966 }
9967 // Now that all security checks passes, perform the operation as ourselves.
9968 final long identity = Binder.clearCallingIdentity();
9969 try {
9970 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9971 new Pair<String, String>(oldPassword, newPassword), phone, null);
9972 return attemptsRemaining;
9973
9974 } catch (Exception e) {
9975 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9976 } finally {
9977 Binder.restoreCallingIdentity(identity);
9978 }
9979 return 0;
9980 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009981
9982 /**
9983 * Request for receiving user activity notification
9984 */
9985 @Override
9986 public void requestUserActivityNotification() {
9987 if (!mNotifyUserActivity.get()
9988 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9989 mNotifyUserActivity.set(true);
9990 }
9991 }
9992
9993 /**
9994 * Called when userActivity is signalled in the power manager.
9995 * This is safe to call from any thread, with any window manager locks held or not.
9996 */
9997 @Override
9998 public void userActivity() {
9999 // ***************************************
10000 // * Inherited from PhoneWindowManager *
10001 // ***************************************
10002 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10003 // WITH ITS LOCKS HELD.
10004 //
10005 // This code must be VERY careful about the locks
10006 // it acquires.
10007 // In fact, the current code acquires way too many,
10008 // and probably has lurking deadlocks.
10009
10010 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10011 throw new SecurityException("Only the OS may call notifyUserActivity()");
10012 }
10013
10014 if (mNotifyUserActivity.getAndSet(false)) {
10015 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10016 USER_ACTIVITY_NOTIFICATION_DELAY);
10017 }
10018 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010019
10020 @Override
10021 public boolean canConnectTo5GInDsdsMode() {
10022 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10023 }
Jack Yud10cdd42020-09-28 20:28:01 -070010024
10025 @Override
10026 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10027 String callingFeatureId) {
10028 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10029 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10030 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10031 }
10032
10033 Phone phone = getPhone(subId);
10034 if (phone == null) {
10035 throw new RuntimeException("phone is not available");
10036 }
10037 // Now that all security checks passes, perform the operation as ourselves.
10038 final long identity = Binder.clearCallingIdentity();
10039 try {
10040 return phone.getEquivalentHomePlmns();
10041 } finally {
10042 Binder.restoreCallingIdentity(identity);
10043 }
10044 }
Daniel Bright59e67312020-11-13 11:49:37 -080010045
10046 @Override
10047 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010048 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10049 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010050 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010051 if (radioInterfaceCapabilities == null) {
10052 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010053 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010054 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010055 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010056
Hui Wang641e81c2020-10-12 12:14:23 -070010057 @Override
10058 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10059 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010060 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10061 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10062 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10063 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10064 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010065 if (DBG) {
10066 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10067 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10068 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10069 }
10070
10071 if (!SubscriptionManager.isValidSubscriptionId(subId)
10072 || appType < TelephonyManager.APPTYPE_UNKNOWN
10073 || appType > TelephonyManager.APPTYPE_ISIM
10074 || nafUrl == null || securityProtocol == null || callback == null) {
10075 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10076 if (callback != null) {
10077 try {
10078 callback.onAuthenticationFailure(
10079 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10080 } catch (RemoteException exception) {
10081 log("Fail to notify onAuthenticationFailure due to " + exception);
10082 }
10083 return;
10084 }
10085 }
10086
10087 final long token = Binder.clearCallingIdentity();
10088 try {
10089 getGbaManager(subId).bootstrapAuthenticationRequest(
10090 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10091 forceBootStrapping, callback));
10092 } finally {
10093 Binder.restoreCallingIdentity(token);
10094 }
10095 }
10096
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010097 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010098 * Attempts to set the radio power state for all phones for thermal reason.
10099 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010100 * requested radio power state will actually be set. See {@link
10101 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10102 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010103 * @param enable {@code true} if trying to turn radio on.
10104 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10105 * false}.
10106 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010107 private boolean setRadioPowerForThermal(boolean enable) {
10108 boolean isPhoneAvailable = false;
10109 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10110 Phone phone = PhoneFactory.getPhone(i);
10111 if (phone != null) {
10112 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10113 isPhoneAvailable = true;
10114 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010115 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010116
10117 // return true if successfully informed the phone object about the thermal radio power
10118 // request.
10119 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010120 }
10121
10122 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010123 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010124 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10125 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10126 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10127 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10128 throw new IllegalArgumentException("modem does not support data throttling");
10129 }
10130
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010131 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10132 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010133 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010134 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10135 }
10136
Sarah Chinecc78c42022-03-31 21:16:48 -070010137 setDataEnabledForReason(
10138 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010139
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010140 if (isDataThrottlingSupported) {
10141 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010142 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010143 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10144 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10145 } else if (thermalMitigationResult
10146 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010147 log("Modem likely does not support data throttling on secondary carrier. Data " +
10148 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10149 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010150 }
10151 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010152 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010153
10154 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010155 }
10156
Jack Nudelman644b91a2021-03-12 14:09:48 -080010157 private static List<String> getThermalMitigationAllowlist(Context context) {
10158 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10159 for (String pckg : context.getResources()
10160 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10161 sThermalMitigationAllowlistedPackages.add(pckg);
10162 }
10163 }
10164
10165 return sThermalMitigationAllowlistedPackages;
10166 }
10167
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010168 private boolean isAnyPhoneInEmergencyState() {
10169 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10170 if (tm.isInEmergencyCall()) {
10171 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10172 return true;
10173 }
10174 for (Phone phone : PhoneFactory.getPhones()) {
10175 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10176 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10177 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10178 + phone.isInEcm());
10179 return true;
10180 }
10181 }
10182
10183 return false;
10184 }
10185
Jack Nudelman644b91a2021-03-12 14:09:48 -080010186 /**
10187 * Used by shell commands to add an authorized package name for thermal mitigation.
10188 * @param packageName name of package to be allowlisted
10189 * @param context
10190 */
10191 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10192 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10193 sThermalMitigationAllowlistedPackages.add(packageName);
10194 }
10195
10196 /**
10197 * Used by shell commands to remove an authorized package name for thermal mitigation.
10198 * @param packageName name of package to remove from allowlist
10199 * @param context
10200 */
10201 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10202 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10203 sThermalMitigationAllowlistedPackages.remove(packageName);
10204 }
10205
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010206 /**
10207 * Thermal mitigation request to control functionalities at modem.
10208 *
10209 * @param subId the id of the subscription.
10210 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010211 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010212 *
10213 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10214 */
10215 @Override
10216 @ThermalMitigationResult
10217 public int sendThermalMitigationRequest(
10218 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010219 ThermalMitigationRequest thermalMitigationRequest,
10220 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010221 enforceModifyPermission();
10222
Jack Nudelman644b91a2021-03-12 14:09:48 -080010223 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10224 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10225 .contains(callingPackage)) {
10226 throw new SecurityException("Calling package must be configured in the device config. "
10227 + "calling package: " + callingPackage);
10228 }
10229
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010230 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10231 final long identity = Binder.clearCallingIdentity();
10232
10233 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10234 try {
10235 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10236 switch (thermalMitigationAction) {
10237 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10238 thermalMitigationResult =
10239 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010240 thermalMitigationRequest.getDataThrottlingRequest(),
10241 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010242 break;
10243 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10244 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10245 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10246 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10247 }
10248
10249 // Ensure that radio is on. If not able to power on due to phone being
10250 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010251 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010252 thermalMitigationResult =
10253 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10254 break;
10255 }
10256
10257 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010258 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010259 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10260 break;
10261 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10262 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10263 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10264 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10265 }
10266
10267 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10268 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010269 Phone phone = getPhone(subId);
10270 if (phone == null) {
10271 thermalMitigationResult =
10272 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10273 break;
10274 }
10275
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010276 TelephonyConnectionService service =
10277 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010278 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010279 Log.e(LOG_TAG, "An emergency call is pending");
10280 thermalMitigationResult =
10281 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10282 break;
10283 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010284 thermalMitigationResult =
10285 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10286 break;
10287 }
10288 } else {
10289 thermalMitigationResult =
10290 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10291 break;
10292 }
10293
10294 // Turn radio off. If not able to power off due to phone being unavailable,
10295 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010296 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010297 thermalMitigationResult =
10298 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10299 break;
10300 }
10301 thermalMitigationResult =
10302 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10303 break;
10304 default:
10305 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10306 + "not exist. Requested action: " + thermalMitigationAction);
10307 }
10308 } catch (IllegalArgumentException e) {
10309 throw e;
10310 } catch (Exception e) {
10311 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10312 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10313 } finally {
10314 Binder.restoreCallingIdentity(identity);
10315 }
10316
10317 if (DBG) {
10318 log("thermalMitigationRequest returning with thermalMitigationResult: "
10319 + thermalMitigationResult);
10320 }
10321
10322 return thermalMitigationResult;
10323 }
Hui Wang641e81c2020-10-12 12:14:23 -070010324
10325 /**
10326 * Set the GbaService Package Name that Telephony will bind to.
10327 *
10328 * @param subId The sim that the GbaService is associated with.
10329 * @param packageName The name of the package to be replaced with.
10330 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10331 */
10332 @Override
10333 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10334 enforceModifyPermission();
10335
10336 final long identity = Binder.clearCallingIdentity();
10337 try {
10338 return getGbaManager(subId).overrideServicePackage(packageName);
10339 } finally {
10340 Binder.restoreCallingIdentity(identity);
10341 }
10342 }
10343
10344 /**
10345 * Return the package name of the currently bound GbaService.
10346 *
10347 * @param subId The sim that the GbaService is associated with.
10348 * @return the package name of the GbaService configuration, null if GBA is not supported.
10349 */
10350 @Override
10351 public String getBoundGbaService(int subId) {
10352 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10353
10354 final long identity = Binder.clearCallingIdentity();
10355 try {
10356 return getGbaManager(subId).getServicePackage();
10357 } finally {
10358 Binder.restoreCallingIdentity(identity);
10359 }
10360 }
10361
10362 /**
10363 * Set the release time for telephony to unbind GbaService.
10364 *
10365 * @param subId The sim that the GbaService is associated with.
10366 * @param interval The release time to unbind GbaService by millisecond.
10367 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10368 */
10369 @Override
10370 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10371 enforceModifyPermission();
10372
10373 final long identity = Binder.clearCallingIdentity();
10374 try {
10375 return getGbaManager(subId).overrideReleaseTime(interval);
10376 } finally {
10377 Binder.restoreCallingIdentity(identity);
10378 }
10379 }
10380
10381 /**
10382 * Return the release time for telephony to unbind GbaService.
10383 *
10384 * @param subId The sim that the GbaService is associated with.
10385 * @return The release time to unbind GbaService by millisecond.
10386 */
10387 @Override
10388 public int getGbaReleaseTime(int subId) {
10389 enforceReadPrivilegedPermission("getGbaReleaseTime");
10390
10391 final long identity = Binder.clearCallingIdentity();
10392 try {
10393 return getGbaManager(subId).getReleaseTime();
10394 } finally {
10395 Binder.restoreCallingIdentity(identity);
10396 }
10397 }
10398
10399 private GbaManager getGbaManager(int subId) {
10400 GbaManager instance = GbaManager.getInstance(subId);
10401 if (instance == null) {
10402 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10403 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10404 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10405 }
10406 return instance;
10407 }
Hui Wang761a6682020-10-31 05:12:53 +000010408
10409 /**
10410 * indicate whether the device and the carrier can support
10411 * RCS VoLTE single registration.
10412 */
10413 @Override
10414 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010415 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10416 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10417 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10418 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010419
10420 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10421 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10422 }
10423
10424 final long identity = Binder.clearCallingIdentity();
10425 try {
10426 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10427 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010428 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10429 if (isCapable != null) {
10430 return isCapable;
10431 }
Hui Wang761a6682020-10-31 05:12:53 +000010432 }
Hui Wang67af90e2021-06-04 16:57:15 -070010433 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10434 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010435 } finally {
10436 Binder.restoreCallingIdentity(identity);
10437 }
10438 }
10439
10440 /**
10441 * Register RCS provisioning callback.
10442 */
10443 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010444 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010445 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010446 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010447 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010448 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10449 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010450
10451 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10452 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10453 }
10454 if (!isImsAvailableOnDevice()) {
10455 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10456 "IMS not available on device.");
10457 }
10458
10459 final long identity = Binder.clearCallingIdentity();
10460 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010461 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010462 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010463 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10464 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010465 }
Hui Wang761a6682020-10-31 05:12:53 +000010466 } finally {
10467 Binder.restoreCallingIdentity(identity);
10468 }
10469 }
10470
10471 /**
10472 * Unregister RCS provisioning callback.
10473 */
10474 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010475 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010476 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010477 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010478 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010479 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10480 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010481
10482 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10483 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10484 }
10485 if (!isImsAvailableOnDevice()) {
10486 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10487 "IMS not available on device.");
10488 }
10489
10490 final long identity = Binder.clearCallingIdentity();
10491 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010492 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010493 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010494 } finally {
10495 Binder.restoreCallingIdentity(identity);
10496 }
10497 }
10498
10499 /**
10500 * trigger RCS reconfiguration.
10501 */
10502 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010503 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10504 "triggerRcsReconfiguration",
10505 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010506
10507 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10508 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10509 }
10510 if (!isImsAvailableOnDevice()) {
10511 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10512 "IMS not available on device.");
10513 }
10514
10515 final long identity = Binder.clearCallingIdentity();
10516 try {
10517 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10518 } finally {
10519 Binder.restoreCallingIdentity(identity);
10520 }
10521 }
10522
10523 /**
10524 * Provide the client configuration parameters of the RCS application.
10525 */
10526 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010527 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10528 "setRcsClientConfiguration",
10529 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010530
10531 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10532 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10533 }
10534 if (!isImsAvailableOnDevice()) {
10535 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10536 "IMS not available on device.");
10537 }
10538
10539 final long identity = Binder.clearCallingIdentity();
10540
10541 try {
10542 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10543 if (configBinder == null) {
10544 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010545 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10546 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010547 } else {
10548 configBinder.setRcsClientConfiguration(rcc);
10549 }
joonhunshin3e154242021-09-17 06:33:39 +000010550
10551 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10552 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010553 } catch (RemoteException e) {
10554 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010555 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10556 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010557 } finally {
10558 Binder.restoreCallingIdentity(identity);
10559 }
10560 }
10561
10562 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010563 * Enables or disables the test mode for RCS VoLTE single registration.
10564 */
10565 @Override
10566 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10567 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10568 "setRcsSingleRegistrationTestModeEnabled");
10569
10570 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10571 }
10572
10573 /**
10574 * Gets the test mode for RCS VoLTE single registration.
10575 */
10576 @Override
10577 public boolean getRcsSingleRegistrationTestModeEnabled() {
10578 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10579 "getRcsSingleRegistrationTestModeEnabled");
10580
10581 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10582 }
10583
10584 /**
Hui Wang761a6682020-10-31 05:12:53 +000010585 * Overrides the config of RCS VoLTE single registration enabled for the device.
10586 */
10587 @Override
10588 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10589 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10590 "setDeviceSingleRegistrationEnabledOverride");
10591 enforceModifyPermission();
10592
10593 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10594 : Boolean.parseBoolean(enabledStr);
10595 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010596 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010597 }
10598
10599 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010600 * Sends a device to device communication message. Only usable via shell.
10601 * @param message message to send.
10602 * @param value message value.
10603 */
10604 @Override
10605 public void sendDeviceToDeviceMessage(int message, int value) {
10606 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010607 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010608 enforceModifyPermission();
10609
10610 final long identity = Binder.clearCallingIdentity();
10611 try {
10612 TelephonyConnectionService service =
10613 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10614 if (service == null) {
10615 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10616 return;
10617 }
10618 service.sendTestDeviceToDeviceMessage(message, value);
10619 } finally {
10620 Binder.restoreCallingIdentity(identity);
10621 }
10622 }
10623
Tyler Gunnbabbda02021-02-10 11:05:02 -080010624 /**
10625 * Sets the specified device to device transport active.
10626 * @param transport The transport to set active.
10627 */
10628 @Override
10629 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10630 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10631 "setActiveDeviceToDeviceTransport");
10632 enforceModifyPermission();
10633
10634 final long identity = Binder.clearCallingIdentity();
10635 try {
10636 TelephonyConnectionService service =
10637 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10638 if (service == null) {
10639 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10640 return;
10641 }
10642 service.setActiveDeviceToDeviceTransport(transport);
10643 } finally {
10644 Binder.restoreCallingIdentity(identity);
10645 }
10646 }
Tyler Gunn92479152021-01-20 16:30:10 -080010647
Tyler Gunnd4339262021-05-03 14:46:49 -070010648 @Override
10649 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10650 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10651 "setDeviceToDeviceForceEnabled");
10652
10653 final long identity = Binder.clearCallingIdentity();
10654 try {
10655 Arrays.stream(PhoneFactory.getPhones()).forEach(
10656 p -> {
10657 Phone thePhone = p.getImsPhone();
10658 if (thePhone != null && thePhone instanceof ImsPhone) {
10659 ImsPhone imsPhone = (ImsPhone) thePhone;
10660 CallTracker tracker = imsPhone.getCallTracker();
10661 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10662 ImsPhoneCallTracker imsPhoneCallTracker =
10663 (ImsPhoneCallTracker) tracker;
10664 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10665 }
10666 }
10667 }
10668 );
10669 } finally {
10670 Binder.restoreCallingIdentity(identity);
10671 }
10672 }
10673
Tyler Gunn92479152021-01-20 16:30:10 -080010674 /**
Hui Wang761a6682020-10-31 05:12:53 +000010675 * Gets the config of RCS VoLTE single registration enabled for the device.
10676 */
10677 @Override
10678 public boolean getDeviceSingleRegistrationEnabled() {
10679 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10680 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10681 }
10682
10683 /**
10684 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10685 */
10686 @Override
10687 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10688 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10689 "setCarrierSingleRegistrationEnabledOverride");
10690 enforceModifyPermission();
10691
10692 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10693 : Boolean.parseBoolean(enabledStr);
10694 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10695 subId, enabled);
10696 }
10697
10698 /**
10699 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10700 */
10701 @Override
10702 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10703 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10704 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10705 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010706
10707 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010708 * Overrides the ims feature validation result
10709 */
10710 @Override
10711 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10712 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10713 "setImsFeatureValidationOverride");
10714
10715 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10716 : Boolean.parseBoolean(enabledStr);
10717 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10718 subId, enabled);
10719 }
10720
10721 /**
10722 * Gets the ims feature validation override value
10723 */
10724 @Override
10725 public boolean getImsFeatureValidationOverride(int subId) {
10726 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10727 "getImsFeatureValidationOverride");
10728 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10729 }
10730
10731 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010732 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10733 * their mobile plan.
10734 */
10735 @Override
10736 public String getMobileProvisioningUrl() {
10737 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10738 final long identity = Binder.clearCallingIdentity();
10739 try {
10740 return getDefaultPhone().getMobileProvisioningUrl();
10741 } finally {
10742 Binder.restoreCallingIdentity(identity);
10743 }
10744 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010745
James.cf Linbcdf8b32021-01-14 16:44:13 +080010746 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010747 * Get the EAB contact from the EAB database.
10748 */
10749 @Override
10750 public String getContactFromEab(String contact) {
10751 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10752 enforceModifyPermission();
10753 final long identity = Binder.clearCallingIdentity();
10754 try {
10755 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10756 } finally {
10757 Binder.restoreCallingIdentity(identity);
10758 }
10759 }
10760
10761 /**
Calvin Pana1434322021-07-01 19:27:01 +080010762 * Get the EAB capability from the EAB database.
10763 */
10764 @Override
10765 public String getCapabilityFromEab(String contact) {
10766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10767 enforceModifyPermission();
10768 final long identity = Binder.clearCallingIdentity();
10769 try {
10770 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10771 } finally {
10772 Binder.restoreCallingIdentity(identity);
10773 }
10774 }
10775
10776 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010777 * Remove the EAB contacts from the EAB database.
10778 */
10779 @Override
10780 public int removeContactFromEab(int subId, String contacts) {
10781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10782 enforceModifyPermission();
10783 final long identity = Binder.clearCallingIdentity();
10784 try {
10785 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10786 } finally {
10787 Binder.restoreCallingIdentity(identity);
10788 }
10789 }
10790
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010791 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010792 public boolean getDeviceUceEnabled() {
10793 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10794 final long identity = Binder.clearCallingIdentity();
10795 try {
10796 return mApp.getDeviceUceEnabled();
10797 } finally {
10798 Binder.restoreCallingIdentity(identity);
10799 }
10800 }
10801
10802 @Override
10803 public void setDeviceUceEnabled(boolean isEnabled) {
10804 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10805 final long identity = Binder.clearCallingIdentity();
10806 try {
10807 mApp.setDeviceUceEnabled(isEnabled);
10808 } finally {
10809 Binder.restoreCallingIdentity(identity);
10810 }
10811 }
10812
Brad Ebinger14d467f2021-02-12 06:18:28 +000010813 /**
10814 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10815 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10816 */
10817 // Used for SHELL command only right now.
10818 @Override
10819 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10820 List<String> featureTags) {
10821 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10822 "addUceRegistrationOverrideShell");
10823 final long identity = Binder.clearCallingIdentity();
10824 try {
10825 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10826 new ArraySet<>(featureTags));
10827 } catch (ImsException e) {
10828 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10829 } finally {
10830 Binder.restoreCallingIdentity(identity);
10831 }
10832 }
10833
10834 /**
10835 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10836 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10837 */
10838 // Used for SHELL command only right now.
10839 @Override
10840 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10841 List<String> featureTags) {
10842 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10843 "removeUceRegistrationOverrideShell");
10844 final long identity = Binder.clearCallingIdentity();
10845 try {
10846 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10847 new ArraySet<>(featureTags));
10848 } catch (ImsException e) {
10849 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10850 } finally {
10851 Binder.restoreCallingIdentity(identity);
10852 }
10853 }
10854
10855 /**
10856 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10857 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10858 */
10859 // Used for SHELL command only right now.
10860 @Override
10861 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10862 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10863 "clearUceRegistrationOverrideShell");
10864 final long identity = Binder.clearCallingIdentity();
10865 try {
10866 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10867 } catch (ImsException e) {
10868 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10869 } finally {
10870 Binder.restoreCallingIdentity(identity);
10871 }
10872 }
10873
10874 /**
10875 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10876 */
10877 // Used for SHELL command only right now.
10878 @Override
10879 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10880 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10881 "getLatestRcsContactUceCapabilityShell");
10882 final long identity = Binder.clearCallingIdentity();
10883 try {
10884 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10885 } catch (ImsException e) {
10886 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10887 } finally {
10888 Binder.restoreCallingIdentity(identity);
10889 }
10890 }
10891
10892 /**
10893 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10894 * device does not have an active PUBLISH.
10895 */
10896 // Used for SHELL command only right now.
10897 @Override
10898 public String getLastUcePidfXmlShell(int subId) {
10899 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10900 final long identity = Binder.clearCallingIdentity();
10901 try {
10902 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10903 } catch (ImsException e) {
10904 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10905 } finally {
10906 Binder.restoreCallingIdentity(identity);
10907 }
10908 }
10909
James.cf Line8713a42021-04-29 16:04:26 +080010910 /**
10911 * Remove UCE requests cannot be sent to the network status.
10912 */
10913 // Used for SHELL command only right now.
10914 @Override
10915 public boolean removeUceRequestDisallowedStatus(int subId) {
10916 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10917 final long identity = Binder.clearCallingIdentity();
10918 try {
10919 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10920 } catch (ImsException e) {
10921 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10922 } finally {
10923 Binder.restoreCallingIdentity(identity);
10924 }
10925 }
10926
James.cf Lin18bb9002021-05-25 01:37:38 +080010927 /**
10928 * Remove UCE requests cannot be sent to the network status.
10929 */
10930 // Used for SHELL command only.
10931 @Override
10932 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10933 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10934 final long identity = Binder.clearCallingIdentity();
10935 try {
10936 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10937 } catch (ImsException e) {
10938 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10939 } finally {
10940 Binder.restoreCallingIdentity(identity);
10941 }
10942 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010943
James.cf Lin4b784aa2021-01-31 03:25:15 +080010944 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010945 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10946 String callingPackage) {
10947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10948 mApp, subId, "setSignalStrengthUpdateRequest");
10949
10950 final int callingUid = Binder.getCallingUid();
10951 // Verify that tha callingPackage belongs to the calling UID
10952 mApp.getSystemService(AppOpsManager.class)
10953 .checkPackage(callingUid, callingPackage);
10954
Rambo Wang3607f502021-02-01 21:51:40 -080010955 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010956
10957 final long identity = Binder.clearCallingIdentity();
10958 try {
10959 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10960 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10961
10962 if (result instanceof IllegalStateException) {
10963 throw (IllegalStateException) result;
10964 }
10965 } finally {
10966 Binder.restoreCallingIdentity(identity);
10967 }
10968 }
10969
10970 @Override
10971 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10972 String callingPackage) {
10973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10974 mApp, subId, "clearSignalStrengthUpdateRequest");
10975
10976 final int callingUid = Binder.getCallingUid();
10977 // Verify that tha callingPackage belongs to the calling UID
10978 mApp.getSystemService(AppOpsManager.class)
10979 .checkPackage(callingUid, callingPackage);
10980
10981 final long identity = Binder.clearCallingIdentity();
10982 try {
10983 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10984 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10985
10986 if (result instanceof IllegalStateException) {
10987 throw (IllegalStateException) result;
10988 }
10989 } finally {
10990 Binder.restoreCallingIdentity(identity);
10991 }
10992 }
10993
Rambo Wang3607f502021-02-01 21:51:40 -080010994 private static void validateSignalStrengthUpdateRequest(Context context,
10995 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010996 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10997 // phone/system process do not have further restriction on request
10998 return;
10999 }
11000
11001 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011002 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011003 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011004 context.enforceCallingOrSelfPermission(
11005 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11006 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011007 }
11008
11009 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11010 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11011 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11012 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11013 || info.isEnabled()) {
11014 throw new IllegalArgumentException(
11015 "Only system can set hide fields in SignalThresholdInfo");
11016 }
11017
11018 // Thresholds length for each RAN need in range. This has been validated in
11019 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11020 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11021 final int[] thresholds = info.getThresholds();
11022 Objects.requireNonNull(thresholds);
11023 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11024 || thresholds.length
11025 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11026 throw new IllegalArgumentException(
11027 "thresholds length is out of range: " + thresholds.length);
11028 }
11029 }
11030 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011031
11032 /**
11033 * Gets the current phone capability.
11034 *
11035 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11036 * @return the PhoneCapability which describes the data connection capability of modem.
11037 * It's used to evaluate possible phone config change, for example from single
11038 * SIM device to multi-SIM device.
11039 */
11040 @Override
11041 public PhoneCapability getPhoneCapability() {
11042 enforceReadPrivilegedPermission("getPhoneCapability");
11043 final long identity = Binder.clearCallingIdentity();
11044 try {
11045 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11046 } finally {
11047 Binder.restoreCallingIdentity(identity);
11048 }
11049 }
Michele Berionne5e411512020-11-13 02:36:59 +000011050
11051 /**
11052 * Prepare TelephonyManager for an unattended reboot. The reboot is
11053 * required to be done shortly after the API is invoked.
11054 */
11055 @Override
11056 @TelephonyManager.PrepareUnattendedRebootResult
11057 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011058 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011059 enforceRebootPermission();
11060
11061 final long identity = Binder.clearCallingIdentity();
11062 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011063 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011064 } finally {
11065 Binder.restoreCallingIdentity(identity);
11066 }
11067 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011068
11069 /**
11070 * Request to get the current slicing configuration including URSP rules and
11071 * NSSAIs (configured, allowed and rejected).
11072 *
11073 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11074 */
11075 @Override
11076 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011077 TelephonyPermissions
11078 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11079 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011080
11081 final long identity = Binder.clearCallingIdentity();
11082 try {
11083 Phone phone = getDefaultPhone();
11084 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11085 } finally {
11086 Binder.restoreCallingIdentity(identity);
11087 }
11088 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011089
11090 /**
11091 * Register an IMS connection state callback
11092 */
11093 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011094 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11095 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011096 if (feature == ImsFeature.FEATURE_MMTEL) {
11097 // ImsMmTelManager
11098 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11099 TelephonyPermissions
11100 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11101 mApp, subId, "registerImsStateCallback");
11102 } else if (feature == ImsFeature.FEATURE_RCS) {
11103 // ImsRcsManager or SipDelegateManager
11104 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11105 Binder.getCallingUid(), "registerImsStateCallback",
11106 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11107 Manifest.permission.READ_PRECISE_PHONE_STATE,
11108 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11109 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11110 }
11111
11112 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11113 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11114 "IMS not available on device.");
11115 }
11116
11117 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11118 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11119 }
11120
11121 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11122 if (controller == null) {
11123 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11124 "IMS not available on device.");
11125 }
11126
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011127 if (callingPackage == null) {
11128 callingPackage = getCurrentPackageName();
11129 }
11130
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011131 final long token = Binder.clearCallingIdentity();
11132 try {
11133 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011134 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011135 } catch (ImsException e) {
11136 throw new ServiceSpecificException(e.getCode());
11137 } finally {
11138 Binder.restoreCallingIdentity(token);
11139 }
11140 }
11141
11142 /**
11143 * Unregister an IMS connection state callback
11144 */
11145 @Override
11146 public void unregisterImsStateCallback(IImsStateCallback cb) {
11147 final long token = Binder.clearCallingIdentity();
11148 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11149 if (controller == null) {
11150 return;
11151 }
11152 try {
11153 controller.unregisterImsStateCallback(cb);
11154 } finally {
11155 Binder.restoreCallingIdentity(token);
11156 }
11157 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011158
11159 /**
11160 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11161 *
11162 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11163 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11164 * SecurityException.
11165 * If there is current registered network this value will be same as the registered cell
11166 * identity. If the device goes out of service the previous cell identity is cached and
11167 * will be returned. If the cache age of the Cell identity is more than 24 hours
11168 * it will be cleared and null will be returned.
11169 *
11170 */
11171 @Override
11172 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11173 String callingFeatureId) {
11174 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11175 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11176 LocationAccessPolicy.checkLocationPermission(mApp,
11177 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11178 .setCallingPackage(callingPackage)
11179 .setCallingFeatureId(callingFeatureId)
11180 .setCallingPid(Binder.getCallingPid())
11181 .setCallingUid(Binder.getCallingUid())
11182 .setMethod("getLastKnownCellIdentity")
11183 .setLogAsInfo(true)
11184 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11185 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11186 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11187 .build());
11188
11189 boolean hasFinePermission =
11190 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11191 if (!hasFinePermission
11192 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11193 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011194 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011195 }
11196
11197 final long identity = Binder.clearCallingIdentity();
11198 try {
11199 Phone phone = getPhone(subId);
11200 if (phone == null) return null;
11201 ServiceStateTracker sst = phone.getServiceStateTracker();
11202 if (sst == null) return null;
11203 return sst.getLastKnownCellIdentity();
11204 } finally {
11205 Binder.restoreCallingIdentity(identity);
11206 }
11207 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011208
jimsun3b9ccac2021-10-26 15:01:23 +080011209 /**
11210 * Sets the modem service class Name that Telephony will bind to.
11211 *
11212 * @param serviceName The class name of the modem service.
11213 * @return true if the operation is succeed, otherwise false.
11214 */
11215 public boolean setModemService(String serviceName) {
11216 Log.d(LOG_TAG, "setModemService - " + serviceName);
11217 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11219 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11220 "setModemService");
11221 return mPhoneConfigurationManager.setModemService(serviceName);
11222 }
11223
11224 /**
11225 * Return the class name of the currently bounded modem service.
11226 *
11227 * @return the class name of the modem service.
11228 */
11229 public String getModemService() {
11230 String result;
11231 Log.d(LOG_TAG, "getModemService");
11232 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11233 TelephonyPermissions
11234 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11235 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11236 "getModemService");
11237 result = mPhoneConfigurationManager.getModemService();
11238 Log.d(LOG_TAG, "result = " + result);
11239 return result;
11240 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011241
11242 @Override
11243 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11244 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11245 mApp.enforceCallingOrSelfPermission(
11246 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11247 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11248
11249 final long identity = Binder.clearCallingIdentity();
11250 try {
11251 Phone phone = getPhone(subId);
11252 if (phone == null) return;
11253 phone.setVoiceServiceStateOverride(hasService);
11254 } finally {
11255 Binder.restoreCallingIdentity(identity);
11256 }
11257 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011258
11259 /**
11260 * set removable eSIM as default eUICC.
11261 *
11262 * @hide
11263 */
11264 @Override
11265 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11266 enforceModifyPermission();
11267 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11268
11269 final long identity = Binder.clearCallingIdentity();
11270 try {
11271 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11272 } finally {
11273 Binder.restoreCallingIdentity(identity);
11274 }
11275 }
11276
11277 /**
11278 * Returns whether the removable eSIM is default eUICC or not.
11279 *
11280 * @hide
11281 */
11282 @Override
11283 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11284 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11285 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11286
11287 final long identity = Binder.clearCallingIdentity();
11288 try {
11289 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11290 } finally {
11291 Binder.restoreCallingIdentity(identity);
11292 }
11293 }
11294
11295
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011296}