blob: c953de5685653dd6e3eef453bbd04e27e3a7af5c [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070034import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000035import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080036import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080075import android.telephony.AccessNetworkConstants;
76import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070077import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070078import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080079import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080080import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070081import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080082import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070083import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080084import android.telephony.CellIdentityCdma;
85import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070087import android.telephony.CellInfoGsm;
88import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070089import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080090import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070091import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070092import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070093import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080094import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070095import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080096import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070097import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080098import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080099import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700100import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800101import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800103import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800104import android.telephony.SignalStrengthUpdateRequest;
105import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800106import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800107import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800108import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700109import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700110import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800111import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800112import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800113import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000114import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000115import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000116import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700117import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700118import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800119import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800120import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700121import android.telephony.gba.GbaAuthRequest;
122import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700123import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000126import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700127import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000128import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700129import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800130import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700131import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800132import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700133import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000134import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700135import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800136import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800137import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700140import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800142import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800143
Andrew Lee312e8172014-10-23 17:01:36 -0700144import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800145import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800146import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800147import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700150import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700151import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800152import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800153import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800156import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700157import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800158import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800159import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800160import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700161import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000162import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800164import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800166import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800167import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700168import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700169import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700170import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700172import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800173import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700174import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700175import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700176import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700177import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800178import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800179import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700180import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700181import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700182import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800183import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800184import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800185import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700186import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700188import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800189import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700190import com.android.internal.telephony.imsphone.ImsPhone;
191import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000192import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800193import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700194import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195import com.android.internal.telephony.uicc.IccIoResult;
196import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800197import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700198import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000201import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800202import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000203import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800204import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700205import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700206import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800207import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800208import com.android.phone.callcomposer.CallComposerPictureManager;
209import com.android.phone.callcomposer.CallComposerPictureTransfer;
210import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700211import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700212import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800213import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700214import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700215import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800216import com.android.services.telephony.TelecomAccountRegistry;
217import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800218import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800219
Hall Liu82694d52020-12-11 18:22:04 -0800220import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700221import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.io.IOException;
223import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700224import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800226import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000227import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800228import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800229import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800230import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800231import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100232import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800233import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700234import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800235import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800236import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800237import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800238import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800239import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240
241/**
242 * Implementation of the ITelephony interface.
243 */
Santos Cordon117fee72014-05-16 17:56:12 -0700244public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245 private static final String LOG_TAG = "PhoneInterfaceManager";
246 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
247 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800248 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249
250 // Message codes used with mMainThreadHandler
251 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700252 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
253 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700254 private static final int CMD_OPEN_CHANNEL = 9;
255 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
256 private static final int CMD_CLOSE_CHANNEL = 11;
257 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800258 private static final int CMD_NV_READ_ITEM = 13;
259 private static final int EVENT_NV_READ_ITEM_DONE = 14;
260 private static final int CMD_NV_WRITE_ITEM = 15;
261 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
262 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
263 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700264 private static final int CMD_RESET_MODEM_CONFIG = 19;
265 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800266 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
267 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800268 private static final int CMD_SEND_ENVELOPE = 25;
269 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000270 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
271 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700272 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
273 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
274 private static final int CMD_EXCHANGE_SIM_IO = 31;
275 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800276 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
277 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700278 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
279 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700280 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
281 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700282 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
283 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
284 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
285 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700286 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
287 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
288 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
289 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700290 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800291 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
292 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000293 private static final int CMD_SWITCH_SLOTS = 50;
294 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700295 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
296 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
297 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
298 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
299 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
300 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
301 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
302 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700303 private static final int CMD_GET_ALL_CELL_INFO = 60;
304 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
305 private static final int CMD_GET_CELL_LOCATION = 62;
306 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700307 private static final int CMD_MODEM_REBOOT = 64;
308 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700309 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
310 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800311 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
312 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700313 private static final int CMD_GET_MODEM_STATUS = 70;
314 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700315 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
316 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700317 private static final int CMD_ERASE_MODEM_CONFIG = 74;
318 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800319 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
320 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
321 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
322 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800323 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
324 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800325 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800326 private static final int CMD_GET_CALL_FORWARDING = 83;
327 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
328 private static final int CMD_SET_CALL_FORWARDING = 85;
329 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
330 private static final int CMD_GET_CALL_WAITING = 87;
331 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
332 private static final int CMD_SET_CALL_WAITING = 89;
333 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700334 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
335 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
336 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
337 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700338 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
339 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800340 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
341 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800342 private static final int CMD_SET_DATA_THROTTLING = 99;
343 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800344 private static final int CMD_SET_SIM_POWER = 101;
345 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800346 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
347 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
348 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
349 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800350 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
351 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000352 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800353 private static final int CMD_GET_SLICING_CONFIG = 110;
354 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800355 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700356 private static final int CMD_ENABLE_VONR = 113;
357 private static final int EVENT_ENABLE_VONR_DONE = 114;
358 private static final int CMD_IS_VONR_ENABLED = 115;
359 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800361 // Parameters of select command.
362 private static final int SELECT_COMMAND = 0xA4;
363 private static final int SELECT_P1 = 0x04;
364 private static final int SELECT_P2 = 0;
365 private static final int SELECT_P3 = 0x10;
366
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 /** The singleton instance. */
368 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800369 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Wink Saville3ab207e2014-11-20 13:07:20 -0800371 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800373 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700374 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700376 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800378 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700380 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800381 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000382 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383
Peter Wangdafb9ac2020-01-15 14:13:38 -0800384 /** User Activity */
385 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800386 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
387
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700388 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
389
Derek Tan97ebb422014-09-05 16:55:38 -0700390 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
391 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800392 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800393 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700394
Michelecea4cf22018-12-21 15:00:11 -0800395 // String to store multi SIM allowed
396 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
397
Derek Tan740e1672017-06-27 14:56:27 -0700398 // The AID of ISD-R.
399 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
400
yinxub1bed742017-04-17 11:45:04 -0700401 private NetworkScanRequestTracker mNetworkScanRequestTracker;
402
David Kelly5e06a7f2018-03-12 14:10:59 +0000403 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
404 private static final int MANUFACTURER_CODE_LENGTH = 8;
405
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800406 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800407 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800408
Derek Tan89e89d42014-07-08 17:00:10 -0700409 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700410 * Experiment flag to enable erase modem config on reset network, default value is false
411 */
412 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
413 "reset_network_erase_modem_config_enabled";
414
Rambo Wang0f050d82021-02-12 11:43:36 -0800415 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800416
sandeepjsb6c87872021-09-27 15:34:44 +0000417 /**
418 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
419 * one ICCID active at the same time.
420 * Apps should use below API signatures if targeting SDK is T and beyond.
421 *
422 * @hide
423 */
424 @ChangeId
425 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
426 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800427
Naina Nallurid63128d2019-09-17 14:10:30 -0700428 /**
Chen Xu540470b2021-12-14 17:15:47 -0800429 * Apps targeting on Android T and beyond will get exception whenever icc close channel
430 * operation fails.
431 */
432 @ChangeId
433 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
434 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
435
436 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 * A request object to use for transmitting data to an ICC.
438 */
439 private static final class IccAPDUArgument {
440 public int channel, cla, command, p1, p2, p3;
441 public String data;
442
443 public IccAPDUArgument(int channel, int cla, int command,
444 int p1, int p2, int p3, String data) {
445 this.channel = channel;
446 this.cla = cla;
447 this.command = command;
448 this.p1 = p1;
449 this.p2 = p2;
450 this.p3 = p3;
451 this.data = data;
452 }
453 }
454
455 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700456 * A request object to use for transmitting data to an ICC.
457 */
458 private static final class ManualNetworkSelectionArgument {
459 public OperatorInfo operatorInfo;
460 public boolean persistSelection;
461
462 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
463 this.operatorInfo = operatorInfo;
464 this.persistSelection = persistSelection;
465 }
466 }
467
468 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
470 * request after sending. The main thread will notify the request when it is complete.
471 */
472 private static final class MainThreadRequest {
473 /** The argument to use for the request */
474 public Object argument;
475 /** The result of the request that is run on the main thread */
476 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800477 // The subscriber id that this request applies to. Defaults to
478 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
479 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480
Nathan Harold92bed182018-10-12 18:16:49 -0700481 // In cases where subId is unavailable, the caller needs to specify the phone.
482 public Phone phone;
483
vagdeviaf9a5b92018-08-15 16:01:53 -0700484 public WorkSource workSource;
485
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 public MainThreadRequest(Object argument) {
487 this.argument = argument;
488 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800489
Nathan Harold92bed182018-10-12 18:16:49 -0700490 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
491 this.argument = argument;
492 if (phone != null) {
493 this.phone = phone;
494 }
495 this.workSource = workSource;
496 }
497
vagdeviaf9a5b92018-08-15 16:01:53 -0700498 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800499 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800500 if (subId != null) {
501 this.subId = subId;
502 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700503 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505 }
506
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800507 private static final class IncomingThirdPartyCallArgs {
508 public final ComponentName component;
509 public final String callId;
510 public final String callerDisplayName;
511
512 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
513 String callerDisplayName) {
514 this.component = component;
515 this.callId = callId;
516 this.callerDisplayName = callerDisplayName;
517 }
518 }
519
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 /**
521 * A handler that processes messages on the main thread in the phone process. Since many
522 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
523 * inbound binder threads to the main thread in the phone process. The Binder thread
524 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
525 * on, which will be notified when the operation completes and will contain the result of the
526 * request.
527 *
528 * <p>If a MainThreadRequest object is provided in the msg.obj field,
529 * note that request.result must be set to something non-null for the calling thread to
530 * unblock.
531 */
532 private final class MainThreadHandler extends Handler {
533 @Override
534 public void handleMessage(Message msg) {
535 MainThreadRequest request;
536 Message onCompleted;
537 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000538 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800540 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541
542 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 case CMD_HANDLE_USSD_REQUEST: {
544 request = (MainThreadRequest) msg.obj;
545 final Phone phone = getPhoneFromRequest(request);
546 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800547 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700549
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 if (!isUssdApiAllowed(request.subId)) {
551 // Carrier does not support use of this API, return failure.
552 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
553 UssdResponse response = new UssdResponse(ussdRequest, null);
554 Bundle returnData = new Bundle();
555 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
556 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700557
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 request.result = true;
559 notifyRequester(request);
560 return;
561 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700562
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 try {
564 request.result = phone != null
565 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
566 } catch (CallStateException cse) {
567 request.result = false;
568 }
569 // Wake up the requesting thread
570 notifyRequester(request);
571 break;
pkanwar32d516d2016-10-14 19:37:38 -0700572 }
573
Yorke Lee716f67e2015-06-17 15:39:16 -0700574 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700575 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700576 final Phone phone = getPhoneFromRequest(request);
577 request.result = phone != null ?
578 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
579 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700580 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700582 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700584
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000588 uiccPort = getUiccPortFromRequest(request);
589 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800591 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800595 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000596 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800597 iccArgument.channel, iccArgument.cla, iccArgument.command,
598 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
599 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 break;
602
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
608 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800609 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 if (ar.result == null) {
611 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800612 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800614 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 } else {
616 loge("iccTransmitApduLogicalChannel: Unknown exception");
617 }
618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 break;
621
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
624 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000625 uiccPort = getUiccPortFromRequest(request);
626 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800628 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800632 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000633 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800634 iccArgument.cla, iccArgument.command, iccArgument.p1,
635 iccArgument.p2,
636 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 }
638 break;
639
640 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
645 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800646 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 if (ar.result == null) {
648 loge("iccTransmitApduBasicChannel: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("iccTransmitApduBasicChannel: CommandException: " +
651 ar.exception);
652 } else {
653 loge("iccTransmitApduBasicChannel: Unknown exception");
654 }
655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 break;
658
659 case CMD_EXCHANGE_SIM_IO:
660 request = (MainThreadRequest) msg.obj;
661 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000662 uiccPort = getUiccPortFromRequest(request);
663 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800665 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 } else {
668 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
669 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000670 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
672 iccArgument.data, onCompleted);
673 }
674 break;
675
676 case EVENT_EXCHANGE_SIM_IO_DONE:
677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result;
681 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 break;
686
Derek Tan4d5e5c12014-02-04 11:54:58 -0800687 case CMD_SEND_ENVELOPE:
688 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000689 uiccPort = getUiccPortFromRequest(request);
690 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800692 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 } else {
695 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800696 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800698 break;
699
700 case EVENT_SEND_ENVELOPE_DONE:
701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800706 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700707 if (ar.result == null) {
708 loge("sendEnvelopeWithStatus: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("sendEnvelopeWithStatus: CommandException: " +
711 ar.exception);
712 } else {
713 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
714 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800717 break;
718
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 case CMD_OPEN_CHANNEL:
720 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000721 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800722 IccLogicalChannelRequest openChannelRequest =
723 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800726 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800727 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 } else {
730 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800731 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
732 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 break;
735
736 case EVENT_OPEN_CHANNEL_DONE:
737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 int[] result = (int[]) ar.result;
742 int channelId = result[0];
743 byte[] selectResponse = null;
744 if (result.length > 1) {
745 selectResponse = new byte[result.length - 1];
746 for (int i = 1; i < result.length; ++i) {
747 selectResponse[i - 1] = (byte) result[i];
748 }
749 }
750 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800751 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800752
753 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700754 if (uiccPort == null) {
755 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
756 } else {
757 IccLogicalChannelRequest channelRequest =
758 (IccLogicalChannelRequest) request.argument;
759 channelRequest.channel = channelId;
760 uiccPort.onLogicalChannelOpened(channelRequest);
761 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 if (ar.result == null) {
764 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700766 if (ar.exception != null) {
767 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
768 }
769
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700770 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700771 if (ar.exception instanceof CommandException) {
772 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800773 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700774 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700775 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700776 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700777 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700778 }
779 }
780 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800781 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700783 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700784 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 break;
786
787 case CMD_CLOSE_CHANNEL:
788 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000789 uiccPort = getUiccPortFromRequest(request);
790 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700791 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800792 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800793 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800794 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700795 } else {
796 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000797 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700798 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 break;
800
801 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
804 if (ar.exception == null) {
805 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800806 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700807 if (uiccPort == null) {
808 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
809 } else {
810 final int channelId = (Integer) request.argument;
811 uiccPort.onLogicalChannelClosed(channelId);
812 }
Chen Xu540470b2021-12-14 17:15:47 -0800813 } else {
814 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800815 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800816 if (ar.exception instanceof CommandException) {
817 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
818 CommandException.Error error =
819 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800820 if (error == CommandException.Error.INVALID_ARGUMENTS) {
821 // should only throw exceptions from the binder threads.
822 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800823 "iccCloseLogicalChannel: invalid argument ");
824 }
825 } else {
826 loge("iccCloseLogicalChannel: Unknown exception");
827 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800828 request.result = (exception != null) ? exception :
829 new IllegalStateException(
830 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800831 }
832 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800833 break;
834
835 case CMD_NV_READ_ITEM:
836 request = (MainThreadRequest) msg.obj;
837 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800838 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
839 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800840 break;
841
842 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800845 if (ar.exception == null && ar.result != null) {
846 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700847 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800848 request.result = "";
849 if (ar.result == null) {
850 loge("nvReadItem: Empty response");
851 } else if (ar.exception instanceof CommandException) {
852 loge("nvReadItem: CommandException: " +
853 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700854 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800855 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700856 }
857 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700858 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700859 break;
860
Jake Hambye994d462014-02-03 13:10:13 -0800861 case CMD_NV_WRITE_ITEM:
862 request = (MainThreadRequest) msg.obj;
863 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
864 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800865 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700866 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800867 break;
868
869 case EVENT_NV_WRITE_ITEM_DONE:
870 handleNullReturnEvent(msg, "nvWriteItem");
871 break;
872
873 case CMD_NV_WRITE_CDMA_PRL:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800876 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800877 break;
878
879 case EVENT_NV_WRITE_CDMA_PRL_DONE:
880 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
881 break;
882
chen xu6dac5ab2018-10-26 17:39:23 -0700883 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800884 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700885 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800886 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800887 break;
888
chen xu6dac5ab2018-10-26 17:39:23 -0700889 case EVENT_RESET_MODEM_CONFIG_DONE:
890 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800891 break;
892
Sooraj Sasindran37444802020-08-11 10:40:43 -0700893 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
894 request = (MainThreadRequest) msg.obj;
895 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
896 request);
897 Phone phone = getPhoneFromRequest(request);
898 if (phone != null) {
899 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
900 } else {
901 loge("isNRDualConnectivityEnabled: No phone object");
902 request.result = false;
903 notifyRequester(request);
904 }
905 break;
906 }
907
908 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result;
913 } else {
914 // request.result must be set to something non-null
915 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700916 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700917 request.result = ar.result;
918 } else {
919 request.result = false;
920 }
921 if (ar.result == null) {
922 loge("isNRDualConnectivityEnabled: Empty response");
923 } else if (ar.exception instanceof CommandException) {
924 loge("isNRDualConnectivityEnabled: CommandException: "
925 + ar.exception);
926 } else {
927 loge("isNRDualConnectivityEnabled: Unknown exception");
928 }
929 }
930 notifyRequester(request);
931 break;
932
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700933 case CMD_IS_VONR_ENABLED: {
934 request = (MainThreadRequest) msg.obj;
935 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
936 request);
937 Phone phone = getPhoneFromRequest(request);
938 if (phone != null) {
939 phone.isVoNrEnabled(onCompleted, request.workSource);
940 } else {
941 loge("isVoNrEnabled: No phone object");
942 request.result = false;
943 notifyRequester(request);
944 }
945 break;
946 }
947
948 case EVENT_IS_VONR_ENABLED_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 if (ar.exception == null && ar.result != null) {
952 request.result = ar.result;
953 } else {
954 // request.result must be set to something non-null
955 // for the calling thread to unblock
956 if (ar.result != null) {
957 request.result = ar.result;
958 } else {
959 request.result = false;
960 }
961 if (ar.result == null) {
962 loge("isVoNrEnabled: Empty response");
963 } else if (ar.exception instanceof CommandException) {
964 loge("isVoNrEnabled: CommandException: "
965 + ar.exception);
966 } else {
967 loge("isVoNrEnabled: Unknown exception");
968 }
969 }
970 notifyRequester(request);
971 break;
972
Sooraj Sasindran37444802020-08-11 10:40:43 -0700973 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
974 request = (MainThreadRequest) msg.obj;
975 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
976 Phone phone = getPhoneFromRequest(request);
977 if (phone != null) {
978 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
979 request.workSource);
980 } else {
981 loge("enableNrDualConnectivity: No phone object");
982 request.result =
983 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
984 notifyRequester(request);
985 }
986 break;
987 }
988
989 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 if (ar.exception == null) {
993 request.result =
994 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
995 } else {
996 request.result =
997 TelephonyManager
998 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
999 if (ar.exception instanceof CommandException) {
1000 CommandException.Error error =
1001 ((CommandException) (ar.exception)).getCommandError();
1002 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1003 request.result =
1004 TelephonyManager
1005 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001006 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1007 request.result =
1008 TelephonyManager
1009 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001010 }
1011 loge("enableNrDualConnectivity" + ": CommandException: "
1012 + ar.exception);
1013 } else {
1014 loge("enableNrDualConnectivity" + ": Unknown exception");
1015 }
1016 }
1017 notifyRequester(request);
1018 break;
1019 }
1020
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001021 case CMD_ENABLE_VONR: {
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1024 Phone phone = getPhoneFromRequest(request);
1025 if (phone != null) {
1026 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1027 request.workSource);
1028 } else {
1029 loge("setVoNrEnabled: No phone object");
1030 request.result =
1031 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1032 notifyRequester(request);
1033 }
1034 break;
1035 }
1036
1037 case EVENT_ENABLE_VONR_DONE: {
1038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
1040 if (ar.exception == null) {
1041 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1042 } else {
1043 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1044 if (ar.exception instanceof CommandException) {
1045 CommandException.Error error =
1046 ((CommandException) (ar.exception)).getCommandError();
1047 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1048 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1049 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1050 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1051 } else {
1052 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1053 }
1054 loge("setVoNrEnabled" + ": CommandException: "
1055 + ar.exception);
1056 } else {
1057 loge("setVoNrEnabled" + ": Unknown exception");
1058 }
1059 }
1060 notifyRequester(request);
1061 break;
1062 }
1063
SongFerngWang3ef3e072020-12-21 16:41:52 +08001064 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001065 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001066 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1067 request);
1068 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001069 break;
1070
SongFerngWang3ef3e072020-12-21 16:41:52 +08001071 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001072 ar = (AsyncResult) msg.obj;
1073 request = (MainThreadRequest) ar.userObj;
1074 if (ar.exception == null && ar.result != null) {
1075 request.result = ar.result; // Integer
1076 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301077 // request.result must be set to something non-null
1078 // for the calling thread to unblock
1079 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001080 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001081 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001082 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001083 loge("getAllowedNetworkTypesBitmask: CommandException: "
1084 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001087 }
1088 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001089 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 break;
1091
SongFerngWang3ef3e072020-12-21 16:41:52 +08001092 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001093 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001094 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1095 request);
1096 Pair<Integer, Long> reasonWithNetworkTypes =
1097 (Pair<Integer, Long>) request.argument;
1098 getPhoneFromRequest(request).setAllowedNetworkTypes(
1099 reasonWithNetworkTypes.first,
1100 reasonWithNetworkTypes.second,
1101 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001102 break;
1103
SongFerngWang3ef3e072020-12-21 16:41:52 +08001104 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1105 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001106 break;
1107
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001108 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1109 request = (MainThreadRequest)msg.obj;
1110 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001111 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001112 break;
1113
1114 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1115 ar = (AsyncResult)msg.obj;
1116 request = (MainThreadRequest)ar.userObj;
1117 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001118 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001119 break;
1120
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001121 case CMD_SET_VOICEMAIL_NUMBER:
1122 request = (MainThreadRequest) msg.obj;
1123 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1124 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001125 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1126 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001127 break;
1128
1129 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1130 handleNullReturnEvent(msg, "setVoicemailNumber");
1131 break;
1132
Stuart Scott54788802015-03-30 13:18:01 -07001133 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1134 request = (MainThreadRequest) msg.obj;
1135 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1136 request);
1137 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1138 break;
1139
1140 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1141 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1142 break;
1143
Shishir Agrawal302c8692015-06-19 13:49:39 -07001144 case CMD_PERFORM_NETWORK_SCAN:
1145 request = (MainThreadRequest) msg.obj;
1146 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1147 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1148 break;
1149
Hall Liu27d24262020-09-18 19:04:59 -07001150 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001151 request = (MainThreadRequest) msg.obj;
1152 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001153 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1154 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1155 request.argument;
1156 int callForwardingReason = args.first;
1157 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001158 break;
Hall Liu27d24262020-09-18 19:04:59 -07001159 }
1160 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001163 TelephonyManager.CallForwardingInfoCallback callback =
1164 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1165 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001166 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001167 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001168 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1169 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1170 // Service Class is a bit mask per 3gpp 27.007. Search for
1171 // any service for voice call.
1172 if ((callForwardInfo.serviceClass
1173 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001174 callForwardingInfo = new CallForwardingInfo(
1175 callForwardInfo.status
1176 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001177 callForwardInfo.reason,
1178 callForwardInfo.number,
1179 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001180 break;
1181 }
1182 }
1183 // Didn't find a call forward info for voice call.
1184 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001185 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1186 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001187 }
Hall Liu27d24262020-09-18 19:04:59 -07001188 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001189 } else {
1190 if (ar.result == null) {
1191 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1192 }
1193 if (ar.exception != null) {
1194 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1195 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001196 int errorCode = TelephonyManager
1197 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001198 if (ar.exception instanceof CommandException) {
1199 CommandException.Error error =
1200 ((CommandException) (ar.exception)).getCommandError();
1201 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001202 errorCode = TelephonyManager
1203 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001204 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001205 errorCode = TelephonyManager
1206 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 }
1208 }
Hall Liu27d24262020-09-18 19:04:59 -07001209 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001210 }
Shuo Qian4a594052020-01-23 11:59:30 -08001211 break;
Hall Liu27d24262020-09-18 19:04:59 -07001212 }
Shuo Qian4a594052020-01-23 11:59:30 -08001213
Hall Liu27d24262020-09-18 19:04:59 -07001214 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001215 request = (MainThreadRequest) msg.obj;
1216 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001217 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001218 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001219 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1220 request.argument).first;
1221 request.phone.setCallForwardingOption(
1222 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001223 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001224 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001225 callForwardingInfoToSet.getReason(),
1226 callForwardingInfoToSet.getNumber(),
1227 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1228 break;
Hall Liu27d24262020-09-18 19:04:59 -07001229 }
Shuo Qian4a594052020-01-23 11:59:30 -08001230
Hall Liu27d24262020-09-18 19:04:59 -07001231 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001232 ar = (AsyncResult) msg.obj;
1233 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001234 Consumer<Integer> callback =
1235 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1236 request.argument).second;
1237 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001238 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001239 int errorCode = TelephonyManager.CallForwardingInfoCallback
1240 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001241 if (ar.exception instanceof CommandException) {
1242 CommandException.Error error =
1243 ((CommandException) (ar.exception)).getCommandError();
1244 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001245 errorCode = TelephonyManager.CallForwardingInfoCallback
1246 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001247 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001248 errorCode = TelephonyManager.CallForwardingInfoCallback
1249 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001250 }
1251 }
1252 callback.accept(errorCode);
1253 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001254 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001255 }
Shuo Qian4a594052020-01-23 11:59:30 -08001256 break;
Hall Liu27d24262020-09-18 19:04:59 -07001257 }
Shuo Qian4a594052020-01-23 11:59:30 -08001258
Hall Liu27d24262020-09-18 19:04:59 -07001259 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001260 request = (MainThreadRequest) msg.obj;
1261 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1262 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1263 break;
Hall Liu27d24262020-09-18 19:04:59 -07001264 }
Shuo Qian4a594052020-01-23 11:59:30 -08001265
Hall Liu27d24262020-09-18 19:04:59 -07001266 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001269 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001270 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001271 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001272 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 // Service Class is a bit mask per 3gpp 27.007.
1274 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001275 if (callForwardResults.length > 1
1276 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001277 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001278 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001279 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1280 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001281 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001282 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001283 }
1284 } else {
1285 if (ar.result == null) {
1286 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1287 }
1288 if (ar.exception != null) {
1289 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1290 }
1291 if (ar.exception instanceof CommandException) {
1292 CommandException.Error error =
1293 ((CommandException) (ar.exception)).getCommandError();
1294 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001295 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001296 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001297 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1298 callWaitingStatus =
1299 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001300 }
1301 }
1302 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001303 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001304 break;
Hall Liu27d24262020-09-18 19:04:59 -07001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306
Hall Liu27d24262020-09-18 19:04:59 -07001307 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001308 request = (MainThreadRequest) msg.obj;
1309 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001310 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1311 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001312 break;
Hall Liu27d24262020-09-18 19:04:59 -07001313 }
Shuo Qian4a594052020-01-23 11:59:30 -08001314
Hall Liu27d24262020-09-18 19:04:59 -07001315 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001316 ar = (AsyncResult) msg.obj;
1317 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001318 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1319 Consumer<Integer> callback =
1320 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1321 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001322 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001323 if (ar.exception instanceof CommandException) {
1324 CommandException.Error error =
1325 ((CommandException) (ar.exception)).getCommandError();
1326 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1327 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1329 callback.accept(
1330 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001331 } else {
1332 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1333 }
1334 } else {
1335 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1336 }
1337 } else {
1338 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1339 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001340 }
Shuo Qian4a594052020-01-23 11:59:30 -08001341 break;
Hall Liu27d24262020-09-18 19:04:59 -07001342 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001343 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1344 ar = (AsyncResult) msg.obj;
1345 request = (MainThreadRequest) ar.userObj;
1346 CellNetworkScanResult cellScanResult;
1347 if (ar.exception == null && ar.result != null) {
1348 cellScanResult = new CellNetworkScanResult(
1349 CellNetworkScanResult.STATUS_SUCCESS,
1350 (List<OperatorInfo>) ar.result);
1351 } else {
1352 if (ar.result == null) {
1353 loge("getCellNetworkScanResults: Empty response");
1354 }
1355 if (ar.exception != null) {
1356 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1357 }
1358 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1359 if (ar.exception instanceof CommandException) {
1360 CommandException.Error error =
1361 ((CommandException) (ar.exception)).getCommandError();
1362 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1363 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1364 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1365 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1366 }
1367 }
1368 cellScanResult = new CellNetworkScanResult(errorCode, null);
1369 }
1370 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001371 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001372 break;
1373
1374 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1375 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001376 ManualNetworkSelectionArgument selArg =
1377 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001378 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1379 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001380 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1381 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001382 break;
1383
1384 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 if (ar.exception == null) {
1388 request.result = true;
1389 } else {
1390 request.result = false;
1391 loge("setNetworkSelectionModeManual " + ar.exception);
1392 }
1393 notifyRequester(request);
1394 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001395 break;
1396
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001397 case CMD_GET_MODEM_ACTIVITY_INFO:
1398 request = (MainThreadRequest) msg.obj;
1399 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001400 if (defaultPhone != null) {
1401 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001402 } else {
1403 ResultReceiver result = (ResultReceiver) request.argument;
1404 Bundle bundle = new Bundle();
1405 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001406 new ModemActivityInfo(0, 0, 0,
1407 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001408 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001409 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001410 break;
1411
Hall Liud0f208c2020-10-14 16:54:44 -07001412 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001413 ar = (AsyncResult) msg.obj;
1414 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001415 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001416 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001417 if (mLastModemActivityInfo == null) {
1418 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1419 mLastModemActivitySpecificInfo[0] =
1420 new ActivityStatsTechSpecificInfo(
1421 0,
1422 0,
1423 new int[ModemActivityInfo.getNumTxPowerLevels()],
1424 0);
1425 mLastModemActivityInfo =
1426 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1427 }
1428
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001429 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001430 // Update the last modem activity info and the result of the request.
1431 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1432 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001433 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001434 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001435 mLastModemActivityInfo =
1436 new ModemActivityInfo(
1437 mLastModemActivityInfo.getTimestampMillis(),
1438 mLastModemActivityInfo.getSleepTimeMillis(),
1439 mLastModemActivityInfo.getIdleTimeMillis(),
1440 mLastModemActivitySpecificInfo);
1441
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001442 } else {
1443 if (ar.result == null) {
1444 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001445 error = TelephonyManager.ModemActivityInfoException
1446 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001448 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001449 error = TelephonyManager.ModemActivityInfoException
1450 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001451 } else {
1452 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001453 error = TelephonyManager.ModemActivityInfoException
1454 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 }
1456 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001457 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001458 if (mLastModemActivityInfo != null) {
1459 bundle.putParcelable(
1460 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1461 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001462 } else {
1463 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1464 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001466 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001467 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001468 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001469
Meng Wang1a7c35a2016-05-05 20:56:15 -07001470 case CMD_SET_ALLOWED_CARRIERS:
1471 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001472 CarrierRestrictionRules argument =
1473 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001474 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001475 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001476 break;
1477
1478 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1479 ar = (AsyncResult) msg.obj;
1480 request = (MainThreadRequest) ar.userObj;
1481 if (ar.exception == null && ar.result != null) {
1482 request.result = ar.result;
1483 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001484 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1485 if (ar.exception instanceof CommandException) {
1486 loge("setAllowedCarriers: CommandException: " + ar.exception);
1487 CommandException.Error error =
1488 ((CommandException) (ar.exception)).getCommandError();
1489 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1490 request.result =
1491 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1492 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001493 } else {
1494 loge("setAllowedCarriers: Unknown exception");
1495 }
1496 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001497 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001498 break;
1499
1500 case CMD_GET_ALLOWED_CARRIERS:
1501 request = (MainThreadRequest) msg.obj;
1502 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001503 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001504 break;
1505
1506 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1507 ar = (AsyncResult) msg.obj;
1508 request = (MainThreadRequest) ar.userObj;
1509 if (ar.exception == null && ar.result != null) {
1510 request.result = ar.result;
1511 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001512 request.result = new IllegalStateException(
1513 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001514 if (ar.result == null) {
1515 loge("getAllowedCarriers: Empty response");
1516 } else if (ar.exception instanceof CommandException) {
1517 loge("getAllowedCarriers: CommandException: " +
1518 ar.exception);
1519 } else {
1520 loge("getAllowedCarriers: Unknown exception");
1521 }
1522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001523 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001524 break;
1525
Nathan Haroldb3014052017-01-25 15:57:32 -08001526 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1527 ar = (AsyncResult) msg.obj;
1528 request = (MainThreadRequest) ar.userObj;
1529 if (ar.exception == null && ar.result != null) {
1530 request.result = ar.result;
1531 } else {
1532 request.result = new IllegalArgumentException(
1533 "Failed to retrieve Forbidden Plmns");
1534 if (ar.result == null) {
1535 loge("getForbiddenPlmns: Empty response");
1536 } else {
1537 loge("getForbiddenPlmns: Unknown exception");
1538 }
1539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001540 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001541 break;
1542
1543 case CMD_GET_FORBIDDEN_PLMNS:
1544 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001545 uiccPort = getUiccPortFromRequest(request);
1546 if (uiccPort == null) {
1547 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001548 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001549 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001550 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001551 break;
1552 }
1553 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001554 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001555 if (uiccApp == null) {
1556 loge("getForbiddenPlmns() no app with specified type -- "
1557 + appType);
1558 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001559 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001560 break;
1561 } else {
1562 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1563 + " specified type -- " + appType);
1564 }
1565 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1566 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1567 onCompleted);
1568 break;
1569
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001570 case CMD_SWITCH_SLOTS:
1571 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001572 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001573 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001574 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001575 break;
1576
1577 case EVENT_SWITCH_SLOTS_DONE:
1578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
1580 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001581 notifyRequester(request);
1582 break;
1583 case CMD_GET_NETWORK_SELECTION_MODE:
1584 request = (MainThreadRequest) msg.obj;
1585 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1586 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1587 break;
1588
1589 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1590 ar = (AsyncResult) msg.obj;
1591 request = (MainThreadRequest) ar.userObj;
1592 if (ar.exception != null) {
1593 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1594 } else {
1595 int mode = ((int[]) ar.result)[0];
1596 if (mode == 0) {
1597 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1598 } else {
1599 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1600 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001601 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001602 notifyRequester(request);
1603 break;
1604 case CMD_GET_CDMA_ROAMING_MODE:
1605 request = (MainThreadRequest) msg.obj;
1606 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1607 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1608 break;
1609 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1610 ar = (AsyncResult) msg.obj;
1611 request = (MainThreadRequest) ar.userObj;
1612 if (ar.exception != null) {
1613 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1614 } else {
1615 request.result = ((int[]) ar.result)[0];
1616 }
1617 notifyRequester(request);
1618 break;
1619 case CMD_SET_CDMA_ROAMING_MODE:
1620 request = (MainThreadRequest) msg.obj;
1621 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1622 int mode = (int) request.argument;
1623 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1624 break;
1625 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1626 ar = (AsyncResult) msg.obj;
1627 request = (MainThreadRequest) ar.userObj;
1628 request.result = ar.exception == null;
1629 notifyRequester(request);
1630 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001631 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1632 request = (MainThreadRequest) msg.obj;
1633 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1634 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1635 break;
1636 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1637 ar = (AsyncResult) msg.obj;
1638 request = (MainThreadRequest) ar.userObj;
1639 if (ar.exception != null) {
1640 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1641 } else {
1642 request.result = ((int[]) ar.result)[0];
1643 }
1644 notifyRequester(request);
1645 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001646 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1647 request = (MainThreadRequest) msg.obj;
1648 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1649 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001650 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1651 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001652 break;
1653 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1654 ar = (AsyncResult) msg.obj;
1655 request = (MainThreadRequest) ar.userObj;
1656 request.result = ar.exception == null;
1657 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001658 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001659 case CMD_GET_ALL_CELL_INFO:
1660 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001661 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001662 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001663 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001664 case EVENT_GET_ALL_CELL_INFO_DONE:
1665 ar = (AsyncResult) msg.obj;
1666 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001667 // If a timeout occurs, the response will be null
1668 request.result = (ar.exception == null && ar.result != null)
1669 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001670 synchronized (request) {
1671 request.notifyAll();
1672 }
1673 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001674 case CMD_REQUEST_CELL_INFO_UPDATE:
1675 request = (MainThreadRequest) msg.obj;
1676 request.phone.requestCellInfoUpdate(request.workSource,
1677 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1678 break;
1679 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1680 ar = (AsyncResult) msg.obj;
1681 request = (MainThreadRequest) ar.userObj;
1682 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1683 try {
1684 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001685 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001686 cb.onError(
1687 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1688 ar.exception.getClass().getName(),
1689 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001690 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001691 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001692 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001693 } else {
1694 // use the result as returned
1695 cb.onCellInfo((List<CellInfo>) ar.result);
1696 }
1697 } catch (RemoteException re) {
1698 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1699 }
1700 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001701 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001702 request = (MainThreadRequest) msg.obj;
1703 WorkSource ws = (WorkSource) request.argument;
1704 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001705 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001706 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001707 }
1708 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001709 ar = (AsyncResult) msg.obj;
1710 request = (MainThreadRequest) ar.userObj;
1711 if (ar.exception == null) {
1712 request.result = ar.result;
1713 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001714 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001715 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001716 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001717 }
1718
1719 synchronized (request) {
1720 request.notifyAll();
1721 }
1722 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001723 }
chen xu6dac5ab2018-10-26 17:39:23 -07001724 case CMD_MODEM_REBOOT:
1725 request = (MainThreadRequest) msg.obj;
1726 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001727 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001728 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001729 case EVENT_CMD_MODEM_REBOOT_DONE:
1730 handleNullReturnEvent(msg, "rebootModem");
1731 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001732 case CMD_REQUEST_ENABLE_MODEM:
1733 request = (MainThreadRequest) msg.obj;
1734 boolean enable = (boolean) request.argument;
1735 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001736 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001737 PhoneConfigurationManager.getInstance()
1738 .enablePhone(request.phone, enable, onCompleted);
1739 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001740 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001741 ar = (AsyncResult) msg.obj;
1742 request = (MainThreadRequest) ar.userObj;
1743 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001744 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001745 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001746 if ((boolean) request.result) {
1747 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1748 updateModemStateMetrics();
1749 } else {
1750 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1751 + ar.exception);
1752 }
1753 notifyRequester(request);
1754 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001755 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001756 case CMD_GET_MODEM_STATUS:
1757 request = (MainThreadRequest) msg.obj;
1758 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1759 PhoneConfigurationManager.getInstance()
1760 .getPhoneStatusFromModem(request.phone, onCompleted);
1761 break;
1762 case EVENT_GET_MODEM_STATUS_DONE:
1763 ar = (AsyncResult) msg.obj;
1764 request = (MainThreadRequest) ar.userObj;
1765 int id = request.phone.getPhoneId();
1766 if (ar.exception == null && ar.result != null) {
1767 request.result = ar.result;
1768 //update the cache as modem status has changed
1769 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1770 (boolean) request.result);
1771 } else {
1772 // Return true if modem status cannot be retrieved. For most cases,
1773 // modem status is on. And for older version modems, GET_MODEM_STATUS
1774 // and disable modem are not supported. Modem is always on.
1775 // TODO: this should be fixed in R to support a third
1776 // status UNKNOWN b/131631629
1777 request.result = true;
1778 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1779 + ar.exception);
1780 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001781 notifyRequester(request);
1782 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001783 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1784 request = (MainThreadRequest) msg.obj;
1785 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1786 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1787 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1788 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1789 break;
1790 }
1791 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1792 ar = (AsyncResult) msg.obj;
1793 request = (MainThreadRequest) ar.userObj;
1794 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1795 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1796 args.second.accept(ar.exception == null);
1797 notifyRequester(request);
1798 break;
1799 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001800 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1801 request = (MainThreadRequest) msg.obj;
1802 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1803 Phone phone = getPhoneFromRequest(request);
1804 if (phone != null) {
1805 phone.getSystemSelectionChannels(onCompleted);
1806 } else {
1807 loge("getSystemSelectionChannels: No phone object");
1808 request.result = new ArrayList<RadioAccessSpecifier>();
1809 notifyRequester(request);
1810 }
1811 break;
1812 }
1813 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1814 ar = (AsyncResult) msg.obj;
1815 request = (MainThreadRequest) ar.userObj;
1816 if (ar.exception == null && ar.result != null) {
1817 request.result = ar.result;
1818 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001819 request.result = new IllegalStateException(
1820 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001821 if (ar.result == null) {
1822 loge("getSystemSelectionChannels: Empty response");
1823 } else {
1824 loge("getSystemSelectionChannels: Unknown exception");
1825 }
1826 }
1827 notifyRequester(request);
1828 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001829 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1830 ar = (AsyncResult) msg.obj;
1831 request = (MainThreadRequest) ar.userObj;
1832 if (ar.exception == null && ar.result != null) {
1833 request.result = ar.result;
1834 } else {
1835 request.result = -1;
1836 loge("Failed to set Forbidden Plmns");
1837 if (ar.result == null) {
1838 loge("setForbidenPlmns: Empty response");
1839 } else if (ar.exception != null) {
1840 loge("setForbiddenPlmns: Exception: " + ar.exception);
1841 request.result = -1;
1842 } else {
1843 loge("setForbiddenPlmns: Unknown exception");
1844 }
1845 }
1846 notifyRequester(request);
1847 break;
1848 case CMD_SET_FORBIDDEN_PLMNS:
1849 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001850 uiccPort = getUiccPortFromRequest(request);
1851 if (uiccPort == null) {
1852 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001853 request.result = -1;
1854 notifyRequester(request);
1855 break;
1856 }
1857 Pair<Integer, List<String>> setFplmnsArgs =
1858 (Pair<Integer, List<String>>) request.argument;
1859 appType = setFplmnsArgs.first;
1860 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001861 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001862 if (uiccApp == null) {
1863 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1864 request.result = -1;
1865 loge("Failed to get UICC App");
1866 notifyRequester(request);
1867 } else {
1868 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1869 ((SIMRecords) uiccApp.getIccRecords())
1870 .setForbiddenPlmns(onCompleted, fplmns);
1871 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001872 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001873 case CMD_ERASE_MODEM_CONFIG:
1874 request = (MainThreadRequest) msg.obj;
1875 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1876 defaultPhone.eraseModemConfig(onCompleted);
1877 break;
1878 case EVENT_ERASE_MODEM_CONFIG_DONE:
1879 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001880 break;
zoey chene02881a2019-12-30 16:11:23 +08001881
Kai Shif70f46f2021-03-03 13:59:46 -08001882 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1883 request = (MainThreadRequest) msg.obj;
1884 request.result = defaultPhone.eraseDataInSharedPreferences();
1885 notifyRequester(request);
1886 break;
1887
zoey chene02881a2019-12-30 16:11:23 +08001888 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1889 request = (MainThreadRequest) msg.obj;
1890 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1891 Pair<String, String> changed = (Pair<String, String>) request.argument;
1892 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1893 changed.first, changed.second, onCompleted);
1894 break;
1895 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1896 ar = (AsyncResult) msg.obj;
1897 request = (MainThreadRequest) ar.userObj;
1898 if (ar.exception == null) {
1899 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001900 // If the operation is successful, update the PIN storage
1901 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1902 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001903 UiccController.getInstance().getPinStorage()
1904 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001905 } else {
1906 request.result = msg.arg1;
1907 }
1908 notifyRequester(request);
1909 break;
1910
Michele Berionne5e411512020-11-13 02:36:59 +00001911 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001912 request = (MainThreadRequest) msg.obj;
1913 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1914 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1915 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1916 enabled.first, enabled.second, onCompleted);
1917 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001918 }
zoey chene02881a2019-12-30 16:11:23 +08001919 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1920 ar = (AsyncResult) msg.obj;
1921 request = (MainThreadRequest) ar.userObj;
1922 if (ar.exception == null) {
1923 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001924 // If the operation is successful, update the PIN storage
1925 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1926 int phoneId = getPhoneFromRequest(request).getPhoneId();
1927 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001928 UiccController.getInstance().getPinStorage()
1929 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001930 } else {
1931 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1932 }
zoey chene02881a2019-12-30 16:11:23 +08001933 } else {
1934 request.result = msg.arg1;
1935 }
Michele Berionne5e411512020-11-13 02:36:59 +00001936
1937
zoey chene02881a2019-12-30 16:11:23 +08001938 notifyRequester(request);
1939 break;
1940
Peter Wangdafb9ac2020-01-15 14:13:38 -08001941 case MSG_NOTIFY_USER_ACTIVITY:
1942 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001943 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001944 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1945 getDefaultPhone().getContext().sendBroadcastAsUser(
1946 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1947 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001948
1949 case CMD_SET_DATA_THROTTLING: {
1950 request = (MainThreadRequest) msg.obj;
1951 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1952 DataThrottlingRequest dataThrottlingRequest =
1953 (DataThrottlingRequest) request.argument;
1954 Phone phone = getPhoneFromRequest(request);
1955 if (phone != null) {
1956 phone.setDataThrottling(onCompleted,
1957 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1958 dataThrottlingRequest.getCompletionDurationMillis());
1959 } else {
1960 loge("setDataThrottling: No phone object");
1961 request.result =
1962 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1963 notifyRequester(request);
1964 }
1965
1966 break;
1967 }
1968 case EVENT_SET_DATA_THROTTLING_DONE:
1969 ar = (AsyncResult) msg.obj;
1970 request = (MainThreadRequest) ar.userObj;
1971
1972 if (ar.exception == null) {
1973 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1974 } else if (ar.exception instanceof CommandException) {
1975 loge("setDataThrottling: CommandException: " + ar.exception);
1976 CommandException.Error error =
1977 ((CommandException) (ar.exception)).getCommandError();
1978
1979 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1980 request.result = TelephonyManager
1981 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1982 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1983 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001984 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1985 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001986 } else {
1987 request.result =
1988 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1989 }
1990 } else {
1991 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1992 }
1993 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1994 notifyRequester(request);
1995 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001996
1997 case CMD_SET_SIM_POWER: {
1998 request = (MainThreadRequest) msg.obj;
1999 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2000 request = (MainThreadRequest) msg.obj;
2001 int stateToSet =
2002 ((Pair<Integer, IIntegerConsumer>)
2003 request.argument).first;
2004 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2005 break;
2006 }
2007 case EVENT_SET_SIM_POWER_DONE: {
2008 ar = (AsyncResult) msg.obj;
2009 request = (MainThreadRequest) ar.userObj;
2010 IIntegerConsumer callback =
2011 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2012 if (ar.exception != null) {
2013 loge("setSimPower exception: " + ar.exception);
2014 int errorCode = TelephonyManager.CallForwardingInfoCallback
2015 .RESULT_ERROR_UNKNOWN;
2016 if (ar.exception instanceof CommandException) {
2017 CommandException.Error error =
2018 ((CommandException) (ar.exception)).getCommandError();
2019 if (error == CommandException.Error.SIM_ERR) {
2020 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2021 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2022 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2023 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2024 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2025 } else {
2026 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2027 }
2028 }
2029 try {
2030 callback.accept(errorCode);
2031 } catch (RemoteException e) {
2032 // Ignore if the remote process is no longer available to call back.
2033 Log.w(LOG_TAG, "setSimPower: callback not available.");
2034 }
2035 } else {
2036 try {
2037 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2038 } catch (RemoteException e) {
2039 // Ignore if the remote process is no longer available to call back.
2040 Log.w(LOG_TAG, "setSimPower: callback not available.");
2041 }
2042 }
2043 break;
2044 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002045 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2046 request = (MainThreadRequest) msg.obj;
2047
2048 final Phone phone = getPhoneFromRequest(request);
2049 if (phone == null || phone.getServiceStateTracker() == null) {
2050 request.result = new IllegalStateException("Phone or SST is null");
2051 notifyRequester(request);
2052 break;
2053 }
2054
2055 Pair<Integer, SignalStrengthUpdateRequest> pair =
2056 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2057 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2058 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002059 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002060 request.subId, pair.first /*callingUid*/,
2061 pair.second /*request*/, onCompleted);
2062 break;
2063 }
2064 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2065 ar = (AsyncResult) msg.obj;
2066 request = (MainThreadRequest) ar.userObj;
2067 // request.result will be the exception of ar if present, true otherwise.
2068 // Be cautious not to leave result null which will wait() forever
2069 request.result = ar.exception != null ? ar.exception : true;
2070 notifyRequester(request);
2071 break;
2072 }
2073 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2074 request = (MainThreadRequest) msg.obj;
2075
2076 Phone phone = getPhoneFromRequest(request);
2077 if (phone == null || phone.getServiceStateTracker() == null) {
2078 request.result = new IllegalStateException("Phone or SST is null");
2079 notifyRequester(request);
2080 break;
2081 }
2082
2083 Pair<Integer, SignalStrengthUpdateRequest> pair =
2084 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2085 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2086 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002087 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002088 request.subId, pair.first /*callingUid*/,
2089 pair.second /*request*/, onCompleted);
2090 break;
2091 }
2092 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2093 ar = (AsyncResult) msg.obj;
2094 request = (MainThreadRequest) ar.userObj;
2095 request.result = ar.exception != null ? ar.exception : true;
2096 notifyRequester(request);
2097 break;
2098 }
Jordan Liu109698e2020-11-24 14:50:34 -08002099
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002100 case CMD_GET_SLICING_CONFIG: {
2101 request = (MainThreadRequest) msg.obj;
2102 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2103 request.phone.getSlicingConfig(onCompleted);
2104 break;
2105 }
2106 case EVENT_GET_SLICING_CONFIG_DONE: {
2107 ar = (AsyncResult) msg.obj;
2108 request = (MainThreadRequest) ar.userObj;
2109 ResultReceiver result = (ResultReceiver) request.argument;
2110
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002111 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002112 Bundle bundle = new Bundle();
2113 int resultCode = 0;
2114 if (ar.exception != null) {
2115 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2116 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002117 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002118 } else if (ar.result == null) {
2119 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002120 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002121 } else {
2122 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002123 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2124 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002125 }
2126
2127 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002128 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002129 }
2130 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2131 result.send(resultCode, bundle);
2132 notifyRequester(request);
2133 break;
2134 }
2135
Michele Berionne5e411512020-11-13 02:36:59 +00002136 case CMD_PREPARE_UNATTENDED_REBOOT:
2137 request = (MainThreadRequest) msg.obj;
2138 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002139 UiccController.getInstance().getPinStorage()
2140 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002141 notifyRequester(request);
2142 break;
2143
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 default:
2145 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2146 break;
2147 }
2148 }
Jake Hambye994d462014-02-03 13:10:13 -08002149
Pengquan Menga1bb6272018-09-06 09:59:22 -07002150 private void notifyRequester(MainThreadRequest request) {
2151 synchronized (request) {
2152 request.notifyAll();
2153 }
2154 }
2155
Jake Hambye994d462014-02-03 13:10:13 -08002156 private void handleNullReturnEvent(Message msg, String command) {
2157 AsyncResult ar = (AsyncResult) msg.obj;
2158 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2159 if (ar.exception == null) {
2160 request.result = true;
2161 } else {
2162 request.result = false;
2163 if (ar.exception instanceof CommandException) {
2164 loge(command + ": CommandException: " + ar.exception);
2165 } else {
2166 loge(command + ": Unknown exception");
2167 }
2168 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002169 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 }
2172
2173 /**
2174 * Posts the specified command to be executed on the main thread,
2175 * waits for the request to complete, and returns the result.
2176 * @see #sendRequestAsync
2177 */
2178 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002179 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2180 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002181 }
2182
2183 /**
2184 * Posts the specified command to be executed on the main thread,
2185 * waits for the request to complete, and returns the result.
2186 * @see #sendRequestAsync
2187 */
2188 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2189 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002190 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002191 }
2192
2193 /**
2194 * Posts the specified command to be executed on the main thread,
2195 * waits for the request to complete, and returns the result.
2196 * @see #sendRequestAsync
2197 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002198 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002199 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2200 }
2201
2202 /**
2203 * Posts the specified command to be executed on the main thread,
2204 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2205 * if not timeout or null otherwise.
2206 * @see #sendRequestAsync
2207 */
2208 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2209 long timeoutInMs) {
2210 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002211 }
2212
2213 /**
2214 * Posts the specified command to be executed on the main thread,
2215 * waits for the request to complete, and returns the result.
2216 * @see #sendRequestAsync
2217 */
Nathan Harold92bed182018-10-12 18:16:49 -07002218 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002219 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002220 }
2221
2222 /**
2223 * Posts the specified command to be executed on the main thread,
2224 * waits for the request to complete, and returns the result.
2225 * @see #sendRequestAsync
2226 */
2227 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002228 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2229 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002230 }
2231
2232 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002233 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2234 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2235 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002236 * @see #sendRequestAsync
2237 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002238 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2239 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2241 throw new RuntimeException("This method will deadlock if called from the main thread.");
2242 }
2243
Nathan Harold92bed182018-10-12 18:16:49 -07002244 MainThreadRequest request = null;
2245 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2246 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2247 } else if (phone != null) {
2248 request = new MainThreadRequest(argument, phone, workSource);
2249 } else {
2250 request = new MainThreadRequest(argument, subId, workSource);
2251 }
2252
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 Message msg = mMainThreadHandler.obtainMessage(command, request);
2254 msg.sendToTarget();
2255
Rambo Wang0f050d82021-02-12 11:43:36 -08002256
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002258 if (timeoutInMs >= 0) {
2259 // Wait for at least timeoutInMs before returning null request result
2260 long now = SystemClock.elapsedRealtime();
2261 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002262 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002263 try {
2264 request.wait(deadline - now);
2265 } catch (InterruptedException e) {
2266 // Do nothing, go back and check if request is completed or timeout
2267 } finally {
2268 now = SystemClock.elapsedRealtime();
2269 }
2270 }
2271 } else {
2272 // Wait for the request to complete
2273 while (request.result == null) {
2274 try {
2275 request.wait();
2276 } catch (InterruptedException e) {
2277 // Do nothing, go back and wait until the request is complete
2278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280 }
2281 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002282 if (request.result == null) {
2283 Log.wtf(LOG_TAG,
2284 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 return request.result;
2287 }
2288
2289 /**
2290 * Asynchronous ("fire and forget") version of sendRequest():
2291 * Posts the specified command to be executed on the main thread, and
2292 * returns immediately.
2293 * @see #sendRequest
2294 */
2295 private void sendRequestAsync(int command) {
2296 mMainThreadHandler.sendEmptyMessage(command);
2297 }
2298
2299 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002300 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002301 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002302 */
2303 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002304 sendRequestAsync(command, argument, null, null);
2305 }
2306
2307 /**
2308 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2309 * @see {@link #sendRequest(int,Object)}
2310 */
2311 private void sendRequestAsync(
2312 int command, Object argument, Phone phone, WorkSource workSource) {
2313 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002314 Message msg = mMainThreadHandler.obtainMessage(command, request);
2315 msg.sendToTarget();
2316 }
2317
2318 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 * Initialize the singleton PhoneInterfaceManager instance.
2320 * This is only done once, at startup, from PhoneApp.onCreate().
2321 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002322 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 synchronized (PhoneInterfaceManager.class) {
2324 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002325 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 } else {
2327 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2328 }
2329 return sInstance;
2330 }
2331 }
2332
2333 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002334 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002337 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002338 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002340 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002342 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002343 mTelephonySharedPreferences =
2344 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002345 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002346 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002347 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002348 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002349 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukiermand6cae882022-12-29 12:02:31 -05002350 mTelephony2gUpdater = new Telephony2gUpdater(mApp);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002351 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 publish();
2353 }
2354
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002355 private Phone getDefaultPhone() {
2356 Phone thePhone = getPhone(getDefaultSubscription());
2357 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2358 }
2359
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 private void publish() {
2361 if (DBG) log("publish: " + this);
2362
Peter Wangc035ce42020-01-08 21:00:22 -08002363 TelephonyFrameworkInitializer
2364 .getTelephonyServiceManager()
2365 .getTelephonyServiceRegisterer()
2366 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 }
2368
Stuart Scott584921c2015-01-15 17:10:34 -08002369 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002370 if (request.phone != null) {
2371 return request.phone;
2372 } else {
2373 return getPhoneFromSubId(request.subId);
2374 }
2375 }
2376
2377 private Phone getPhoneFromSubId(int subId) {
2378 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2379 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002380 }
2381
Rambo Wange53e07d2022-05-10 13:01:13 -07002382 @Nullable
2383 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002384 Phone phone = getPhoneFromRequest(request);
2385 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002386 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002387 }
2388
Wink Saville36469e72014-06-11 15:17:00 -07002389 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002390 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002391 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393
Kai Shif70f46f2021-03-03 13:59:46 -08002394 private void sendEraseModemConfig(@NonNull Phone phone) {
2395 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2396 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2397 }
2398
2399 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2400 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2401 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002402 }
2403
Peter Wang44b186e2020-01-13 23:33:09 -08002404 private boolean isImsAvailableOnDevice() {
2405 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2406 if (pm == null) {
2407 // For some reason package manger is not available.. This will fail internally anyway,
2408 // so do not throw error and allow.
2409 return true;
2410 }
2411 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2412 }
2413
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002415 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002416 }
2417
Wink Savilleb564aae2014-10-23 10:18:09 -07002418 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 if (DBG) log("dial: " + number);
2420 // No permission check needed here: This is just a wrapper around the
2421 // ACTION_DIAL intent, which is available to any app since it puts up
2422 // the UI before it does anything.
2423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002424 final long identity = Binder.clearCallingIdentity();
2425 try {
2426 String url = createTelUrl(number);
2427 if (url == null) {
2428 return;
2429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002431 // PENDING: should we just silently fail if phone is offhook or ringing?
2432 PhoneConstants.State state = mCM.getState(subId);
2433 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2434 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2435 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2436 mApp.startActivity(intent);
2437 }
2438 } finally {
2439 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 }
2441 }
2442
2443 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002444 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002445 }
2446
Wink Savilleb564aae2014-10-23 10:18:09 -07002447 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 if (DBG) log("call: " + number);
2449
2450 // This is just a wrapper around the ACTION_CALL intent, but we still
2451 // need to do a permission check since we're calling startActivity()
2452 // from the context of the phone app.
2453 enforceCallPermission();
2454
Jordan Liu1617b712019-07-10 15:06:26 -07002455 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 != AppOpsManager.MODE_ALLOWED) {
2457 return;
2458 }
2459
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002460 final long identity = Binder.clearCallingIdentity();
2461 try {
2462 String url = createTelUrl(number);
2463 if (url == null) {
2464 return;
2465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467 boolean isValid = false;
2468 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2469 if (slist != null) {
2470 for (SubscriptionInfo subInfoRecord : slist) {
2471 if (subInfoRecord.getSubscriptionId() == subId) {
2472 isValid = true;
2473 break;
2474 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002475 }
Wink Saville08874612014-08-31 19:19:58 -07002476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477 if (!isValid) {
2478 return;
2479 }
Wink Saville08874612014-08-31 19:19:58 -07002480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2482 intent.putExtra(SUBSCRIPTION_KEY, subId);
2483 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2484 mApp.startActivity(intent);
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
2487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 }
2489
Wink Savilleb564aae2014-10-23 10:18:09 -07002490 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002491 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002492 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2493 }
2494
Wink Savilleb564aae2014-10-23 10:18:09 -07002495 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002496 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002497 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2498 }
2499
Wink Savilleb564aae2014-10-23 10:18:09 -07002500 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002502
2503 final long identity = Binder.clearCallingIdentity();
2504 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002505 Phone phone = getPhone(subId);
2506 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 checkSimPin.start();
2508 return checkSimPin.unlockSim(null, pin);
2509 } finally {
2510 Binder.restoreCallingIdentity(identity);
2511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512 }
2513
Wink Savilleb564aae2014-10-23 10:18:09 -07002514 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002516
2517 final long identity = Binder.clearCallingIdentity();
2518 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002519 Phone phone = getPhone(subId);
2520 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521 checkSimPuk.start();
2522 return checkSimPuk.unlockSim(puk, pin);
2523 } finally {
2524 Binder.restoreCallingIdentity(identity);
2525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 }
2527
2528 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002529 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002530 * a synchronous one.
2531 */
2532 private static class UnlockSim extends Thread {
2533
2534 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002535 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536
2537 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002538 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2539 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540
2541 // For replies from SimCard interface
2542 private Handler mHandler;
2543
2544 // For async handler to identify request type
2545 private static final int SUPPLY_PIN_COMPLETE = 100;
2546
Michele Berionne5e411512020-11-13 02:36:59 +00002547 UnlockSim(int phoneId, IccCard simCard) {
2548 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002549 mSimCard = simCard;
2550 }
2551
2552 @Override
2553 public void run() {
2554 Looper.prepare();
2555 synchronized (UnlockSim.this) {
2556 mHandler = new Handler() {
2557 @Override
2558 public void handleMessage(Message msg) {
2559 AsyncResult ar = (AsyncResult) msg.obj;
2560 switch (msg.what) {
2561 case SUPPLY_PIN_COMPLETE:
2562 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2563 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002564 mRetryCount = msg.arg1;
2565 if (ar.exception != null) {
2566 if (ar.exception instanceof CommandException &&
2567 ((CommandException)(ar.exception)).getCommandError()
2568 == CommandException.Error.PASSWORD_INCORRECT) {
2569 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002570 } //When UiccCardApp dispose,handle message and return exception
2571 else if (ar.exception instanceof CommandException &&
2572 ((CommandException) (ar.exception)).getCommandError()
2573 == CommandException.Error.ABORTED) {
2574 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002575 } else {
2576 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2577 }
2578 } else {
2579 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 mDone = true;
2582 UnlockSim.this.notifyAll();
2583 }
2584 break;
2585 }
2586 }
2587 };
2588 UnlockSim.this.notifyAll();
2589 }
2590 Looper.loop();
2591 }
2592
2593 /*
2594 * Use PIN or PUK to unlock SIM card
2595 *
2596 * If PUK is null, unlock SIM card with PIN
2597 *
2598 * If PUK is not null, unlock SIM card with PUK and set PIN code
2599 */
Wink Saville9de0f752013-10-22 19:04:03 -07002600 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601
2602 while (mHandler == null) {
2603 try {
2604 wait();
2605 } catch (InterruptedException e) {
2606 Thread.currentThread().interrupt();
2607 }
2608 }
2609 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2610
2611 if (puk == null) {
2612 mSimCard.supplyPin(pin, callback);
2613 } else {
2614 mSimCard.supplyPuk(puk, pin, callback);
2615 }
2616
2617 while (!mDone) {
2618 try {
2619 Log.d(LOG_TAG, "wait for done");
2620 wait();
2621 } catch (InterruptedException e) {
2622 // Restore the interrupted status
2623 Thread.currentThread().interrupt();
2624 }
2625 }
2626 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002627 int[] resultArray = new int[2];
2628 resultArray[0] = mResult;
2629 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002630
2631 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002632 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002633 }
2634
Wink Saville9de0f752013-10-22 19:04:03 -07002635 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636 }
2637 }
2638
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002639 /**
2640 * This method has been removed due to privacy and stability concerns.
2641 */
2642 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002644 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2645 return;
Wink Saville36469e72014-06-11 15:17:00 -07002646 }
2647
Nathan Harold1f889d82020-06-04 17:05:26 -07002648 @Override
2649 public void updateServiceLocationWithPackageName(String callingPackage) {
2650 mApp.getSystemService(AppOpsManager.class)
2651 .checkPackage(Binder.getCallingUid(), callingPackage);
2652
Nathan Haroldf096d982020-11-18 17:18:06 -08002653 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002654 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2655 // Callers targeting S have no business invoking this method.
2656 return;
2657 }
2658
2659 LocationAccessPolicy.LocationPermissionResult locationResult =
2660 LocationAccessPolicy.checkLocationPermission(mApp,
2661 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2662 .setCallingPackage(callingPackage)
2663 .setCallingFeatureId(null)
2664 .setCallingPid(Binder.getCallingPid())
2665 .setCallingUid(Binder.getCallingUid())
2666 .setMethod("updateServiceLocation")
2667 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2668 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2669 .build());
2670 // Apps that lack location permission have no business calling this method;
2671 // however, because no permission was declared in the public API, denials must
2672 // all be "soft".
2673 switch (locationResult) {
2674 case DENIED_HARD: /* fall through */
2675 case DENIED_SOFT:
2676 return;
2677 }
2678
2679 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680 final long identity = Binder.clearCallingIdentity();
2681 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002682 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002684 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 }
2686 } finally {
2687 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 }
2690
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002691 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002692 @Override
2693 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002694 return isRadioOnWithFeature(callingPackage, null);
2695 }
2696
2697
2698 @Override
2699 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2700 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2701 callingFeatureId);
2702 }
2703
2704 @Deprecated
2705 @Override
2706 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2707 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002708 }
2709
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002710 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002711 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2712 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002714 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002715 return false;
2716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717
2718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 return isRadioOnForSubscriber(subId);
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
2723 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002724 }
2725
2726 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 final Phone phone = getPhone(subId);
2730 if (phone != null) {
2731 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2732 } else {
2733 return false;
2734 }
2735 } finally {
2736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 }
2739
2740 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002741 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 }
Wink Saville36469e72014-06-11 15:17:00 -07002743
Wink Savilleb564aae2014-10-23 10:18:09 -07002744 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746
2747 final long identity = Binder.clearCallingIdentity();
2748 try {
2749 final Phone phone = getPhone(subId);
2750 if (phone != null) {
2751 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2752 }
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002755 }
Wink Saville36469e72014-06-11 15:17:00 -07002756 }
2757
2758 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002759 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002760 }
2761
Wink Savilleb564aae2014-10-23 10:18:09 -07002762 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 final Phone phone = getPhone(subId);
2768 if (phone == null) {
2769 return false;
2770 }
2771 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2772 toggleRadioOnOffForSubscriber(subId);
2773 }
2774 return true;
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
Wink Saville36469e72014-06-11 15:17:00 -07002779
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002780 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002781 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002782 /*
2783 * If any of the Radios are available, it will need to be
2784 * shutdown. So return true if any Radio is available.
2785 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2789 Phone phone = PhoneFactory.getPhone(i);
2790 if (phone != null && phone.isRadioAvailable()) return true;
2791 }
2792 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2793 return false;
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002796 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002797 }
2798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002800 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801 enforceModifyPermission();
2802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2806 logv("Shutting down Phone " + i);
2807 shutdownRadioUsingPhoneId(i);
2808 }
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002811 }
2812 }
2813
2814 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002815 Phone phone = PhoneFactory.getPhone(phoneId);
2816 if (phone != null && phone.isRadioAvailable()) {
2817 phone.shutdownRadio();
2818 }
2819 }
2820
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002822 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823
2824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2827 if (defaultPhone != null) {
2828 defaultPhone.setRadioPower(turnOn);
2829 return true;
2830 } else {
2831 loge("There's no default phone.");
2832 return false;
2833 }
2834 } finally {
2835 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002836 }
Wink Saville36469e72014-06-11 15:17:00 -07002837 }
2838
Wink Savilleb564aae2014-10-23 10:18:09 -07002839 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002841
2842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 final Phone phone = getPhone(subId);
2845 if (phone != null) {
2846 phone.setRadioPower(turnOn);
2847 return true;
2848 } else {
2849 return false;
2850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854 }
2855
Wink Saville36469e72014-06-11 15:17:00 -07002856 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002857 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002858 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860
2861 final long identity = Binder.clearCallingIdentity();
2862 try {
2863 int subId = mSubscriptionController.getDefaultDataSubId();
2864 final Phone phone = getPhone(subId);
2865 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002866 phone.getDataSettingsManager().setDataEnabled(
2867 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 return true;
2869 } else {
2870 return false;
2871 }
2872 } finally {
2873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875 }
2876
Wink Saville36469e72014-06-11 15:17:00 -07002877 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002878 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002879 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 int subId = mSubscriptionController.getDefaultDataSubId();
2885 final Phone phone = getPhone(subId);
2886 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002887 phone.getDataSettingsManager().setDataEnabled(
2888 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889 return true;
2890 } else {
2891 return false;
2892 }
2893 } finally {
2894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 }
2897
Sanket Padawe356d7632015-06-22 14:03:32 -07002898 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002899 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 final Phone phone = getPhone(subId);
2903 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002904 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 } else {
2906 return false;
2907 }
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002911 }
2912
2913 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002914 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002915 }
2916
pkanwarae03a6b2016-11-06 20:37:09 -08002917 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918 enforceCallPermission();
2919
2920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2923 return;
2924 }
2925 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2926 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2927 } finally {
2928 Binder.restoreCallingIdentity(identity);
2929 }
pkanwar32d516d2016-10-14 19:37:38 -07002930 };
2931
Wink Savilleb564aae2014-10-23 10:18:09 -07002932 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934
2935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2938 return false;
2939 }
2940 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002943 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002944 }
2945
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002946 /**
2947 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2948 * tag on getCallState Binder call.
2949 */
2950 @Deprecated
2951 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002952 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002953 if (CompatChanges.isChangeEnabled(
2954 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2955 Binder.getCallingUid())) {
2956 // Do not allow this API to be called on API version 31+, it should only be
2957 // called on old apps using this Binder call directly.
2958 throw new SecurityException("This method can only be used for applications "
2959 + "targeting API version 30 or less.");
2960 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002961 final long identity = Binder.clearCallingIdentity();
2962 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002963 Phone phone = getPhone(getDefaultSubscription());
2964 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2965 PhoneConstantConversions.convertCallState(phone.getState());
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 }
2970
2971 @Override
2972 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2973 if (CompatChanges.isChangeEnabled(
2974 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2975 Binder.getCallingUid())) {
2976 // Check READ_PHONE_STATE for API version 31+
2977 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2978 featureId, "getCallStateForSubscription")) {
2979 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2980 + "targeting API level 31+.");
2981 }
2982 }
2983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2987 PhoneConstantConversions.convertCallState(phone.getState());
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 }
2992
Sanket Padawe356d7632015-06-22 14:03:32 -07002993 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002994 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002995 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2996 }
2997
2998 @Override
2999 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 final long identity = Binder.clearCallingIdentity();
3001 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003002 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07003004 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 } else {
3006 return PhoneConstantConversions.convertDataState(
3007 PhoneConstants.DataState.DISCONNECTED);
3008 }
3009 } finally {
3010 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003011 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003012 }
3013
Sanket Padawe356d7632015-06-22 14:03:32 -07003014 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003015 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003016 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3017 }
3018
3019 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003020 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 final long identity = Binder.clearCallingIdentity();
3022 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003023 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003025 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 } else {
3027 return TelephonyManager.DATA_ACTIVITY_NONE;
3028 }
3029 } finally {
3030 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003031 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003032 }
3033
3034 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003035 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003037 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003038
3039 LocationAccessPolicy.LocationPermissionResult locationResult =
3040 LocationAccessPolicy.checkLocationPermission(mApp,
3041 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3042 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003043 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003044 .setCallingPid(Binder.getCallingPid())
3045 .setCallingUid(Binder.getCallingUid())
3046 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003047 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003048 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3049 .build());
3050 switch (locationResult) {
3051 case DENIED_HARD:
3052 throw new SecurityException("Not allowed to access cell location");
3053 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003054 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3055 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003056 }
3057
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003058 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003062 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003063 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064 } finally {
3065 Binder.restoreCallingIdentity(identity);
3066 }
Svetoslav64fad262015-04-14 14:35:21 -07003067 }
3068
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003069 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003070 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003071 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3072 // registered cell info, so return a NULL country instead.
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003075 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3076 // Get default phone in this case.
3077 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3078 }
Jack Yucda0c342022-11-17 22:47:32 -08003079 final int subId = mSubscriptionController.getSubId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003081 if (phone == null) return "";
3082 ServiceStateTracker sst = phone.getServiceStateTracker();
3083 if (sst == null) return "";
3084 LocaleTracker lt = sst.getLocaleTracker();
3085 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003086 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003090 }
3091
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003092 /**
3093 * This method was removed due to potential issues caused by performing partial
3094 * updates of service state, and lack of a credible use case.
3095 *
3096 * This has the ability to break the telephony implementation by disabling notification of
3097 * changes in device connectivity. DO NOT USE THIS!
3098 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003099 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003100 public void enableLocationUpdates() {
3101 mApp.enforceCallingOrSelfPermission(
3102 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003103 }
3104
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003105 /**
3106 * This method was removed due to potential issues caused by performing partial
3107 * updates of service state, and lack of a credible use case.
3108 *
3109 * This has the ability to break the telephony implementation by disabling notification of
3110 * changes in device connectivity. DO NOT USE THIS!
3111 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003112 @Override
3113 public void disableLocationUpdates() {
3114 mApp.enforceCallingOrSelfPermission(
3115 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 }
3117
3118 @Override
3119 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003120 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3121 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003122 try {
3123 mApp.getSystemService(AppOpsManager.class)
3124 .checkPackage(Binder.getCallingUid(), callingPackage);
3125 } catch (SecurityException e) {
3126 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3127 throw e;
3128 }
3129
Nathan Haroldf096d982020-11-18 17:18:06 -08003130 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003131 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3132 throw new SecurityException(
3133 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3134 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003135
Jordan Liu1617b712019-07-10 15:06:26 -07003136 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003137 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3138 return null;
3139 }
Svetoslav64fad262015-04-14 14:35:21 -07003140
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003141 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003143 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003144 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003145
Nathan Haroldf180aac2018-06-01 18:43:55 -07003146 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3147 for (CellInfo ci : info) {
3148 if (ci instanceof CellInfoGsm) {
3149 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3150 } else if (ci instanceof CellInfoWcdma) {
3151 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003154 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003155 }
3156
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003157 private List<CellInfo> getCachedCellInfo() {
3158 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3159 for (Phone phone : PhoneFactory.getPhones()) {
3160 List<CellInfo> info = phone.getAllCellInfo();
3161 if (info != null) cellInfos.addAll(info);
3162 }
3163 return cellInfos;
3164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165
3166 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003167 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003168 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003169 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003170
3171 LocationAccessPolicy.LocationPermissionResult locationResult =
3172 LocationAccessPolicy.checkLocationPermission(mApp,
3173 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3174 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003175 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003176 .setCallingPid(Binder.getCallingPid())
3177 .setCallingUid(Binder.getCallingUid())
3178 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003179 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003180 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3181 .build());
3182 switch (locationResult) {
3183 case DENIED_HARD:
3184 throw new SecurityException("Not allowed to access cell info");
3185 case DENIED_SOFT:
3186 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003187 }
3188
Nathan Haroldf096d982020-11-18 17:18:06 -08003189 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003190 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3191 return getCachedCellInfo();
3192 }
3193
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003194 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003195 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3199 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003200 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003201 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 if (info != null) cellInfos.addAll(info);
3203 }
3204 return cellInfos;
3205 } finally {
3206 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 }
3208 }
3209
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003210 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003211 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3212 String callingFeatureId) {
3213 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3214 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003215 }
3216
3217 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003218 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3219 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003220 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003221 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003222 }
3223
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003224 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3225 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003226 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003227 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003228
3229 LocationAccessPolicy.LocationPermissionResult locationResult =
3230 LocationAccessPolicy.checkLocationPermission(mApp,
3231 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3232 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003233 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003234 .setCallingPid(Binder.getCallingPid())
3235 .setCallingUid(Binder.getCallingUid())
3236 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003237 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3238 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003239 .build());
3240 switch (locationResult) {
3241 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003242 if (TelephonyPermissions
3243 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003244 // Safetynet logging for b/154934934
3245 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3246 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003247 throw new SecurityException("Not allowed to access cell info");
3248 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003249 if (TelephonyPermissions
3250 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003251 // Safetynet logging for b/154934934
3252 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3253 }
Nathan Harold5320c422019-05-09 10:26:08 -07003254 try {
3255 cb.onCellInfo(new ArrayList<CellInfo>());
3256 } catch (RemoteException re) {
3257 // Drop without consequences
3258 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003259 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003260 }
3261
Nathan Harolda939a962019-05-09 10:13:47 -07003262
3263 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003264 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3265
3266 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3267 }
3268
3269 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003270 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003271 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003272 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273
3274 final long identity = Binder.clearCallingIdentity();
3275 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003276 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277 } finally {
3278 Binder.restoreCallingIdentity(identity);
3279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 }
3281
Shishir Agrawala9f32182016-04-12 12:00:16 -07003282 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003283 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003284 Phone phone = PhoneFactory.getPhone(slotIndex);
3285 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003286 return null;
3287 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003288 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003289 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003290 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003291 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003292 return null;
3293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294
3295 final long identity = Binder.clearCallingIdentity();
3296 try {
3297 return phone.getImei();
3298 } finally {
3299 Binder.restoreCallingIdentity(identity);
3300 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003301 }
3302
3303 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003304 public String getTypeAllocationCodeForSlot(int slotIndex) {
3305 Phone phone = PhoneFactory.getPhone(slotIndex);
3306 String tac = null;
3307 if (phone != null) {
3308 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003309 try {
3310 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3311 } catch (IndexOutOfBoundsException e) {
3312 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3313 return null;
3314 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003315 }
3316 return tac;
3317 }
3318
3319 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003320 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003321 try {
3322 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3323 } catch (SecurityException se) {
3324 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3325 throw new SecurityException("Package " + callingPackage + " does not belong to "
3326 + Binder.getCallingUid());
3327 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003328 Phone phone = PhoneFactory.getPhone(slotIndex);
3329 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003330 return null;
3331 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003332
Jeff Davidson913390f2018-02-23 17:11:49 -08003333 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003334 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003335 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003336 return null;
3337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338
3339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 return phone.getMeid();
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
3344 }
Jack Yu2af8d712017-03-15 17:14:14 -07003345 }
3346
3347 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003348 public String getManufacturerCodeForSlot(int slotIndex) {
3349 Phone phone = PhoneFactory.getPhone(slotIndex);
3350 String manufacturerCode = null;
3351 if (phone != null) {
3352 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003353 try {
3354 manufacturerCode =
3355 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3356 } catch (IndexOutOfBoundsException e) {
3357 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3358 return null;
3359 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003360 }
3361 return manufacturerCode;
3362 }
3363
3364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003365 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3366 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003367 Phone phone = PhoneFactory.getPhone(slotIndex);
3368 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003369 return null;
3370 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003371 int subId = phone.getSubId();
3372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003373 mApp, subId, callingPackage, callingFeatureId,
3374 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003375 return null;
3376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003377
3378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 return phone.getDeviceSvn();
3381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003384 }
3385
fionaxu43304da2017-11-27 22:51:16 -08003386 @Override
3387 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003388 final long identity = Binder.clearCallingIdentity();
3389 try {
3390 final Phone phone = getPhone(subId);
3391 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3392 } finally {
3393 Binder.restoreCallingIdentity(identity);
3394 }
fionaxu43304da2017-11-27 22:51:16 -08003395 }
3396
3397 @Override
3398 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399 final long identity = Binder.clearCallingIdentity();
3400 try {
3401 final Phone phone = getPhone(subId);
3402 return phone == null ? null : phone.getCarrierName();
3403 } finally {
3404 Binder.restoreCallingIdentity(identity);
3405 }
fionaxu43304da2017-11-27 22:51:16 -08003406 }
3407
calvinpanffe225e2018-11-01 19:43:06 +08003408 @Override
chen xu0026ca62019-03-06 15:28:50 -08003409 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 final Phone phone = getPhone(subId);
3413 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003414 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003415 } finally {
3416 Binder.restoreCallingIdentity(identity);
3417 }
3418 }
3419
3420 @Override
chen xu0026ca62019-03-06 15:28:50 -08003421 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003425 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003426 } finally {
3427 Binder.restoreCallingIdentity(identity);
3428 }
3429 }
3430
chen xu651eec72018-11-11 19:03:44 -08003431 @Override
chen xu864e11c2018-12-06 22:10:03 -08003432 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3433 if (!isSubscriptionMccMnc) {
3434 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3435 }
chen xu651eec72018-11-11 19:03:44 -08003436 final Phone phone = PhoneFactory.getPhone(slotIndex);
3437 if (phone == null) {
3438 return TelephonyManager.UNKNOWN_CARRIER_ID;
3439 }
3440 final long identity = Binder.clearCallingIdentity();
3441 try {
3442 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3443 } finally {
3444 Binder.restoreCallingIdentity(identity);
3445 }
3446 }
3447
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003448 //
3449 // Internal helper methods.
3450 //
3451
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003452 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003453 * Make sure the caller is the calling package itself
3454 *
3455 * @throws SecurityException if the caller is not the calling package
3456 */
3457 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3458 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003459 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3460 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003461 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003462 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003463 } catch (PackageManager.NameNotFoundException e) {
3464 // packageUid is -1
3465 }
3466 if (packageUid != callingUid) {
3467 throw new SecurityException(message + ": Package " + callingPackage
3468 + " does not belong to " + callingUid);
3469 }
3470 }
3471
3472 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003473 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3474 *
3475 * @throws SecurityException if the caller does not have the required permission
3476 */
3477 private void enforceModifyPermission() {
3478 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3479 }
3480
Shuo Qian3b6ee772019-11-13 17:43:31 -08003481 private void enforceActiveEmergencySessionPermission() {
3482 mApp.enforceCallingOrSelfPermission(
3483 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3484 }
3485
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003486 /**
3487 * Make sure the caller has the CALL_PHONE permission.
3488 *
3489 * @throws SecurityException if the caller does not have the required permission
3490 */
3491 private void enforceCallPermission() {
3492 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3493 }
3494
paulhu5a773602019-08-23 19:17:33 +08003495 private void enforceSettingsPermission() {
3496 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003497 }
3498
Michele Berionne5e411512020-11-13 02:36:59 +00003499 private void enforceRebootPermission() {
3500 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3501 }
3502
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503 private String createTelUrl(String number) {
3504 if (TextUtils.isEmpty(number)) {
3505 return null;
3506 }
3507
Jake Hambye994d462014-02-03 13:10:13 -08003508 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003509 }
3510
Ihab Awadf9e92732013-12-05 18:02:52 -08003511 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003512 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3513 }
3514
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003515 private static void logv(String msg) {
3516 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3517 }
3518
Ihab Awadf9e92732013-12-05 18:02:52 -08003519 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003520 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3521 }
3522
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003523 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003525 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003526 }
3527
Sanket Padawe356d7632015-06-22 14:03:32 -07003528 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003529 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 final Phone phone = PhoneFactory.getPhone(slotIndex);
3533 if (phone == null) {
3534 return PhoneConstants.PHONE_TYPE_NONE;
3535 } else {
3536 return phone.getPhoneType();
3537 }
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003541 }
3542
3543 /**
3544 * Returns the CDMA ERI icon index to display
3545 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003546 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003547 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3548 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3549 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003550 }
3551
Sanket Padawe356d7632015-06-22 14:03:32 -07003552 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003553 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3554 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003556 mApp, subId, callingPackage, callingFeatureId,
3557 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003558 return -1;
3559 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003560
3561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 final Phone phone = getPhone(subId);
3564 if (phone != null) {
3565 return phone.getCdmaEriIconIndex();
3566 } else {
3567 return -1;
3568 }
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003572 }
3573
3574 /**
3575 * Returns the CDMA ERI icon mode,
3576 * 0 - ON
3577 * 1 - FLASHING
3578 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003579 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003580 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3581 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3582 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003583 }
3584
Sanket Padawe356d7632015-06-22 14:03:32 -07003585 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003586 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3587 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003589 mApp, subId, callingPackage, callingFeatureId,
3590 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003591 return -1;
3592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003593
3594 final long identity = Binder.clearCallingIdentity();
3595 try {
3596 final Phone phone = getPhone(subId);
3597 if (phone != null) {
3598 return phone.getCdmaEriIconMode();
3599 } else {
3600 return -1;
3601 }
3602 } finally {
3603 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003605 }
3606
3607 /**
3608 * Returns the CDMA ERI text,
3609 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003610 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003611 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3612 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3613 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003614 }
3615
Sanket Padawe356d7632015-06-22 14:03:32 -07003616 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003617 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3618 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003619 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003620 mApp, subId, callingPackage, callingFeatureId,
3621 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003622 return null;
3623 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003624
3625 final long identity = Binder.clearCallingIdentity();
3626 try {
3627 final Phone phone = getPhone(subId);
3628 if (phone != null) {
3629 return phone.getCdmaEriText();
3630 } else {
3631 return null;
3632 }
3633 } finally {
3634 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003636 }
3637
3638 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003639 * Returns the CDMA MDN.
3640 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003641 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003642 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3644 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645
3646 final long identity = Binder.clearCallingIdentity();
3647 try {
3648 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003649 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650 return phone.getLine1Number();
3651 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003652 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 return null;
3654 }
3655 } finally {
3656 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003657 }
3658 }
3659
3660 /**
3661 * Returns the CDMA MIN.
3662 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003663 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003664 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3666 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003667
3668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 final Phone phone = getPhone(subId);
3671 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3672 return phone.getCdmaMin();
3673 } else {
3674 return null;
3675 }
3676 } finally {
3677 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003678 }
3679 }
3680
Hall Liud892bec2018-11-30 14:51:45 -08003681 @Override
3682 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3683 INumberVerificationCallback callback, String callingPackage) {
3684 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3685 != PERMISSION_GRANTED) {
3686 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3687 }
3688 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3689
3690 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3691 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003692 throw new SecurityException("Calling package must be configured in the device config: "
3693 + "calling package: " + callingPackage
3694 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003695 }
3696
3697 if (range == null) {
3698 throw new NullPointerException("Range must be non-null");
3699 }
3700
3701 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003702 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003703
3704 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3705 }
3706
Junda Liuca05d5d2014-08-14 22:36:34 -07003707 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003708 * Returns true if CDMA provisioning needs to run.
3709 */
3710 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711 final long identity = Binder.clearCallingIdentity();
3712 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003713 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003717 }
3718
3719 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003720 * Sets the voice mail number of a given subId.
3721 */
3722 @Override
3723 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003724 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3725 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003726
3727 final long identity = Binder.clearCallingIdentity();
3728 try {
3729 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3730 new Pair<String, String>(alphaTag, number), new Integer(subId));
3731 return success;
3732 } finally {
3733 Binder.restoreCallingIdentity(identity);
3734 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003735 }
3736
Ta-wei Yen87c49842016-05-13 21:19:52 -07003737 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003738 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3739 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003740 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3741 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003742 if (!TextUtils.equals(callingPackage, systemDialer)) {
3743 throw new SecurityException("caller must be system dialer");
3744 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003745
3746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3749 if (phoneAccountHandle == null) {
3750 return null;
3751 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003752 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753 } finally {
3754 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003755 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003756 }
3757
3758 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003759 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3760 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003761 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 mApp, subId, callingPackage, callingFeatureId,
3764 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003765 return null;
3766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003767
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003768 final long identity = Binder.clearCallingIdentity();
3769 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003770 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003771 } finally {
3772 Binder.restoreCallingIdentity(identity);
3773 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003774 }
3775
3776 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003777 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3778 VisualVoicemailSmsFilterSettings settings) {
3779 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003780
3781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003784 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785 } finally {
3786 Binder.restoreCallingIdentity(identity);
3787 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003788 }
3789
3790 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003791 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3792 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793
3794 final long identity = Binder.clearCallingIdentity();
3795 try {
3796 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003797 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798 } finally {
3799 Binder.restoreCallingIdentity(identity);
3800 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003801 }
3802
3803 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003804 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3805 String callingPackage, int subId) {
3806 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003807
3808 final long identity = Binder.clearCallingIdentity();
3809 try {
3810 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003811 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812 } finally {
3813 Binder.restoreCallingIdentity(identity);
3814 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003815 }
3816
3817 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003818 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003819 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820
3821 final long identity = Binder.clearCallingIdentity();
3822 try {
3823 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003824 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825 } finally {
3826 Binder.restoreCallingIdentity(identity);
3827 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003828 }
3829
3830 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003831 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3832 String callingAttributionTag, int subId, String number, int port, String text,
3833 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003834 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003835 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003836 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003837 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003838 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3839 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003840 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003841
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003842 /**
fionaxu0152e512016-11-14 13:36:14 -08003843 * Sets the voice activation state of a given subId.
3844 */
3845 @Override
3846 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3848 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003849
3850 final long identity = Binder.clearCallingIdentity();
3851 try {
3852 final Phone phone = getPhone(subId);
3853 if (phone != null) {
3854 phone.setVoiceActivationState(activationState);
3855 } else {
3856 loge("setVoiceActivationState fails with invalid subId: " + subId);
3857 }
3858 } finally {
3859 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003860 }
3861 }
3862
3863 /**
3864 * Sets the data activation state of a given subId.
3865 */
3866 @Override
3867 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3869 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870
3871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 final Phone phone = getPhone(subId);
3874 if (phone != null) {
3875 phone.setDataActivationState(activationState);
3876 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003877 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003878 }
3879 } finally {
3880 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003881 }
3882 }
3883
3884 /**
3885 * Returns the voice activation state of a given subId.
3886 */
3887 @Override
3888 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890
fionaxu0152e512016-11-14 13:36:14 -08003891 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892 final long identity = Binder.clearCallingIdentity();
3893 try {
3894 if (phone != null) {
3895 return phone.getVoiceActivationState();
3896 } else {
3897 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3898 }
3899 } finally {
3900 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003901 }
3902 }
3903
3904 /**
3905 * Returns the data activation state of a given subId.
3906 */
3907 @Override
3908 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003909 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910
fionaxu0152e512016-11-14 13:36:14 -08003911 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 final long identity = Binder.clearCallingIdentity();
3913 try {
3914 if (phone != null) {
3915 return phone.getDataActivationState();
3916 } else {
3917 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3918 }
3919 } finally {
3920 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003921 }
3922 }
3923
3924 /**
Wink Saville36469e72014-06-11 15:17:00 -07003925 * Returns the unread count of voicemails for a subId
3926 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003927 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003928 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3929 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003931 mApp, subId, callingPackage, callingFeatureId,
3932 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003933 return 0;
3934 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 final Phone phone = getPhone(subId);
3938 if (phone != null) {
3939 return phone.getVoiceMessageCount();
3940 } else {
3941 return 0;
3942 }
3943 } finally {
3944 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003946 }
3947
3948 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003949 * returns true, if the device is in a state where both voice and data
3950 * are supported simultaneously. This can change based on location or network condition.
3951 */
3952 @Override
3953 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 final Phone phone = getPhone(subId);
3957 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3958 } finally {
3959 Binder.restoreCallingIdentity(identity);
3960 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003961 }
3962
3963 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003964 * Send the dialer code if called from the current default dialer or the caller has
3965 * carrier privilege.
3966 * @param inputCode The dialer code to send
3967 */
3968 @Override
3969 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003970 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003971 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003972 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3973 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003974 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003975 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003976 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978
3979 final long identity = Binder.clearCallingIdentity();
3980 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003981 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003982 } finally {
3983 Binder.restoreCallingIdentity(identity);
3984 }
fionaxu235cc5e2017-03-06 22:25:57 -08003985 }
3986
Pengquan Menga1bb6272018-09-06 09:59:22 -07003987 @Override
3988 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003989 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003990 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003991 mApp, subId, "getNetworkSelectionMode");
3992 final long identity = Binder.clearCallingIdentity();
3993 try {
3994 if (!isActiveSubscription(subId)) {
3995 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3996 }
3997 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3998 } finally {
3999 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004000 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004001 }
4002
Brad Ebinger35c841c2018-10-01 10:40:55 -07004003 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004004 public boolean isInEmergencySmsMode() {
4005 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4006 final long identity = Binder.clearCallingIdentity();
4007 try {
4008 for (Phone phone : PhoneFactory.getPhones()) {
4009 if (phone.isInEmergencySmsMode()) {
4010 return true;
4011 }
4012 }
4013 } finally {
4014 Binder.restoreCallingIdentity(identity);
4015 }
4016 return false;
4017 }
4018
shilu366312e2019-12-17 09:28:10 -08004019 /**
4020 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4021 * @param subId The subscription to use to check the configuration.
4022 * @param c The callback that will be used to send the result.
4023 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004024 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004025 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4026 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004027 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004028 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004029
4030 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4031 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4032 "IMS not available on device.");
4033 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 final long token = Binder.clearCallingIdentity();
4035 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004036 int slotId = getSlotIndexOrException(subId);
4037 verifyImsMmTelConfiguredOrThrow(slotId);
4038 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004039 } catch (ImsException e) {
4040 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 } finally {
4042 Binder.restoreCallingIdentity(token);
4043 }
4044 }
4045
shilu366312e2019-12-17 09:28:10 -08004046 /**
4047 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4048 * @param subId The subscription to use to check the configuration.
4049 * @param c The callback that will be used to send the result.
4050 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004051 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004052 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004053 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004054 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004055 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4056 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4057 }
Meng Wangafbc5852019-09-19 17:37:13 -07004058 final long token = Binder.clearCallingIdentity();
4059 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004060 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4061 .removeRegistrationCallbackForSubscription(c, subId);
4062 } catch (ImsException e) {
4063 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4064 + "is inactive, ignoring unregister.");
4065 // If the subscription is no longer active, just return, since the callback
4066 // will already have been removed internally.
4067 } finally {
4068 Binder.restoreCallingIdentity(token);
4069 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 }
4071
Brad Ebingera34a6c22019-10-22 17:36:18 -07004072 /**
4073 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4074 */
4075 @Override
4076 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4077 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4078 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4079 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4080 "IMS not available on device.");
4081 }
4082 final long token = Binder.clearCallingIdentity();
4083 try {
4084 Phone phone = getPhone(subId);
4085 if (phone == null) {
4086 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4087 + subId + "'");
4088 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4089 }
4090 phone.getImsRegistrationState(regState -> {
4091 try {
4092 consumer.accept((regState == null)
4093 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4094 } catch (RemoteException e) {
4095 // Ignore if the remote process is no longer available to call back.
4096 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4097 }
4098 });
4099 } finally {
4100 Binder.restoreCallingIdentity(token);
4101 }
4102 }
4103
4104 /**
4105 * Get the transport type for the IMS service registration state.
4106 */
4107 @Override
4108 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004109 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004110 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004111 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4112 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4113 "IMS not available on device.");
4114 }
4115 final long token = Binder.clearCallingIdentity();
4116 try {
4117 Phone phone = getPhone(subId);
4118 if (phone == null) {
4119 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4120 + subId + "'");
4121 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4122 }
4123 phone.getImsRegistrationTech(regTech -> {
4124 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4125 int regTechConverted = (regTech == null)
4126 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4127 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4128 regTechConverted);
4129 try {
4130 consumer.accept(regTechConverted);
4131 } catch (RemoteException e) {
4132 // Ignore if the remote process is no longer available to call back.
4133 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4134 }
4135 });
4136 } finally {
4137 Binder.restoreCallingIdentity(token);
4138 }
4139 }
4140
shilu366312e2019-12-17 09:28:10 -08004141 /**
4142 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4143 * @param subId The subscription to use to check the configuration.
4144 * @param c The callback that will be used to send the result.
4145 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004147 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4148 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004149 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004150 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004151 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4152 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4153 "IMS not available on device.");
4154 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 final long token = Binder.clearCallingIdentity();
4156 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004157 int slotId = getSlotIndexOrException(subId);
4158 verifyImsMmTelConfiguredOrThrow(slotId);
4159 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004160 } catch (ImsException e) {
4161 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004162 } finally {
4163 Binder.restoreCallingIdentity(token);
4164 }
4165 }
4166
shilu366312e2019-12-17 09:28:10 -08004167 /**
4168 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4169 * @param subId The subscription to use to check the configuration.
4170 * @param c The callback that will be used to send the result.
4171 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004172 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004173 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004174 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004175 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004176 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4177 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4178 }
Meng Wangafbc5852019-09-19 17:37:13 -07004179
4180 final long token = Binder.clearCallingIdentity();
4181 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004182 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004183 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004184 } catch (ImsException e) {
4185 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4186 + "is inactive, ignoring unregister.");
4187 // If the subscription is no longer active, just return, since the callback
4188 // will already have been removed internally.
4189 } finally {
4190 Binder.restoreCallingIdentity(token);
4191 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 }
4193
4194 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004195 public boolean isCapable(int subId, int capability, int regTech) {
4196 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 final long token = Binder.clearCallingIdentity();
4198 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004199 int slotId = getSlotIndexOrException(subId);
4200 verifyImsMmTelConfiguredOrThrow(slotId);
4201 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4202 } catch (com.android.ims.ImsException e) {
4203 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4204 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004205 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004206 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4207 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 } finally {
4209 Binder.restoreCallingIdentity(token);
4210 }
4211 }
4212
4213 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004214 public boolean isAvailable(int subId, int capability, int regTech) {
4215 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 final long token = Binder.clearCallingIdentity();
4217 try {
4218 Phone phone = getPhone(subId);
4219 if (phone == null) return false;
4220 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004221 } catch (com.android.ims.ImsException e) {
4222 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4223 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 } finally {
4225 Binder.restoreCallingIdentity(token);
4226 }
4227 }
4228
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004229 /**
4230 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4231 * subscription.
4232 * @param subId The subscription to use to check the configuration.
4233 * @param callback The callback that will be used to send the result.
4234 * @param capability The MmTelFeature capability that will be used to send the result.
4235 * @param transportType The transport type of the MmTelFeature capability.
4236 */
4237 @Override
4238 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4239 int transportType) {
4240 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004241 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4242 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4243 "IMS not available on device.");
4244 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004245 final long token = Binder.clearCallingIdentity();
4246 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004247 int slotId = getSlotIndex(subId);
4248 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4249 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4250 + subId + "'");
4251 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4252 }
4253 verifyImsMmTelConfiguredOrThrow(slotId);
4254 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4255 transportType, aBoolean -> {
4256 try {
4257 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4258 } catch (RemoteException e) {
4259 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4260 + "running. Ignore");
4261 }
4262 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004263 } catch (ImsException e) {
4264 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004265 } finally {
4266 Binder.restoreCallingIdentity(token);
4267 }
4268 }
4269
shilu366312e2019-12-17 09:28:10 -08004270 /**
4271 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4272 * @param subId The subscription to use to check the configuration.
4273 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004274 @Override
4275 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004276 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004277 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004278
Brad Ebinger35c841c2018-10-01 10:40:55 -07004279 final long token = Binder.clearCallingIdentity();
4280 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004281 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004282 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004283 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004284 } catch (ImsException e) {
4285 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004286 } finally {
4287 Binder.restoreCallingIdentity(token);
4288 }
4289 }
4290
4291 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004292 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004294 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 final long identity = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004298 // This setting doesn't require an active ImsService connection, so do not verify. The
4299 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004300 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004301 } catch (ImsException e) {
4302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004303 } finally {
4304 Binder.restoreCallingIdentity(identity);
4305 }
4306 }
4307
shilu366312e2019-12-17 09:28:10 -08004308 /**
4309 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4310 * @param subId The subscription to use to check the configuration.
4311 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004312 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004313 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004314 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004315 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004316 final long identity = Binder.clearCallingIdentity();
4317 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004318 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004319 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004320 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004321 } catch (ImsException e) {
4322 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004323 } finally {
4324 Binder.restoreCallingIdentity(identity);
4325 }
4326 }
4327
4328 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004329 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004331 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 final long identity = Binder.clearCallingIdentity();
4333 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004335 // This setting doesn't require an active ImsService connection, so do not verify. The
4336 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004337 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004338 } catch (ImsException e) {
4339 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004340 } finally {
4341 Binder.restoreCallingIdentity(identity);
4342 }
4343 }
4344
shilu366312e2019-12-17 09:28:10 -08004345 /**
4346 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4347 * @param subId The subscription to use to check the configuration.
4348 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004349 @Override
4350 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004351 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004352 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004353 final long identity = Binder.clearCallingIdentity();
4354 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004355 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004356 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004357 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004358 } catch (ImsException e) {
4359 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004360 } finally {
4361 Binder.restoreCallingIdentity(identity);
4362 }
4363 }
4364
4365 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004366 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004368 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 final long identity = Binder.clearCallingIdentity();
4370 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004371 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004372 // This setting doesn't require an active ImsService connection, so do not verify. The
4373 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004374 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004375 } catch (ImsException e) {
4376 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004377 } finally {
4378 Binder.restoreCallingIdentity(identity);
4379 }
4380 }
4381
shilu366312e2019-12-17 09:28:10 -08004382 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004383 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4384 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4385 * @param subId The subscription to use to check the configuration.
4386 */
4387 @Override
4388 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004389 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004390 mApp, subId, "isCrossSimCallingEnabledByUser");
4391 final long identity = Binder.clearCallingIdentity();
4392 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004393 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004394 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004396 } catch (ImsException e) {
4397 throw new ServiceSpecificException(e.getCode());
4398 } finally {
4399 Binder.restoreCallingIdentity(identity);
4400 }
4401 }
4402
4403 /**
4404 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4405 * Requires MODIFY_PHONE_STATE permission.
4406 * @param subId The subscription to use to check the configuration.
4407 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4408 * false otherwise
4409 */
4410 @Override
4411 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4413 "setCrossSimCallingEnabled");
4414 final long identity = Binder.clearCallingIdentity();
4415 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004416 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004417 // This setting doesn't require an active ImsService connection, so do not verify. The
4418 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004419 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004420 } catch (ImsException e) {
4421 throw new ServiceSpecificException(e.getCode());
4422 } finally {
4423 Binder.restoreCallingIdentity(identity);
4424 }
4425 }
4426
4427 /**
shilu366312e2019-12-17 09:28:10 -08004428 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4429 * @param subId The subscription to use to check the configuration.
4430 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004431 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004432
Brad Ebinger35c841c2018-10-01 10:40:55 -07004433 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004434 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004435 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004436 final long identity = Binder.clearCallingIdentity();
4437 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004438 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004439 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004440 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004441 } catch (ImsException e) {
4442 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004443 } finally {
4444 Binder.restoreCallingIdentity(identity);
4445 }
4446 }
4447
4448 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004449 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004451 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004452 final long identity = Binder.clearCallingIdentity();
4453 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004454 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004455 // This setting doesn't require an active ImsService connection, so do not verify. The
4456 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004457 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004458 } catch (ImsException e) {
4459 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004460 } finally {
4461 Binder.restoreCallingIdentity(identity);
4462 }
4463 }
4464
4465 @Override
4466 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4468 "setVoWiFiNonPersistent");
4469 final long identity = Binder.clearCallingIdentity();
4470 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004471 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004472 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004473 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004474 } catch (ImsException e) {
4475 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004476 } finally {
4477 Binder.restoreCallingIdentity(identity);
4478 }
4479 }
4480
shilu366312e2019-12-17 09:28:10 -08004481 /**
4482 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4483 * @param subId The subscription to use to check the configuration.
4484 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004485 @Override
4486 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004487 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004488 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004489 final long identity = Binder.clearCallingIdentity();
4490 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004491 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004492 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004493 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004494 } catch (ImsException e) {
4495 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004496 } finally {
4497 Binder.restoreCallingIdentity(identity);
4498 }
4499 }
4500
4501 @Override
4502 public void setVoWiFiModeSetting(int subId, int mode) {
4503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4504 "setVoWiFiModeSetting");
4505 final long identity = Binder.clearCallingIdentity();
4506 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004507 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004508 // This setting doesn't require an active ImsService connection, so do not verify. The
4509 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004510 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004511 } catch (ImsException e) {
4512 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
4516 }
4517
4518 @Override
4519 public int getVoWiFiRoamingModeSetting(int subId) {
4520 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4521 final long identity = Binder.clearCallingIdentity();
4522 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004523 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004524 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004525 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004526 } catch (ImsException e) {
4527 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004528 } finally {
4529 Binder.restoreCallingIdentity(identity);
4530 }
4531 }
4532
4533 @Override
4534 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4536 "setVoWiFiRoamingModeSetting");
4537 final long identity = Binder.clearCallingIdentity();
4538 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004539 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004540 // This setting doesn't require an active ImsService connection, so do not verify. The
4541 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004542 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004543 } catch (ImsException e) {
4544 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004545 } finally {
4546 Binder.restoreCallingIdentity(identity);
4547 }
4548 }
4549
4550 @Override
4551 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4553 "setRttCapabilityEnabled");
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004556 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004557 // This setting doesn't require an active ImsService connection, so do not verify. The
4558 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004559 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004560 } catch (ImsException e) {
4561 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004562 } finally {
4563 Binder.restoreCallingIdentity(identity);
4564 }
4565 }
4566
shilu366312e2019-12-17 09:28:10 -08004567 /**
4568 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4569 * @param subId The subscription to use to check the configuration.
4570 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004571 @Override
4572 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004573 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004574 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004575 final long identity = Binder.clearCallingIdentity();
4576 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004577 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004578 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004579 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004580 } catch (ImsException e) {
4581 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
4585 }
4586
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004587 @Override
4588 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4589 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004590
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004591 final long identity = Binder.clearCallingIdentity();
4592 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004593 if (!isImsAvailableOnDevice()) {
4594 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4595 "IMS not available on device.");
4596 }
4597 int slotId = getSlotIndexOrException(subId);
4598 verifyImsMmTelConfiguredOrThrow(slotId);
4599 ImsManager.getInstance(mApp, slotId)
4600 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004601 } catch (ImsException e) {
4602 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004603 } finally {
4604 Binder.restoreCallingIdentity(identity);
4605 }
4606 }
4607
4608 @Override
4609 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4610 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004611
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004612 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004613 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4614 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4615 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004616 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004617 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004618 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004619 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004620 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4621 + "is inactive, ignoring unregister.");
4622 // If the subscription is no longer active, just return, since the callback will already
4623 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004624 } finally {
4625 Binder.restoreCallingIdentity(identity);
4626 }
4627 }
4628
joonhunshincffb7fc2021-11-28 07:32:01 +00004629 @Override
4630 public void registerFeatureProvisioningChangedCallback(int subId,
4631 IFeatureProvisioningCallback callback) {
4632 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4633 mApp, subId, "registerFeatureProvisioningChangedCallback");
4634
4635 final long identity = Binder.clearCallingIdentity();
4636 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4637 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4638 }
4639
joonhunshin91bc1952022-04-29 08:47:15 +00004640 try {
4641 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4642 if (controller == null) {
4643 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4644 "Device does not support IMS");
4645 }
4646 controller.addFeatureProvisioningChangedCallback(subId, callback);
4647 } finally {
4648 Binder.restoreCallingIdentity(identity);
4649 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004650 }
4651
4652 @Override
4653 public void unregisterFeatureProvisioningChangedCallback(int subId,
4654 IFeatureProvisioningCallback callback) {
4655 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4656 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4657
4658 final long identity = Binder.clearCallingIdentity();
4659 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4660 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4661 }
4662
joonhunshin91bc1952022-04-29 08:47:15 +00004663 try {
4664 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4665 if (controller == null) {
4666 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4667 return;
4668 }
4669 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4670 } finally {
4671 Binder.restoreCallingIdentity(identity);
4672 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004673 }
allenwtsu99c623b2020-01-03 18:24:23 +08004674
4675 private void checkModifyPhoneStatePermission(int subId, String message) {
4676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4677 message);
4678 }
4679
allenwtsu99c623b2020-01-03 18:24:23 +08004680 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004681 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004682 boolean isProvisioned) {
4683 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4684
4685 final long identity = Binder.clearCallingIdentity();
4686 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004687 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4688 if (controller == null) {
4689 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4690 return;
4691 }
4692 controller.setRcsProvisioningStatusForCapability(
4693 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004694 } finally {
4695 Binder.restoreCallingIdentity(identity);
4696 }
allenwtsu99c623b2020-01-03 18:24:23 +08004697 }
4698
4699
4700 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004701 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4702 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4703 mApp, subId, "getRcsProvisioningStatusForCapability");
4704
allenwtsu99c623b2020-01-03 18:24:23 +08004705 final long identity = Binder.clearCallingIdentity();
4706 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004707 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4708 if (controller == null) {
4709 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4710
4711 // device does not support IMS, this method will return true always.
4712 return true;
4713 }
4714 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004715 } finally {
4716 Binder.restoreCallingIdentity(identity);
4717 }
4718 }
4719
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004720 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004721 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4722 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004723 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004724
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004725 final long identity = Binder.clearCallingIdentity();
4726 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004727 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4728 if (controller == null) {
4729 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4730 return;
4731 }
4732 controller.setImsProvisioningStatusForCapability(
4733 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 } finally {
4735 Binder.restoreCallingIdentity(identity);
4736 }
4737 }
4738
4739 @Override
4740 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004741 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4742 mApp, subId, "getProvisioningStatusForCapability");
4743
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004744 final long identity = Binder.clearCallingIdentity();
4745 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004746 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4747 if (controller == null) {
4748 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004749
joonhunshin91bc1952022-04-29 08:47:15 +00004750 // device does not support IMS, this method will return true always.
4751 return true;
4752 }
4753 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004754 } finally {
4755 Binder.restoreCallingIdentity(identity);
4756 }
4757 }
4758
4759 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004760 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4761 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4762 mApp, subId, "isProvisioningRequiredForCapability");
4763
4764 final long identity = Binder.clearCallingIdentity();
4765 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004766 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4767 if (controller == null) {
4768 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4769
4770 // device does not support IMS, this method will return false
4771 return false;
4772 }
4773 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004774 } finally {
4775 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004776 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004777 }
4778
4779 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004780 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4781 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4782 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004783
joonhunshincffb7fc2021-11-28 07:32:01 +00004784 final long identity = Binder.clearCallingIdentity();
4785 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004786 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4787 if (controller == null) {
4788 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4789
4790 // device does not support IMS, this method will return false
4791 return false;
4792 }
4793 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004794 } finally {
4795 Binder.restoreCallingIdentity(identity);
4796 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004797 }
4798
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004799 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004800 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004801 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4802 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4803 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004804 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4805 mApp, subId, "getImsProvisioningInt");
4806
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004807 final long identity = Binder.clearCallingIdentity();
4808 try {
4809 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004810 int slotId = getSlotIndex(subId);
4811 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4812 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4813 + subId + "' for key:" + key);
4814 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4815 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004816
joonhunshin91bc1952022-04-29 08:47:15 +00004817 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4818 if (controller == null) {
4819 loge("getImsProvisioningInt: Device does not support IMS");
4820
4821 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4822 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4823 }
4824 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004825 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4826 return retVal;
4827 }
4828
calvinpanb5a34062021-02-08 19:59:36 +08004829 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004830 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004831 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4832 + subId + "' for key:" + key);
4833 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004834 } finally {
4835 Binder.restoreCallingIdentity(identity);
4836 }
4837 }
4838
4839 @Override
4840 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004841 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4842 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4843 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004844 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4845 mApp, subId, "getImsProvisioningString");
4846
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004847 final long identity = Binder.clearCallingIdentity();
4848 try {
4849 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004850 int slotId = getSlotIndex(subId);
4851 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4852 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4853 + subId + "' for key:" + key);
4854 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4855 }
calvinpanb5a34062021-02-08 19:59:36 +08004856 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004857 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004858 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4859 + subId + "' for key:" + key);
4860 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
4864 }
4865
4866 @Override
4867 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004868 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4869 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4870 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4872 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004873
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004874 final long identity = Binder.clearCallingIdentity();
4875 try {
4876 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004877 int slotId = getSlotIndex(subId);
4878 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4879 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4880 + subId + "' for key:" + key);
4881 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4882 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004883
joonhunshin91bc1952022-04-29 08:47:15 +00004884 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4885 if (controller == null) {
4886 loge("setImsProvisioningInt: Device does not support IMS");
4887
4888 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
4889 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4890 }
4891 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00004892 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4893 return retVal;
4894 }
4895
calvinpanb5a34062021-02-08 19:59:36 +08004896 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4897 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004898 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004899 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004900 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
4904 }
4905
4906 @Override
4907 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004908 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4909 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4910 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4912 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004913 final long identity = Binder.clearCallingIdentity();
4914 try {
4915 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004916 int slotId = getSlotIndex(subId);
4917 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4918 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4919 + subId + "' for key:" + key);
4920 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4921 }
calvinpanb5a34062021-02-08 19:59:36 +08004922 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4923 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004924 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004925 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004926 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004927 } finally {
4928 Binder.restoreCallingIdentity(identity);
4929 }
4930 }
4931
Brad Ebinger919631e2021-06-02 17:46:35 -07004932 /**
4933 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4934 * for the given slot ID or no ImsResolver instance has been created.
4935 * @param slotId The slot ID that the IMS service is created for.
4936 * @throws ImsException If there is no ImsService configured for this slot.
4937 */
4938 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4939 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4940 ImsFeature.FEATURE_MMTEL)) {
4941 throw new ImsException("This subscription does not support MMTEL over IMS",
4942 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4943 }
4944 }
4945
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004946 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004947 int slotId = SubscriptionManager.getSlotIndex(subId);
4948 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004949 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4950 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004951 }
4952 return slotId;
4953 }
4954
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004955 private int getSlotIndex(int subId) {
4956 int slotId = SubscriptionManager.getSlotIndex(subId);
4957 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4958 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4959 }
4960 return slotId;
4961 }
4962
Wink Saville36469e72014-06-11 15:17:00 -07004963 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004964 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004965 */
4966 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004967 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4968 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004969 try {
4970 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4971 } catch (SecurityException se) {
4972 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4973 throw new SecurityException("Package " + callingPackage + " does not belong to "
4974 + Binder.getCallingUid());
4975 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004976 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004977 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004978 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004979 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004980 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004981 mApp, subId, callingPackage, callingFeatureId,
4982 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004983 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4984 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986 final long identity = Binder.clearCallingIdentity();
4987 try {
4988 final Phone phone = getPhone(subId);
4989 if (phone != null) {
4990 return phone.getServiceState().getDataNetworkType();
4991 } else {
4992 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4993 }
4994 } finally {
4995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004997 }
4998
4999 /**
5000 * Returns the data network type
5001 */
5002 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005003 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005004 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5005 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005006 }
5007
5008 /**
5009 * Returns the data network type for a subId
5010 */
5011 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005012 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5013 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005014 String functionName = "getDataNetworkTypeForSubscriber";
5015 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5016 mApp, functionName)) {
5017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5018 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5019 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5020 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005021 }
5022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 final long identity = Binder.clearCallingIdentity();
5024 try {
5025 final Phone phone = getPhone(subId);
5026 if (phone != null) {
5027 return phone.getServiceState().getDataNetworkType();
5028 } else {
5029 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5030 }
5031 } finally {
5032 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005033 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005034 }
5035
5036 /**
Wink Saville36469e72014-06-11 15:17:00 -07005037 * Returns the Voice network type for a subId
5038 */
5039 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005040 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5041 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005042 String functionName = "getVoiceNetworkTypeForSubscriber";
5043 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5044 mApp, functionName)) {
5045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5046 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5047 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5048 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005049 }
5050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005051 final long identity = Binder.clearCallingIdentity();
5052 try {
5053 final Phone phone = getPhone(subId);
5054 if (phone != null) {
5055 return phone.getServiceState().getVoiceNetworkType();
5056 } else {
5057 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5058 }
5059 } finally {
5060 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005062 }
5063
5064 /**
5065 * @return true if a ICC card is present
5066 */
5067 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005068 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005069 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5070 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005071 }
5072
5073 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005074 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005075 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005076 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005077 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 final long identity = Binder.clearCallingIdentity();
5079 try {
5080 final Phone phone = PhoneFactory.getPhone(slotIndex);
5081 if (phone != null) {
5082 return phone.getIccCard().hasIccCard();
5083 } else {
5084 return false;
5085 }
5086 } finally {
5087 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005089 }
5090
5091 /**
5092 * Return if the current radio is LTE on CDMA. This
5093 * is a tri-state return value as for a period of time
5094 * the mode may be unknown.
5095 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005096 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005097 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005098 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005099 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005100 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005101 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5102 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5103 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005104 }
5105
Sanket Padawe356d7632015-06-22 14:03:32 -07005106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005107 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5108 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005109 try {
5110 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5111 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005112 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5113 }
5114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 final Phone phone = getPhone(subId);
5118 if (phone == null) {
5119 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5120 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005121 return TelephonyProperties.lte_on_cdma_device()
5122 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123 }
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005126 }
Wink Saville36469e72014-06-11 15:17:00 -07005127 }
5128
Wink Saville36469e72014-06-11 15:17:00 -07005129 /**
5130 * {@hide}
5131 * Returns Default subId, 0 in the case of single standby.
5132 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005133 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005134 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005135 }
5136
Shishir Agrawala9f32182016-04-12 12:00:16 -07005137 private int getSlotForDefaultSubscription() {
5138 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5139 }
5140
Wink Savilleb564aae2014-10-23 10:18:09 -07005141 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005142 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005143 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005144
Pengquan Menge92a50d2018-09-21 15:54:48 -07005145 private boolean isActiveSubscription(int subId) {
5146 return mSubscriptionController.isActiveSubId(subId);
5147 }
5148
Ihab Awadf2177b72013-11-25 13:33:23 -08005149 /**
5150 * @see android.telephony.TelephonyManager.WifiCallingChoices
5151 */
5152 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 final long identity = Binder.clearCallingIdentity();
5154 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005155 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5157 getWhenToMakeWifiCallsDefaultPreference());
5158 } finally {
5159 Binder.restoreCallingIdentity(identity);
5160 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005161 }
5162
5163 /**
5164 * @see android.telephony.TelephonyManager.WifiCallingChoices
5165 */
5166 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167 final long identity = Binder.clearCallingIdentity();
5168 try {
5169 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005170 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005175 }
5176
Sailesh Nepald1e68152013-12-12 19:08:02 -08005177 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005178 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005179 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005180 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005181
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005182 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5183 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5184 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005185 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005186 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5187 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005188 }
5189 return PhoneFactory.getPhone(phoneId);
5190 }
5191
Shishir Agrawal566b7612013-10-28 14:41:00 -07005192 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005193 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005194 @NonNull IccLogicalChannelRequest request) {
5195 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5196 /*message=*/ "iccOpenLogicalChannel");
5197
5198 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5199 // Verify that the callingPackage in the request belongs to the calling UID
5200 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5201
5202 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005203 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005204
Rambo Wanga1782702021-11-10 20:15:19 -08005205 private Phone getPhoneFromValidIccLogicalChannelRequest(
5206 @NonNull IccLogicalChannelRequest request, String message) {
5207 Phone phone;
5208 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5210 mApp, request.subId, message);
5211 phone = getPhoneFromSubId(request.subId);
5212 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5213 enforceModifyPermission();
5214 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5215 } else {
5216 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005217 }
Rambo Wanga1782702021-11-10 20:15:19 -08005218 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005219 }
5220
5221 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005222 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005225 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005227 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5228 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005229 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5230 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 loge("The calling package is not allowed to access ISD-R.");
5232 throw new SecurityException(
5233 "The calling package is not allowed to access ISD-R.");
5234 }
Derek Tan740e1672017-06-27 14:56:27 -07005235 }
Derek Tan740e1672017-06-27 14:56:27 -07005236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005238 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5239 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005240 return response;
5241 } finally {
5242 Binder.restoreCallingIdentity(identity);
5243 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005244 }
5245
5246 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005247 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5248 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5249 /*message=*/"iccCloseLogicalChannel");
5250
5251 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5252
5253 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005254 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005255
Rambo Wanga1782702021-11-10 20:15:19 -08005256 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5257 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005258 // before this feature is enabled, this API should only return false if
5259 // the operation fails instead of throwing runtime exception for
5260 // backward-compatibility.
5261 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5262 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 final long identity = Binder.clearCallingIdentity();
5264 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005265 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005266 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267 }
Chen Xue9d737e2022-01-01 23:41:31 -08005268 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005269 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005270 Boolean success = false;
5271 if (result instanceof RuntimeException) {
5272 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005273 if (shouldThrowExceptionOnFailure) {
5274 throw (RuntimeException) result;
5275 } else {
5276 return false;
5277 }
Chen Xue9d737e2022-01-01 23:41:31 -08005278 } else if (result instanceof Boolean) {
5279 success = (Boolean) result;
5280 } else {
5281 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5282 }
Rambo Wanga1782702021-11-10 20:15:19 -08005283 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 return success;
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005287 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005288 }
5289
5290 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005291 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005292 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5294 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005295 if (DBG) {
5296 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5297 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5298 + p3 + " data=" + data);
5299 }
5300 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5301 command, p1, p2, p3, data);
5302 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005303
Jordan Liu4c733742019-02-28 12:03:40 -08005304 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005305 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5306 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005307 enforceModifyPermission();
5308 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005309 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5310 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5311 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005312 }
5313 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005314 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5315 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005316 }
5317
5318 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5319 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 final long identity = Binder.clearCallingIdentity();
5321 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005322 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 return "";
5324 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005327 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5328 null /* workSource */);
5329 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 // Append the returned status code to the end of the response payload.
5332 String s = Integer.toHexString(
5333 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5334 if (response.payload != null) {
5335 s = IccUtils.bytesToHexString(response.payload) + s;
5336 }
5337 return s;
5338 } finally {
5339 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005340 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005341 }
Jake Hambye994d462014-02-03 13:10:13 -08005342
Evan Charltonc66da362014-05-16 14:06:40 -07005343 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005344 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5345 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5347 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005349 if (DBG) {
5350 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5351 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5352 }
5353 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5354 cla, command, p1, p2, p3, data);
5355 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005356
Jordan Liu4c733742019-02-28 12:03:40 -08005357 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005358 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5359 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005360 enforceModifyPermission();
5361 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5362 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005363 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5364 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5365 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005366 }
5367
5368 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005369 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5370 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005371 }
5372
5373 // open APDU basic channel assuming the caller has sufficient permissions
5374 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5375 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 final long identity = Binder.clearCallingIdentity();
5377 try {
5378 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5379 && TextUtils.equals(ISDR_AID, data)) {
5380 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005381 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5382 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 if (bestComponent == null
5384 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5385 loge("The calling package is not allowed to select ISD-R.");
5386 throw new SecurityException(
5387 "The calling package is not allowed to select ISD-R.");
5388 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005389 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005392 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5393 null /* workSource */);
5394 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 // Append the returned status code to the end of the response payload.
5397 String s = Integer.toHexString(
5398 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5399 if (response.payload != null) {
5400 s = IccUtils.bytesToHexString(response.payload) + s;
5401 }
5402 return s;
5403 } finally {
5404 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005405 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005406 }
5407
5408 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005409 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005410 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5412 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005413
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414 final long identity = Binder.clearCallingIdentity();
5415 try {
5416 if (DBG) {
5417 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5418 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5419 }
5420
5421 IccIoResult response =
5422 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5423 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5424 subId);
5425
5426 if (DBG) {
5427 log("Exchange SIM_IO [R]" + response);
5428 }
5429
5430 byte[] result = null;
5431 int length = 2;
5432 if (response.payload != null) {
5433 length = 2 + response.payload.length;
5434 result = new byte[length];
5435 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5436 } else {
5437 result = new byte[length];
5438 }
5439
5440 result[length - 1] = (byte) response.sw2;
5441 result[length - 2] = (byte) response.sw1;
5442 return result;
5443 } finally {
5444 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005445 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005446 }
5447
Nathan Haroldb3014052017-01-25 15:57:32 -08005448 /**
5449 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5450 * on a particular subscription
5451 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005452 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5453 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005454 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005455 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005456 return null;
5457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458
5459 final long identity = Binder.clearCallingIdentity();
5460 try {
5461 if (appType != TelephonyManager.APPTYPE_USIM
5462 && appType != TelephonyManager.APPTYPE_SIM) {
5463 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5464 return null;
5465 }
5466 Object response = sendRequest(
5467 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5468 if (response instanceof String[]) {
5469 return (String[]) response;
5470 }
yincheng zhao2737e882019-09-06 17:06:54 -07005471 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005473 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 } finally {
5475 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005476 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005477 }
5478
yincheng zhao2737e882019-09-06 17:06:54 -07005479 /**
5480 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5481 * subscription.
5482 *
5483 * @param subId the id of the subscription.
5484 * @param appType the uicc app type, must be USIM or SIM.
5485 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5486 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005487 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005488 * @return number of fplmns that is successfully written to the SIM.
5489 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005490 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5491 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5493 mApp, subId, "setForbiddenPlmns");
5494
yincheng zhao2737e882019-09-06 17:06:54 -07005495 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5496 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5497 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5498 }
5499 if (fplmns == null) {
5500 throw new IllegalArgumentException("Fplmn List provided is null");
5501 }
5502 for (String fplmn : fplmns) {
5503 if (!CellIdentity.isValidPlmn(fplmn)) {
5504 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5505 }
5506 }
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 Object response = sendRequest(
5510 CMD_SET_FORBIDDEN_PLMNS,
5511 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5512 subId);
5513 return (int) response;
5514 } finally {
5515 Binder.restoreCallingIdentity(identity);
5516 }
5517 }
5518
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005519 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005520 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5522 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 final long identity = Binder.clearCallingIdentity();
5525 try {
5526 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5527 if (response.payload == null) {
5528 return "";
5529 }
Evan Charltonc66da362014-05-16 14:06:40 -07005530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 // Append the returned status code to the end of the response payload.
5532 String s = Integer.toHexString(
5533 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5534 s = IccUtils.bytesToHexString(response.payload) + s;
5535 return s;
5536 } finally {
5537 Binder.restoreCallingIdentity(identity);
5538 }
Evan Charltonc66da362014-05-16 14:06:40 -07005539 }
5540
Jake Hambye994d462014-02-03 13:10:13 -08005541 /**
5542 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5543 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5544 *
5545 * @param itemID the ID of the item to read
5546 * @return the NV item as a String, or null on error.
5547 */
5548 @Override
5549 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005550 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5552 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553
5554 final long identity = Binder.clearCallingIdentity();
5555 try {
5556 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005557 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5559 return value;
5560 } finally {
5561 Binder.restoreCallingIdentity(identity);
5562 }
Jake Hambye994d462014-02-03 13:10:13 -08005563 }
5564
5565 /**
5566 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5567 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5568 *
5569 * @param itemID the ID of the item to read
5570 * @param itemValue the value to write, as a String
5571 * @return true on success; false on any failure
5572 */
5573 @Override
5574 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005575 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5577 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578
5579 final long identity = Binder.clearCallingIdentity();
5580 try {
5581 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5582 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005583 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5585 return success;
5586 } finally {
5587 Binder.restoreCallingIdentity(identity);
5588 }
Jake Hambye994d462014-02-03 13:10:13 -08005589 }
5590
5591 /**
5592 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5593 * Used for device configuration by some CDMA operators.
5594 *
5595 * @param preferredRoamingList byte array containing the new PRL
5596 * @return true on success; false on any failure
5597 */
5598 @Override
5599 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5601 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602
5603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5606 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5607 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5608 return success;
5609 } finally {
5610 Binder.restoreCallingIdentity(identity);
5611 }
Jake Hambye994d462014-02-03 13:10:13 -08005612 }
5613
5614 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005615 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005616 * Used for device configuration by some CDMA operators.
5617 *
chen xu6dac5ab2018-10-26 17:39:23 -07005618 * @param slotIndex - device slot.
5619 *
Jake Hambye994d462014-02-03 13:10:13 -08005620 * @return true on success; false on any failure
5621 */
5622 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005623 public boolean resetModemConfig(int slotIndex) {
5624 Phone phone = PhoneFactory.getPhone(slotIndex);
5625 if (phone != null) {
5626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5627 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628
chen xu6dac5ab2018-10-26 17:39:23 -07005629 final long identity = Binder.clearCallingIdentity();
5630 try {
5631 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5632 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5633 return success;
5634 } finally {
5635 Binder.restoreCallingIdentity(identity);
5636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 }
chen xu6dac5ab2018-10-26 17:39:23 -07005638 return false;
5639 }
5640
5641 /**
5642 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5643 *
5644 * @param slotIndex - device slot.
5645 *
5646 * @return true on success; false on any failure
5647 */
5648 @Override
5649 public boolean rebootModem(int slotIndex) {
5650 Phone phone = PhoneFactory.getPhone(slotIndex);
5651 if (phone != null) {
5652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5653 mApp, phone.getSubId(), "rebootModem");
5654
5655 final long identity = Binder.clearCallingIdentity();
5656 try {
5657 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5658 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5659 return success;
5660 } finally {
5661 Binder.restoreCallingIdentity(identity);
5662 }
5663 }
5664 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005665 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005666
Brad Ebinger51f743a2017-01-23 13:50:20 -08005667 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005668 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5669 * {@link #disableIms(int)}.
5670 * @param slotIndex device slot.
5671 */
5672 public void resetIms(int slotIndex) {
5673 enforceModifyPermission();
5674
5675 final long identity = Binder.clearCallingIdentity();
5676 try {
5677 if (mImsResolver == null) {
5678 // may happen if the does not support IMS.
5679 return;
5680 }
5681 mImsResolver.disableIms(slotIndex);
5682 mImsResolver.enableIms(slotIndex);
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
5686 }
5687
5688 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005689 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5690 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005691 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005692 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005693 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694
5695 final long identity = Binder.clearCallingIdentity();
5696 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005697 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005698 // may happen if the device does not support IMS.
5699 return;
5700 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005701 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 } finally {
5703 Binder.restoreCallingIdentity(identity);
5704 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005705 }
5706
5707 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005708 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5709 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005710 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005711 public void disableIms(int slotId) {
5712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713
5714 final long identity = Binder.clearCallingIdentity();
5715 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005716 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005717 // may happen if the device does not support IMS.
5718 return;
5719 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005720 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721 } finally {
5722 Binder.restoreCallingIdentity(identity);
5723 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005724 }
5725
5726 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005727 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5728 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005729 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005730 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005731 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005732 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733
5734 final long identity = Binder.clearCallingIdentity();
5735 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005736 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005737 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5738 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005739 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005740 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005744 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005745 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005746 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5747 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005748 @Override
5749 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005750 enforceModifyPermission();
5751
5752 final long identity = Binder.clearCallingIdentity();
5753 try {
5754 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005755 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005756 } finally {
5757 Binder.restoreCallingIdentity(identity);
5758 }
5759 }
5760
5761 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005762 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005763 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005764 */
5765 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5766 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767
5768 final long identity = Binder.clearCallingIdentity();
5769 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005770 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005771 // may happen if the device does not support IMS.
5772 return null;
5773 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005774 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005778 }
5779
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005780 /**
5781 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005782 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005783 */
5784 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5785 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786
5787 final long identity = Binder.clearCallingIdentity();
5788 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005790 // may happen if the device does not support IMS.
5791 return null;
5792 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005793 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005797 }
5798
Brad Ebinger884c07b2018-02-15 16:17:40 -08005799 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005800 * Sets the ImsService Package Name that Telephony will bind to.
5801 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005802 * @param slotIndex the slot ID that the ImsService should bind for.
5803 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005804 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005805 * @param featureTypes An integer array of feature types associated with a packageName.
5806 * @param packageName The name of the package that the current configuration will be replaced
5807 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005808 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005809 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005810 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5811 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005812 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yude40a3f2022-11-19 22:29:12 -08005814 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816 final long identity = Binder.clearCallingIdentity();
5817 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005818 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005819 // may happen if the device does not support IMS.
5820 return false;
5821 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005822 Map<Integer, String> featureConfig = new HashMap<>();
5823 for (int featureType : featureTypes) {
5824 featureConfig.put(featureType, packageName);
5825 }
5826 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5827 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005828 } finally {
5829 Binder.restoreCallingIdentity(identity);
5830 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005831 }
5832
5833 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005834 * Clears any carrier ImsService overrides for the slot index specified that were previously
5835 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5836 *
5837 * This should only be used for testing.
5838 *
5839 * @param slotIndex the slot ID that the ImsService should bind for.
5840 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5841 */
5842 @Override
5843 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08005844 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5845 "clearCarrierImsServiceOverride");
5846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yude40a3f2022-11-19 22:29:12 -08005847 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08005848
5849 final long identity = Binder.clearCallingIdentity();
5850 try {
5851 if (mImsResolver == null) {
5852 // may happen if the device does not support IMS.
5853 return false;
5854 }
5855 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5856 } finally {
5857 Binder.restoreCallingIdentity(identity);
5858 }
5859 }
5860
5861 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005862 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005863 *
5864 * @param slotId The slot that the ImsService is associated with.
5865 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5866 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005868 * @return the package name of the ImsService configuration.
5869 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005870 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5871 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005872 TelephonyPermissions
Jack Yude40a3f2022-11-19 22:29:12 -08005873 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
5874 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005875
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005876 final long identity = Binder.clearCallingIdentity();
5877 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005878 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005879 // may happen if the device does not support IMS.
5880 return "";
5881 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005882 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005883 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5884 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005885 } finally {
5886 Binder.restoreCallingIdentity(identity);
5887 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005888 }
5889
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005890 /**
5891 * Get the MmTelFeature state associated with the requested subscription id.
5892 * @param subId The subscription that the MmTelFeature is associated with.
5893 * @param callback A callback with an integer containing the
5894 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5895 */
5896 @Override
5897 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5898 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005899 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5900 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5901 "IMS not available on device.");
5902 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005903 final long token = Binder.clearCallingIdentity();
5904 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005905 int slotId = getSlotIndex(subId);
5906 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5907 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5908 + subId + "'");
5909 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5910 }
5911 verifyImsMmTelConfiguredOrThrow(slotId);
5912 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5913 try {
5914 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5915 } catch (RemoteException e) {
5916 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5917 + "Ignore");
5918 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005919 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005920 } catch (ImsException e) {
5921 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005922 } finally {
5923 Binder.restoreCallingIdentity(token);
5924 }
5925 }
5926
Daniel Brightbb5840b2021-01-12 15:48:18 -08005927 /**
5928 * Sets the ims registration state on all valid {@link Phone}s.
5929 */
5930 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005931 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932
5933 final long identity = Binder.clearCallingIdentity();
5934 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005935 // NOTE: Before S, this method only set the default phone.
5936 for (final Phone phone : PhoneFactory.getPhones()) {
5937 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5938 phone.setImsRegistrationState(registered);
5939 }
5940 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
Wink Saville36469e72014-06-11 15:17:00 -07005944 }
5945
5946 /**
Stuart Scott54788802015-03-30 13:18:01 -07005947 * Set the network selection mode to automatic.
5948 *
5949 */
5950 @Override
5951 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5953 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954
5955 final long identity = Binder.clearCallingIdentity();
5956 try {
shilufc958392020-01-20 11:36:01 -08005957 if (!isActiveSubscription(subId)) {
5958 return;
5959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005961 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5962 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
Stuart Scott54788802015-03-30 13:18:01 -07005966 }
5967
Jack Yud10cdd42020-09-28 20:28:01 -07005968 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005969 * Ask the radio to connect to the input network and change selection mode to manual.
5970 *
5971 * @param subId the id of the subscription.
5972 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5973 * the operator to attach to.
5974 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5975 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5976 * normal network selection next time.
5977 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005978 */
5979 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005980 public boolean setNetworkSelectionModeManual(
5981 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5983 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005984
5985 if (!isActiveSubscription(subId)) {
5986 return false;
5987 }
5988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989 final long identity = Binder.clearCallingIdentity();
5990 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005991 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005993 if (DBG) {
5994 log("setNetworkSelectionModeManual: subId: " + subId
5995 + " operator: " + operatorInfo);
5996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5998 } finally {
5999 Binder.restoreCallingIdentity(identity);
6000 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006001 }
shilu84f6e8b2019-12-19 13:58:01 -08006002 /**
6003 * Get the manual network selection
6004 *
6005 * @param subId the id of the subscription.
6006 *
6007 * @return the previously saved user selected PLMN
6008 */
6009 @Override
6010 public String getManualNetworkSelectionPlmn(int subId) {
6011 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006012 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006013 mApp, subId, "getManualNetworkSelectionPlmn");
6014
6015 final long identity = Binder.clearCallingIdentity();
6016 try {
6017 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006018 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006019 }
6020
6021 final Phone phone = getPhone(subId);
6022 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006023 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006024 }
6025 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6026 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6027 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6028 } finally {
6029 Binder.restoreCallingIdentity(identity);
6030 }
6031 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006032
6033 /**
6034 * Scans for available networks.
6035 */
6036 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006037 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6038 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6040 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006041 LocationAccessPolicy.LocationPermissionResult locationResult =
6042 LocationAccessPolicy.checkLocationPermission(mApp,
6043 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6044 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006045 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006046 .setCallingPid(Binder.getCallingPid())
6047 .setCallingUid(Binder.getCallingUid())
6048 .setMethod("getCellNetworkScanResults")
6049 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006050 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6051 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006052 .build());
6053 switch (locationResult) {
6054 case DENIED_HARD:
6055 throw new SecurityException("Not allowed to access scan results -- location");
6056 case DENIED_SOFT:
6057 return null;
6058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059
Pengquan Menga1bb6272018-09-06 09:59:22 -07006060 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061 try {
6062 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006063 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 } finally {
6066 Binder.restoreCallingIdentity(identity);
6067 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006068 }
6069
6070 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006071 * Get the call forwarding info, given the call forwarding reason.
6072 */
6073 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006074 public void getCallForwarding(int subId, int callForwardingReason,
6075 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006076 enforceReadPrivilegedPermission("getCallForwarding");
6077 long identity = Binder.clearCallingIdentity();
6078 try {
6079 if (DBG) {
6080 log("getCallForwarding: subId " + subId
6081 + " callForwardingReason" + callForwardingReason);
6082 }
Hall Liu27d24262020-09-18 19:04:59 -07006083
6084 Phone phone = getPhone(subId);
6085 if (phone == null) {
6086 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006087 callback.onError(
6088 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006089 } catch (RemoteException e) {
6090 // ignore
6091 }
6092 return;
6093 }
6094
6095 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6096 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6097 @Override
6098 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6099 try {
6100 callback.onCallForwardingInfoAvailable(info);
6101 } catch (RemoteException e) {
6102 // ignore
6103 }
6104 }
6105
6106 @Override
6107 public void onError(int error) {
6108 try {
6109 callback.onError(error);
6110 } catch (RemoteException e) {
6111 // ignore
6112 }
6113 }
6114 });
6115 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006116 } finally {
6117 Binder.restoreCallingIdentity(identity);
6118 }
6119 }
6120
6121 /**
6122 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6123 * reason, the number to forward, and the timeout before the forwarding is attempted.
6124 */
6125 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006126 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6127 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006128 enforceModifyPermission();
6129 long identity = Binder.clearCallingIdentity();
6130 try {
6131 if (DBG) {
6132 log("setCallForwarding: subId " + subId
6133 + " callForwardingInfo" + callForwardingInfo);
6134 }
Hall Liu27d24262020-09-18 19:04:59 -07006135
6136 Phone phone = getPhone(subId);
6137 if (phone == null) {
6138 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006139 callback.accept(
6140 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006141 } catch (RemoteException e) {
6142 // ignore
6143 }
6144 return;
6145 }
6146
6147 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6148 FunctionalUtils.ignoreRemoteException(callback::accept));
6149
6150 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006151 } finally {
6152 Binder.restoreCallingIdentity(identity);
6153 }
6154 }
6155
6156 /**
Hall Liu27d24262020-09-18 19:04:59 -07006157 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006158 */
6159 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006160 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006161 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006162 long identity = Binder.clearCallingIdentity();
6163 try {
Hall Liu27d24262020-09-18 19:04:59 -07006164 Phone phone = getPhone(subId);
6165 if (phone == null) {
6166 try {
6167 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6168 } catch (RemoteException e) {
6169 // ignore
6170 }
6171 return;
6172 }
SongFerngWang0e767992021-03-31 22:08:45 +08006173 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6174 PersistableBundle c = configManager.getConfigForSubId(subId);
6175 boolean requireUssd = c.getBoolean(
6176 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006177
Shuo Qian4a594052020-01-23 11:59:30 -08006178 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006179 if (requireUssd) {
6180 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6181 getSubscriptionCarrierId(subId));
6182 String newUssdCommand = "";
6183 try {
6184 newUssdCommand = carrierXmlParser.getFeature(
6185 CarrierXmlParser.FEATURE_CALL_WAITING)
6186 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6187 } catch (NullPointerException e) {
6188 loge("Failed to generate USSD number" + e);
6189 }
6190 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6191 mMainThreadHandler, callback, carrierXmlParser,
6192 CarrierXmlParser.SsEntry.SSAction.QUERY);
6193 final String ussdCommand = newUssdCommand;
6194 Executors.newSingleThreadExecutor().execute(() -> {
6195 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6196 });
6197 } else {
6198 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6199 callback::accept);
6200 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6201 }
Shuo Qian4a594052020-01-23 11:59:30 -08006202 } finally {
6203 Binder.restoreCallingIdentity(identity);
6204 }
6205 }
6206
6207 /**
Hall Liu27d24262020-09-18 19:04:59 -07006208 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006209 */
6210 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006211 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006212 enforceModifyPermission();
6213 long identity = Binder.clearCallingIdentity();
6214 try {
Hall Liu27d24262020-09-18 19:04:59 -07006215 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6216
6217 Phone phone = getPhone(subId);
6218 if (phone == null) {
6219 try {
6220 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6221 } catch (RemoteException e) {
6222 // ignore
6223 }
6224 return;
6225 }
6226
SongFerngWang0e767992021-03-31 22:08:45 +08006227 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6228 PersistableBundle c = configManager.getConfigForSubId(subId);
6229 boolean requireUssd = c.getBoolean(
6230 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006231
SongFerngWang0e767992021-03-31 22:08:45 +08006232 if (DBG) log("getCallWaitingStatus: subId " + subId);
6233 if (requireUssd) {
6234 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6235 getSubscriptionCarrierId(subId));
6236 CarrierXmlParser.SsEntry.SSAction ssAction =
6237 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6238 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6239 String newUssdCommand = "";
6240 try {
6241 newUssdCommand = carrierXmlParser.getFeature(
6242 CarrierXmlParser.FEATURE_CALL_WAITING)
6243 .makeCommand(ssAction, null);
6244 } catch (NullPointerException e) {
6245 loge("Failed to generate USSD number" + e);
6246 }
6247 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6248 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6249 final String ussdCommand = newUssdCommand;
6250 Executors.newSingleThreadExecutor().execute(() -> {
6251 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6252 });
6253 } else {
6254 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6255 FunctionalUtils.ignoreRemoteException(callback::accept));
6256
6257 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6258 }
Shuo Qian4a594052020-01-23 11:59:30 -08006259 } finally {
6260 Binder.restoreCallingIdentity(identity);
6261 }
6262 }
6263
6264 /**
yinxub1bed742017-04-17 11:45:04 -07006265 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006266 *
yinxub1bed742017-04-17 11:45:04 -07006267 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006268 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6269 * location related information which will be sent if the caller already possess
6270 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006271 * @param request contains the radio access networks with bands/channels to scan
6272 * @param messenger callback messenger for scan results or errors
6273 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006274 * @return the id of the requested scan which can be used to stop the scan.
6275 */
6276 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006277 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6278 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006279 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6281 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006282 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006283 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6284 if (!renounceFineLocationAccess) {
6285 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6286 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6287 .setCallingPackage(callingPackage)
6288 .setCallingFeatureId(callingFeatureId)
6289 .setCallingPid(Binder.getCallingPid())
6290 .setCallingUid(Binder.getCallingUid())
6291 .setMethod("requestNetworkScan")
6292 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6293 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6294 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6295 .build());
6296 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006297 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006298 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6299 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006300 if (e != null) {
6301 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6302 throw e;
6303 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006304 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006305 return TelephonyScanManager.INVALID_SCAN_ID;
6306 }
6307 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308 }
Hall Liu912dfd32019-04-25 14:02:26 -07006309 int callingUid = Binder.getCallingUid();
6310 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006311 final long identity = Binder.clearCallingIdentity();
6312 try {
6313 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006314 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006315 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006316 } finally {
6317 Binder.restoreCallingIdentity(identity);
6318 }
yinxu504e1392017-04-12 16:03:22 -07006319 }
6320
Hall Liub2ac8ef2019-02-28 15:56:23 -08006321 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006322 NetworkScanRequest request, int subId, String callingPackage) {
6323 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006324 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6325 boolean hasNetworkScanPermission =
6326 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6327 == PERMISSION_GRANTED;
6328
6329 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6330 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6331 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006332 }
6333
6334 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6335 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006336 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6337 return new SecurityException("Specific channels must not be"
6338 + " scanned without location access.");
6339 }
6340 }
6341 }
6342
Hall Liub2ac8ef2019-02-28 15:56:23 -08006343 return null;
6344 }
6345
yinxu504e1392017-04-12 16:03:22 -07006346 /**
6347 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006348 *
6349 * @param subId id of the subscription
6350 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006351 */
6352 @Override
6353 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6355 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356
Hall Liu912dfd32019-04-25 14:02:26 -07006357 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 final long identity = Binder.clearCallingIdentity();
6359 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006360 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
yinxu504e1392017-04-12 16:03:22 -07006364 }
6365
6366 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006367 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006368 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006369 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006370 */
6371 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006372 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006373 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006374 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006375 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376
6377 final long identity = Binder.clearCallingIdentity();
6378 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006379 if (DBG) log("getAllowedNetworkTypesBitmask");
6380 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6381 int networkTypesBitmask = (result != null ? result[0] : -1);
6382 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6383 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384 } finally {
6385 Binder.restoreCallingIdentity(identity);
6386 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006387 }
6388
6389 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006390 * Get the allowed network types for certain reason.
6391 *
6392 * @param subId the id of the subscription.
6393 * @param reason the reason the allowed network type change is taking place
6394 * @return the allowed network types.
6395 */
6396 @Override
6397 public long getAllowedNetworkTypesForReason(int subId,
6398 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006399 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006400 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006401 final long identity = Binder.clearCallingIdentity();
6402 try {
6403 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6404 } finally {
6405 Binder.restoreCallingIdentity(identity);
6406 }
6407 }
6408
6409 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006410 * Enable/Disable E-UTRA-NR Dual Connectivity
6411 * @param subId subscription id of the sim card
6412 * @param nrDualConnectivityState expected NR dual connectivity state
6413 * This can be passed following states
6414 * <ol>
6415 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6416 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6417 * <li>Disable NR dual connectivity and force secondary cell to be released
6418 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6419 * </ol>
6420 * @return operation result.
6421 */
6422 @Override
6423 public int setNrDualConnectivityState(int subId,
6424 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6426 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006427 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006428 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6429 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6430 }
6431
Sooraj Sasindran37444802020-08-11 10:40:43 -07006432 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6433 final long identity = Binder.clearCallingIdentity();
6434 try {
6435 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6436 nrDualConnectivityState, subId,
6437 workSource);
6438 if (DBG) log("enableNRDualConnectivity result: " + result);
6439 return result;
6440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
6443 }
6444
6445 /**
6446 * Is E-UTRA-NR Dual Connectivity enabled
6447 * @return true if dual connectivity is enabled else false
6448 */
6449 @Override
6450 public boolean isNrDualConnectivityEnabled(int subId) {
6451 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006452 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006453 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006454 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006455 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6456 return false;
6457 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006458 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6459 final long identity = Binder.clearCallingIdentity();
6460 try {
6461 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6462 null, subId, workSource);
6463 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6464 return isEnabled;
6465 } finally {
6466 Binder.restoreCallingIdentity(identity);
6467 }
6468 }
6469
6470 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006471 * Set the allowed network types of the device and
6472 * provide the reason triggering the allowed network change.
6473 *
6474 * @param subId the id of the subscription.
6475 * @param reason the reason the allowed network type change is taking place
6476 * @param allowedNetworkTypes the allowed network types.
6477 * @return true on success; false on any failure.
6478 */
6479 @Override
6480 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006481 @TelephonyManager.AllowedNetworkTypesReason int reason,
6482 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6484 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006485 // If the caller only has carrier privileges, then they should not be able to override
6486 // any network types which were set for security reasons.
6487 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6488 != PERMISSION_GRANTED
6489 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6490 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6491 throw new SecurityException(
6492 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6493 + " reason "
6494 + reason);
6495 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006496 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006497 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6498 return false;
6499 }
6500 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6501 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006502 return false;
6503 }
6504
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006505 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6506 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6507
6508
6509 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6510 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6511 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006512 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006513
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006514 final long identity = Binder.clearCallingIdentity();
6515 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006516 Boolean success = (Boolean) sendRequest(
6517 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6518 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6519
6520 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6521 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006522 } finally {
6523 Binder.restoreCallingIdentity(identity);
6524 }
6525 }
6526
6527 /**
Miaoa84611c2019-03-15 09:21:10 +08006528 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006529 *
Miaoa84611c2019-03-15 09:21:10 +08006530 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006531 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006532 * @hide
6533 */
6534 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006535 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006536 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006537 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006538 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539 try {
Miaoa84611c2019-03-15 09:21:10 +08006540 if (phone != null) {
6541 return phone.hasMatchedTetherApnSetting();
6542 } else {
6543 return false;
6544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545 } finally {
6546 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006547 }
Junda Liu475951f2014-11-07 16:45:03 -08006548 }
6549
6550 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006551 * Get the user enabled state of Mobile Data.
6552 *
6553 * TODO: remove and use isUserDataEnabled.
6554 * This can't be removed now because some vendor codes
6555 * calls through ITelephony directly while they should
6556 * use TelephonyManager.
6557 *
6558 * @return true on enabled
6559 */
6560 @Override
6561 public boolean getDataEnabled(int subId) {
6562 return isUserDataEnabled(subId);
6563 }
6564
6565 /**
6566 * Get whether mobile data is enabled per user setting.
6567 *
6568 * There are other factors deciding whether mobile data is actually enabled, but they are
6569 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006570 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006571 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6572 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006573 *
6574 * @return {@code true} if data is enabled else {@code false}
6575 */
6576 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006577 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006578 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006579 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006580 try {
6581 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6582 functionName);
6583 } catch (Exception e) {
6584 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6585 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006586 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006588 mApp, subId, functionName);
6589
Robert Greenwalt646120a2014-05-23 11:54:03 -07006590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006591
6592 final long identity = Binder.clearCallingIdentity();
6593 try {
6594 int phoneId = mSubscriptionController.getPhoneId(subId);
6595 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6596 Phone phone = PhoneFactory.getPhone(phoneId);
6597 if (phone != null) {
6598 boolean retVal = phone.isUserDataEnabled();
6599 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6600 return retVal;
6601 } else {
6602 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6603 return false;
6604 }
6605 } finally {
6606 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006607 }
6608 }
6609
6610 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006611 * Checks if the device is capable of mobile data by considering whether whether the
6612 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6613 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006614 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006615 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006616 */
6617 @Override
6618 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006619 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006620 try {
6621 try {
6622 mApp.enforceCallingOrSelfPermission(
6623 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006624 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006625 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006626 try {
6627 mApp.enforceCallingOrSelfPermission(
6628 android.Manifest.permission.READ_PHONE_STATE,
6629 functionName);
6630 } catch (Exception e2) {
6631 mApp.enforceCallingOrSelfPermission(
6632 permission.READ_BASIC_PHONE_STATE, functionName);
6633 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006634 }
6635 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006636 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006638
6639 final long identity = Binder.clearCallingIdentity();
6640 try {
6641 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006642 Phone phone = PhoneFactory.getPhone(phoneId);
6643 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006644 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006645 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006646 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006647 return retVal;
6648 } else {
6649 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6650 return false;
6651 }
6652 } finally {
6653 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006654 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006655 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006656
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006657 /**
6658 * Check if data is enabled for a specific reason
6659 * @param subId Subscription index
6660 * @param reason the reason the data enable change is taking place
6661 * @return {@code true} if the overall data is enabled; {@code false} if not.
6662 */
6663 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006664 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006665 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006666 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006667 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006668 try {
6669 mApp.enforceCallingOrSelfPermission(
6670 android.Manifest.permission.ACCESS_NETWORK_STATE,
6671 functionName);
6672 } catch (Exception e) {
6673 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6674 functionName);
6675 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006676 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006677 try {
6678 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006679 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006680 } catch (Exception e2) {
6681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006682 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006683 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006684 }
6685
6686
6687 final long identity = Binder.clearCallingIdentity();
6688 try {
6689 int phoneId = mSubscriptionController.getPhoneId(subId);
6690 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006691 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006692 + " reason=" + reason);
6693 }
6694 Phone phone = PhoneFactory.getPhone(phoneId);
6695 if (phone != null) {
6696 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006697 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006698 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006699 return retVal;
6700 } else {
6701 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006702 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006703 + subId + " retVal=false");
6704 }
6705 return false;
6706 }
6707 } finally {
6708 Binder.restoreCallingIdentity(identity);
6709 }
6710 }
6711
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006712 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006713 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006714 // No permission needed; this only lets the caller inspect their own status.
6715 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006716 }
Junda Liu29340342014-07-10 15:23:27 -07006717
6718 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006719 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006720 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006721 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6722 }
6723
6724 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6725 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006726 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006727 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006728 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6729 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006730 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6731 if (cpt == null) {
6732 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006733 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6734 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006735 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006736 }
6737
6738 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006739 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006740 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006741 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006742 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006743 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006744 Phone phone = getPhone(subId);
6745 if (phone == null) {
6746 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6747 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6748 }
6749 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6750 if (cpt == null) {
6751 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6753 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006754 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006755 }
6756
6757 @Override
6758 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006759 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006760 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6761 }
6762
6763 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006764 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006765 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006766 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006767 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006768 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6769 Phone phone = PhoneFactory.getPhone(phoneId);
6770 if (phone == null) {
6771 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006772 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006773 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6774 if (cpt == null) {
6775 continue;
6776 }
6777 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006778 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6779 break;
6780 }
6781 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006782 return result;
Junda Liu29340342014-07-10 15:23:27 -07006783 }
Derek Tan89e89d42014-07-08 17:00:10 -07006784
6785 @Override
Junda Liue64de782015-04-16 17:19:16 -07006786 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006787 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006788 Phone phone = PhoneFactory.getPhone(phoneId);
6789 if (phone == null) {
6790 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006791 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006792 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6793 if (cpt == null) {
6794 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006795 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006796 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006797 }
6798
Amith Yamasani6e118872016-02-19 12:53:51 -08006799 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006800 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006801 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006802 Phone phone = PhoneFactory.getPhone(phoneId);
6803 if (phone == null) {
6804 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006805 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006806 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6807 if (cpt == null) {
6808 return Collections.emptyList();
6809 }
6810 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006811 }
6812
chen xuf7e9fe82019-05-09 19:31:02 -07006813 @Override
6814 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006815 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006816 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006817 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006818 try {
6819 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6820 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6821 }
6822 } finally {
6823 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006824 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006825 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006826 }
6827
Rambo Wang6812ffb2022-03-15 16:54:17 -07006828 @Override
6829 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6830 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6831
6832 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6833 if (phone == null) {
6834 return null;
6835 }
6836 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6837 if (cpt == null) {
6838 return null;
6839 }
6840 return cpt.getCarrierServicePackageName();
6841 }
6842
Wink Savilleb564aae2014-10-23 10:18:09 -07006843 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006844 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006845 UiccPort port = phone == null ? null : phone.getUiccPort();
6846 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006847 return null;
6848 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006849 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006850 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006851 return null;
6852 }
6853 return iccId;
6854 }
6855
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006856 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006857 public void setCallComposerStatus(int subId, int status) {
6858 enforceModifyPermission();
6859
6860 final long identity = Binder.clearCallingIdentity();
6861 try {
6862 Phone phone = getPhone(subId);
6863 if (phone != null) {
6864 Phone defaultPhone = phone.getImsPhone();
6865 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6866 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6867 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006868 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6869 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006870 }
6871 }
Shuo Qian284ae752020-12-22 19:10:14 -08006872 } catch (ImsException e) {
6873 throw new ServiceSpecificException(e.getCode());
6874 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006875 Binder.restoreCallingIdentity(identity);
6876 }
6877 }
6878
6879 @Override
6880 public int getCallComposerStatus(int subId) {
6881 enforceReadPrivilegedPermission("getCallComposerStatus");
6882
6883 final long identity = Binder.clearCallingIdentity();
6884 try {
6885 Phone phone = getPhone(subId);
6886 if (phone != null) {
6887 Phone defaultPhone = phone.getImsPhone();
6888 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6889 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6890 return imsPhone.getCallComposerStatus();
6891 }
6892 }
6893 } finally {
6894 Binder.restoreCallingIdentity(identity);
6895 }
6896 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6897 }
6898
6899 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006900 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6901 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006902 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006903 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006905 final long identity = Binder.clearCallingIdentity();
6906 try {
6907 final String iccId = getIccId(subId);
6908 final Phone phone = getPhone(subId);
6909 if (phone == null) {
6910 return false;
6911 }
6912 final String subscriberId = phone.getSubscriberId();
6913
6914 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006915 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916 + subscriberId + " to " + number);
6917 }
6918
6919 if (TextUtils.isEmpty(iccId)) {
6920 return false;
6921 }
6922
6923 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6924
6925 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6926 if (alphaTag == null) {
6927 editor.remove(alphaTagPrefKey);
6928 } else {
6929 editor.putString(alphaTagPrefKey, alphaTag);
6930 }
6931
6932 // Record both the line number and IMSI for this ICCID, since we need to
6933 // track all merged IMSIs based on line number
6934 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6935 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6936 if (number == null) {
6937 editor.remove(numberPrefKey);
6938 editor.remove(subscriberPrefKey);
6939 } else {
6940 editor.putString(numberPrefKey, number);
6941 editor.putString(subscriberPrefKey, subscriberId);
6942 }
6943
6944 editor.commit();
6945 return true;
6946 } finally {
6947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006948 }
Derek Tan7226c842014-07-02 17:42:23 -07006949 }
6950
6951 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006952 public String getLine1NumberForDisplay(int subId, String callingPackage,
6953 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006954 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006956 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006957 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006958 return null;
6959 }
Derek Tan97ebb422014-09-05 16:55:38 -07006960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006961 final long identity = Binder.clearCallingIdentity();
6962 try {
6963 String iccId = getIccId(subId);
6964 if (iccId != null) {
6965 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6966 if (DBG_MERGE) {
6967 log("getLine1NumberForDisplay returning "
6968 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6969 }
6970 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006971 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006972 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6973 return null;
6974 } finally {
6975 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006976 }
Derek Tan7226c842014-07-02 17:42:23 -07006977 }
6978
6979 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006980 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6981 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006983 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006984 return null;
6985 }
Derek Tan97ebb422014-09-05 16:55:38 -07006986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006987 final long identity = Binder.clearCallingIdentity();
6988 try {
6989 String iccId = getIccId(subId);
6990 if (iccId != null) {
6991 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6992 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6993 }
6994 return null;
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006997 }
Derek Tan7226c842014-07-02 17:42:23 -07006998 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006999
7000 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007001 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7002 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007003 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7004 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007005 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007006 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007007 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007008 return null;
7009 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007010
Jordan Liub49b04b2019-05-06 14:45:15 -07007011 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7012 // the process, where TelephonyManager was instantiated.
7013 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007014 final long identity = Binder.clearCallingIdentity();
7015 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007016 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007017 final TelephonyManager tele = TelephonyManager.from(context);
7018 final SubscriptionManager sub = SubscriptionManager.from(context);
7019
7020 // Figure out what subscribers are currently active
7021 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022
Jordan Liub49b04b2019-05-06 14:45:15 -07007023 // Only consider subs which match the current subId
7024 // This logic can be simplified. See b/131189269 for progress.
7025 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007026 activeSubscriberIds.add(tele.getSubscriberId(subId));
7027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007028
7029 // First pass, find a number override for an active subscriber
7030 String mergeNumber = null;
7031 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7032 for (String key : prefs.keySet()) {
7033 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7034 final String subscriberId = (String) prefs.get(key);
7035 if (activeSubscriberIds.contains(subscriberId)) {
7036 final String iccId = key.substring(
7037 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7038 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7039 mergeNumber = (String) prefs.get(numberKey);
7040 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007041 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042 + " for active subscriber " + subscriberId);
7043 }
7044 if (!TextUtils.isEmpty(mergeNumber)) {
7045 break;
7046 }
7047 }
7048 }
7049 }
7050
7051 // Shortcut when no active merged subscribers
7052 if (TextUtils.isEmpty(mergeNumber)) {
7053 return null;
7054 }
7055
7056 // Second pass, find all subscribers under that line override
7057 final ArraySet<String> result = new ArraySet<>();
7058 for (String key : prefs.keySet()) {
7059 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7060 final String number = (String) prefs.get(key);
7061 if (mergeNumber.equals(number)) {
7062 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7063 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7064 final String subscriberId = (String) prefs.get(subscriberKey);
7065 if (!TextUtils.isEmpty(subscriberId)) {
7066 result.add(subscriberId);
7067 }
7068 }
7069 }
7070 }
7071
7072 final String[] resultArray = result.toArray(new String[result.size()]);
7073 Arrays.sort(resultArray);
7074 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007075 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007076 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7077 }
7078 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007079 } finally {
7080 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007081 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007082 }
7083
7084 @Override
zoey chen38003472019-12-13 17:16:31 +08007085 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7086 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007087
7088 final long identity = Binder.clearCallingIdentity();
7089 try {
7090 final TelephonyManager telephonyManager = mApp.getSystemService(
7091 TelephonyManager.class);
7092 String subscriberId = telephonyManager.getSubscriberId(subId);
7093 if (subscriberId == null) {
7094 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007095 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007096 + subId);
7097 }
7098 return null;
7099 }
7100
7101 final SubscriptionInfo info = SubscriptionController.getInstance()
7102 .getSubscriptionInfo(subId);
7103 final ParcelUuid groupUuid = info.getGroupUuid();
7104 // If it doesn't belong to any group, return just subscriberId of itself.
7105 if (groupUuid == null) {
7106 return new String[]{subscriberId};
7107 }
7108
7109 // Get all subscriberIds from the group.
7110 final List<String> mergedSubscriberIds = new ArrayList<>();
7111 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007112 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007113 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007114 for (SubscriptionInfo subInfo : groupInfos) {
7115 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7116 if (subscriberId != null) {
7117 mergedSubscriberIds.add(subscriberId);
7118 }
7119 }
7120
7121 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7122 } finally {
7123 Binder.restoreCallingIdentity(identity);
7124
7125 }
7126 }
7127
7128 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007129 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007130 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007131 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007132
7133 final long identity = Binder.clearCallingIdentity();
7134 try {
7135 final Phone phone = getPhone(subId);
7136 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7137 } finally {
7138 Binder.restoreCallingIdentity(identity);
7139 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007140 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007141
7142 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007143 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007144 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7145 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007146 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7147 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007148
7149 final long identity = Binder.clearCallingIdentity();
7150 try {
7151 final Phone phone = getPhone(subId);
7152 if (phone == null) {
7153 return false;
7154 }
7155 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7156 cdmaNonRoamingList);
7157 } finally {
7158 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007159 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007160 }
7161
7162 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007163 @Deprecated
7164 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7165 enforceModifyPermission();
7166
7167 int returnValue = 0;
7168 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007169 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007170 if(result.exception == null) {
7171 if (result.result != null) {
7172 byte[] responseData = (byte[])(result.result);
7173 if(responseData.length > oemResp.length) {
7174 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7175 responseData.length + "bytes. Buffer Size is " +
7176 oemResp.length + "bytes.");
7177 }
7178 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7179 returnValue = responseData.length;
7180 }
7181 } else {
7182 CommandException ex = (CommandException) result.exception;
7183 returnValue = ex.getCommandError().ordinal();
7184 if(returnValue > 0) returnValue *= -1;
7185 }
7186 } catch (RuntimeException e) {
7187 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7188 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7189 if(returnValue > 0) returnValue *= -1;
7190 }
7191
7192 return returnValue;
7193 }
7194
7195 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007196 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007197 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007198 try {
7199 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007200 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007201 mApp, phone.getSubId(), "getRadioAccessFamily");
7202 } catch (SecurityException e) {
7203 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7204 throw e;
7205 }
chen xub97461a2018-10-26 14:17:57 -07007206 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007207 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007208 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210 final long identity = Binder.clearCallingIdentity();
7211 try {
chen xub97461a2018-10-26 14:17:57 -07007212 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007213 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007214 mApp, phone.getSubId(), "getRadioAccessFamily");
7215 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007216 } finally {
7217 Binder.restoreCallingIdentity(identity);
7218 }
chen xub97461a2018-10-26 14:17:57 -07007219 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007220 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007221
7222 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007223 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007224 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007225 try {
7226 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7227 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007228 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007229 }
7230 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007231 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007232 }
7233 RoleManager rm = mApp.getSystemService(RoleManager.class);
7234 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7235 if (!dialerRoleHolders.contains(callingPackage)) {
7236 throw new SecurityException("App must be the dialer role holder to"
7237 + " upload a call composer pic");
7238 }
7239
7240 Executors.newSingleThreadExecutor().execute(() -> {
7241 ByteArrayOutputStream output = new ByteArrayOutputStream(
7242 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7243 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7244 boolean readUntilEnd = false;
7245 int totalBytesRead = 0;
7246 byte[] buffer = new byte[16 * 1024];
7247 while (true) {
7248 int numRead;
7249 try {
7250 numRead = input.read(buffer);
7251 } catch (IOException e) {
7252 try {
7253 fd.checkError();
7254 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7255 null);
7256 } catch (IOException e1) {
7257 // This means that the other side closed explicitly with an error. If this
7258 // happens, log and ignore.
7259 loge("Remote end of call composer picture pipe closed: " + e1);
7260 }
7261 break;
7262 }
7263 if (numRead == -1) {
7264 readUntilEnd = true;
7265 break;
7266 }
7267 totalBytesRead += numRead;
7268 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7269 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7270 try {
7271 input.close();
7272 } catch (IOException e) {
7273 // ignore
7274 }
7275 break;
7276 }
7277 output.write(buffer, 0, numRead);
7278 }
7279 // Generally, the remote end will close the file descriptors. The only case where we
7280 // close is above, where the picture size is too big.
7281
7282 try {
7283 fd.checkError();
7284 } catch (IOException e) {
7285 loge("Remote end for call composer closed with an error: " + e);
7286 return;
7287 }
7288
Hall Liuaa4211e2021-01-20 15:43:39 -08007289 if (!readUntilEnd) {
7290 loge("Did not finish reading entire image; aborting");
7291 return;
7292 }
Hall Liu82694d52020-12-11 18:22:04 -08007293
Hall Liuaa4211e2021-01-20 15:43:39 -08007294 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7295 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7296 new CallComposerPictureTransfer.Factory() {},
7297 imageData,
7298 (result) -> {
7299 if (result.first != null) {
7300 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7301 Bundle outputResult = new Bundle();
7302 outputResult.putParcelable(
7303 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7304 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7305 outputResult);
7306 } else {
7307 callback.send(result.second, null);
7308 }
7309 }
7310 );
Hall Liu82694d52020-12-11 18:22:04 -08007311 });
7312 }
7313
7314 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007315 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007316 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007317 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007321 ImsManager.getInstance(defaultPhone.getContext(),
7322 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007323 } finally {
7324 Binder.restoreCallingIdentity(identity);
7325 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007326 }
7327
7328 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007329 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007330 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007331 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7332 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007333 return false;
7334 }
Svet Ganovb320e182015-04-16 12:30:10 -07007335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007336 final long identity = Binder.clearCallingIdentity();
7337 try {
7338 // Check the user preference and the system-level IMS setting. Even if the user has
7339 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7340 // In the long run, we may instead need to check if there exists a connection service
7341 // which can support video calling.
7342 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007343 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344 return imsManager.isVtEnabledByPlatform()
7345 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7346 && imsManager.isVtEnabledByUser();
7347 } finally {
7348 Binder.restoreCallingIdentity(identity);
7349 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007350 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007351
Andrew Leea1239f22015-03-02 17:44:07 -08007352 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007353 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7354 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007356 mApp, subId, callingPackage, callingFeatureId,
7357 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358 return false;
7359 }
7360
7361 final long identity = Binder.clearCallingIdentity();
7362 try {
7363 CarrierConfigManager configManager =
7364 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007365 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7367 } finally {
7368 Binder.restoreCallingIdentity(identity);
7369 }
Andrew Leea1239f22015-03-02 17:44:07 -08007370 }
7371
7372 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007373 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007375 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 return false;
7377 }
7378
7379 final long identity = Binder.clearCallingIdentity();
7380 try {
7381 CarrierConfigManager configManager =
7382 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007383 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7385 } finally {
7386 Binder.restoreCallingIdentity(identity);
7387 }
Andrew Leea1239f22015-03-02 17:44:07 -08007388 }
7389
Andrew Lee9431b832015-03-09 18:46:45 -07007390 @Override
7391 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007392 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007393 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007394 }
7395
7396 @Override
7397 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 final long identity = Binder.clearCallingIdentity();
7399 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007400 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007401 } finally {
7402 Binder.restoreCallingIdentity(identity);
7403 }
Andrew Lee9431b832015-03-09 18:46:45 -07007404 }
7405
Hall Liuf6668912018-10-31 17:05:23 -07007406 /**
7407 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7408 * support for the feature and device firmware support.
7409 *
7410 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7411 */
7412 @Override
7413 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007414 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007415 final Phone phone = getPhone(subscriptionId);
7416 if (phone == null) {
7417 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7418 return false;
7419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007421 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7423 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007424 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007425 return isCarrierSupported && isDeviceSupported;
7426 } finally {
7427 Binder.restoreCallingIdentity(identity);
7428 }
Hall Liu98187582018-01-22 19:15:32 -08007429 }
7430
Hall Liuf6668912018-10-31 17:05:23 -07007431 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007432 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7433 * RTT setting, will return true if the device and carrier both support RTT.
7434 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007435 */
7436 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 final long identity = Binder.clearCallingIdentity();
7438 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007439 boolean isRttSupported = isRttSupported(subscriptionId);
7440 boolean isUserRttSettingOn = Settings.Secure.getInt(
7441 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7442 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7443 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7444 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 } finally {
7446 Binder.restoreCallingIdentity(identity);
7447 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007448 }
7449
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007450 @Deprecated
7451 @Override
7452 public String getDeviceId(String callingPackage) {
7453 return getDeviceIdWithFeature(callingPackage, null);
7454 }
7455
Sanket Padawe7310cc72015-01-14 09:53:20 -08007456 /**
7457 * Returns the unique device ID of phone, for example, the IMEI for
7458 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7459 *
7460 * <p>Requires Permission:
7461 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7462 */
7463 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007464 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007465 try {
7466 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7467 } catch (SecurityException se) {
7468 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7469 throw new SecurityException("Package " + callingPackage + " does not belong to "
7470 + Binder.getCallingUid());
7471 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007472 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007473 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007474 return null;
7475 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007476 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007477 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007478 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007479 return null;
7480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481
7482 final long identity = Binder.clearCallingIdentity();
7483 try {
7484 return phone.getDeviceId();
7485 } finally {
7486 Binder.restoreCallingIdentity(identity);
7487 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007488 }
7489
Ping Sunc67b7c22016-03-02 19:16:45 +08007490 /**
7491 * {@hide}
7492 * Returns the IMS Registration Status on a particular subid
7493 *
7494 * @param subId
7495 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007496 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007497 Phone phone = getPhone(subId);
7498 if (phone != null) {
7499 return phone.isImsRegistered();
7500 } else {
7501 return false;
7502 }
7503 }
7504
Santos Cordon7a1885b2015-02-03 11:15:19 -08007505 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007506 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007507 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007509 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007510 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7511 }
7512 final long identity = Binder.clearCallingIdentity();
7513 try {
7514 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7515 } finally {
7516 Binder.restoreCallingIdentity(identity);
7517 }
7518 }
7519
7520 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007521 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007522 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007523 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007524 mApp,
7525 subscriptionId,
7526 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007527 final long identity = Binder.clearCallingIdentity();
7528 try {
7529 Phone phone = getPhone(subscriptionId);
7530 if (phone == null) {
7531 return null;
7532 }
7533 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7534 } finally {
7535 Binder.restoreCallingIdentity(identity);
7536 }
7537 }
7538
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007539 /**
7540 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007541 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007542 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 final long identity = Binder.clearCallingIdentity();
7544 try {
7545 Phone phone = getPhone(subId);
7546 if (phone != null) {
7547 return phone.isWifiCallingEnabled();
7548 } else {
7549 return false;
7550 }
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007553 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007554 }
7555
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007556 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007557 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007558 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007559 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 final long identity = Binder.clearCallingIdentity();
7561 try {
7562 Phone phone = getPhone(subId);
7563 if (phone != null) {
7564 return phone.isVideoEnabled();
7565 } else {
7566 return false;
7567 }
7568 } finally {
7569 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007570 }
7571 }
7572
7573 /**
7574 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7575 * defined in {@link ImsRegistrationImplBase}.
7576 */
7577 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007578 final long identity = Binder.clearCallingIdentity();
7579 try {
7580 Phone phone = getPhone(subId);
7581 if (phone != null) {
7582 return phone.getImsRegistrationTech();
7583 } else {
7584 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7585 }
7586 } finally {
7587 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007588 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007589 }
7590
Stuart Scott8eef64f2015-04-08 15:13:54 -07007591 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007592 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007593 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007594 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7595 return;
7596 }
Kai Shif70f46f2021-03-03 13:59:46 -08007597 Phone defaultPhone = getDefaultPhone();
7598 if (defaultPhone != null) {
7599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7600 mApp, getDefaultPhone().getSubId(), "factoryReset");
7601 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007602 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007603
Svet Ganovcc087f82015-05-12 20:35:54 -07007604 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007605 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7606 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007607 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007608 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007609 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007610 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007611 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007612 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007613 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007614 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007615 // There has been issues when Sms raw table somehow stores orphan
7616 // fragments. They lead to garbled message when new fragments come
7617 // in and combined with those stale ones. In case this happens again,
7618 // user can reset all network settings which will clean up this table.
7619 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007620 // Clean up IMS settings as well here.
7621 int slotId = getSlotIndex(subId);
7622 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7623 ImsManager.getInstance(mApp, slotId).factoryReset();
7624 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007625
Kai Shif70f46f2021-03-03 13:59:46 -08007626 if (defaultPhone == null) {
7627 return;
7628 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007629 // Erase modem config if erase modem on network setting is enabled.
7630 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7631 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7632 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007633 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007634 }
Kai Shif70f46f2021-03-03 13:59:46 -08007635
7636 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007637 } finally {
7638 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007639 }
7640 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007641
SongFerngWangfd89b102021-05-27 22:44:54 +08007642 @VisibleForTesting
7643 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7644 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7645 return;
7646 }
7647 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7648 RILConstants.PREFERRED_NETWORK_MODE);
7649 SubscriptionManager.setSubscriptionProperty(subId,
7650 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7651 "user=" + defaultNetworkType);
7652 phone.loadAllowedNetworksFromSubscriptionDatabase();
7653 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7654 defaultNetworkType, null);
7655 }
7656
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007657 private void cleanUpSmsRawTable(Context context) {
7658 ContentResolver resolver = context.getContentResolver();
7659 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7660 resolver.delete(uri, null, null);
7661 }
7662
Narayan Kamath1c496c22015-04-16 14:40:19 +01007663 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007664 public String getSimLocaleForSubscriber(int subId) {
7665 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7666 final Phone phone = getPhone(subId);
7667 if (phone == null) {
7668 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007669 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671 final long identity = Binder.clearCallingIdentity();
7672 try {
chen xu5d3637b2019-01-21 23:31:38 -08007673 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007674 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007675 if (info == null) {
7676 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7677 return null;
7678 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 // Try and fetch the locale from the carrier properties or from the SIM language
7680 // preferences (EF-PL and EF-LI)...
7681 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007682 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007683 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7684 if (localeFromDefaultSim != null) {
7685 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7686 if (DBG) log("Using locale from subId: " + subId + " locale: "
7687 + localeFromDefaultSim);
7688 return localeFromDefaultSim.toLanguageTag();
7689 } else {
7690 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 }
7692 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 // The SIM language preferences only store a language (e.g. fr = French), not an
7695 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7696 // the SIM and carrier preferences does not include a country we add the country
7697 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007698 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007700 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 return mccLocale.toLanguageTag();
7702 }
7703
7704 if (DBG) log("No locale found - returning null");
7705 return null;
7706 } finally {
7707 Binder.restoreCallingIdentity(identity);
7708 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007709 }
7710
7711 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007712 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007713 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007714 }
7715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716 /**
7717 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7718 */
7719 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007720 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007721 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007722 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007723
Gary Jian3aa9a762022-01-24 16:41:19 +08007724 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7725 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007726
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007727 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007728 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7729 * representing the state of the modem.
7730 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007731 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7732 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007733 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007734 */
7735 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007736 public void requestModemActivityInfo(ResultReceiver result) {
7737 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007738 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007739
7740 final long identity = Binder.clearCallingIdentity();
7741 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007742 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007743 } finally {
7744 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007745 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007746 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007747
Siddharth Rayb8114062018-06-17 15:02:38 -07007748 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7749 // less than total activity duration.
7750 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7751 if (info == null) {
7752 return false;
7753 }
7754 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007755 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7756 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7757
Siddharth Rayb8114062018-06-17 15:02:38 -07007758 return (info.isValid()
7759 && (info.getSleepTimeMillis() <= activityDurationMs)
7760 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007761 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007762 && (totalTxTimeMs <= activityDurationMs));
7763 }
7764
Gary Jian3aa9a762022-01-24 16:41:19 +08007765 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7766 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7767 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7768 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7769
7770 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7771 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7772 }
7773
7774 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7775 mLastModemActivityInfo.setReceiveTimeMillis(
7776 rat,
7777 freq,
7778 info.getReceiveTimeMillis(rat, freq)
7779 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7780 }
7781
7782 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7783 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7784 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7785 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7786
7787 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7788 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7789 }
7790 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7791 mLastModemActivityInfo.setReceiveTimeMillis(
7792 rat,
7793 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7794 }
7795
7796 /**
7797 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7798 * @param info recent ModemActivityInfo
7799 */
7800 private void mergeModemActivityInfo(ModemActivityInfo info) {
7801 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7802 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7803 boolean matched;
7804 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7805 matched = false;
7806 int rat = info.getSpecificInfoRat(i);
7807 int freq = info.getSpecificInfoFrequencyRange(i);
7808 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7809 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7810 //if it already exists
7811 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7812 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7813 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7814 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7815 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7816 updateLastModemActivityInfo(info, rat, freq);
7817 matched = true;
7818 }
7819 } else {
7820 updateLastModemActivityInfo(info, rat);
7821 matched = true;
7822 }
7823 }
7824 }
7825
7826 if (!matched) {
7827 mDeltaSpecificInfo =
7828 new ActivityStatsTechSpecificInfo(
7829 rat,
7830 freq,
7831 info.getTransmitTimeMillis(rat, freq),
7832 (int) info.getReceiveTimeMillis(rat, freq));
7833 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7834 }
7835 }
7836 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7837 mLastModemActivitySpecificInfo =
7838 new ActivityStatsTechSpecificInfo[merged.size()];
7839 merged.toArray(mLastModemActivitySpecificInfo);
7840
7841 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7842 mLastModemActivityInfo.setSleepTimeMillis(
7843 info.getSleepTimeMillis()
7844 + mLastModemActivityInfo.getSleepTimeMillis());
7845 mLastModemActivityInfo.setIdleTimeMillis(
7846 info.getIdleTimeMillis()
7847 + mLastModemActivityInfo.getIdleTimeMillis());
7848 }
7849
Jack Yu85bd38a2015-11-09 11:34:32 -08007850 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007851 * Returns the service state information on specified subscription.
7852 */
7853 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007854 public ServiceState getServiceStateForSubscriber(int subId,
7855 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7856 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007858 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007859 return null;
7860 }
7861
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007862 boolean hasFinePermission = false;
7863 boolean hasCoarsePermission = false;
7864 if (!renounceFineLocationAccess) {
7865 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7866 LocationAccessPolicy.checkLocationPermission(mApp,
7867 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7868 .setCallingPackage(callingPackage)
7869 .setCallingFeatureId(callingFeatureId)
7870 .setCallingPid(Binder.getCallingPid())
7871 .setCallingUid(Binder.getCallingUid())
7872 .setMethod("getServiceStateForSubscriber")
7873 .setLogAsInfo(true)
7874 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7875 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7876 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7877 .build());
7878 hasFinePermission =
7879 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7880 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007881
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007882 if (!renounceCoarseLocationAccess) {
7883 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7884 LocationAccessPolicy.checkLocationPermission(mApp,
7885 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7886 .setCallingPackage(callingPackage)
7887 .setCallingFeatureId(callingFeatureId)
7888 .setCallingPid(Binder.getCallingPid())
7889 .setCallingUid(Binder.getCallingUid())
7890 .setMethod("getServiceStateForSubscriber")
7891 .setLogAsInfo(true)
7892 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7893 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7894 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7895 .build());
7896 hasCoarsePermission =
7897 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7898 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007899
Jack Yu479f40e2020-10-27 21:29:25 -07007900 final Phone phone = getPhone(subId);
7901 if (phone == null) {
7902 return null;
7903 }
7904
Jordan Liu0f2bc442020-11-18 16:47:37 -08007905 final long identity = Binder.clearCallingIdentity();
7906
Jack Yu479f40e2020-10-27 21:29:25 -07007907 boolean isCallingPackageDataService = phone.getDataServicePackages()
7908 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007909 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007910 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7911 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7912 Rlog.d(LOG_TAG,
7913 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7914 return null;
7915 }
7916
Hall Liuf19c44f2018-11-27 14:38:17 -08007917 ServiceState ss = phone.getServiceState();
7918
7919 // Scrub out the location info in ServiceState depending on what level of access
7920 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007921 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007922 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7923 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007924 } finally {
7925 Binder.restoreCallingIdentity(identity);
7926 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007927 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007928
7929 /**
7930 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7931 *
7932 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7933 * voicemail ringtone.
7934 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7935 * PhoneAccount.
7936 */
7937 @Override
7938 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007939 final long identity = Binder.clearCallingIdentity();
7940 try {
7941 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7942 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007943 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007944 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007946 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7947 } finally {
7948 Binder.restoreCallingIdentity(identity);
7949 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007950 }
7951
7952 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007953 * Sets the per-account voicemail ringtone.
7954 *
7955 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7956 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7957 *
7958 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7959 * voicemail ringtone.
7960 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7961 * PhoneAccount.
7962 */
7963 @Override
7964 public void setVoicemailRingtoneUri(String callingPackage,
7965 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007966 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007967 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007968 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7969 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7971 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7972 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007973 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007974
7975 final long identity = Binder.clearCallingIdentity();
7976 try {
7977 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7978 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007979 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007980 }
7981 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7982 } finally {
7983 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007984 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007985 }
7986
7987 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007988 * Returns whether vibration is set for voicemail notification in Phone settings.
7989 *
7990 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7991 * voicemail vibration setting.
7992 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7993 */
7994 @Override
7995 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 final long identity = Binder.clearCallingIdentity();
7997 try {
7998 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7999 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008000 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008003 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8004 } finally {
8005 Binder.restoreCallingIdentity(identity);
8006 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008007 }
8008
Youhan Wange64578a2016-05-02 15:32:42 -07008009 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008010 * Sets the per-account voicemail vibration.
8011 *
8012 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8013 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8014 *
8015 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8016 * voicemail vibration setting.
8017 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8018 * specific PhoneAccount.
8019 */
8020 @Override
8021 public void setVoicemailVibrationEnabled(String callingPackage,
8022 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008023 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008024 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008025 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8026 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8028 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8029 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008030 }
8031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032 final long identity = Binder.clearCallingIdentity();
8033 try {
8034 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8035 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008036 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008037 }
8038 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8039 } finally {
8040 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008041 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008042 }
8043
8044 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008045 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8046 *
8047 * @throws SecurityException if the caller does not have the required permission
8048 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008049 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008050 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008051 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008052 }
8053
8054 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008055 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8056 * permission.
8057 *
8058 * @throws SecurityException if the caller does not have the required permission
8059 */
8060 private void enforceSendSmsPermission() {
8061 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8062 }
8063
8064 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008065 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008066 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008067 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008068 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008069 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 final long identity = Binder.clearCallingIdentity();
8071 try {
8072 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008073 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074 if (componentName == null) {
8075 throw new SecurityException(
8076 "Caller not current active visual voicemail package[null]");
8077 }
8078 String vvmPackage = componentName.getPackageName();
8079 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008080 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 }
8082 } finally {
8083 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008084 }
8085 }
8086
8087 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008088 * Return the application ID for the app type.
8089 *
8090 * @param subId the subscription ID that this request applies to.
8091 * @param appType the uicc app type.
8092 * @return Application ID for specificied app type, or null if no uicc.
8093 */
8094 @Override
8095 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008096 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008097 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098
8099 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008100 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008101 if (phone == null) {
8102 return null;
8103 }
8104 String aid = null;
8105 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008106 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008107 .getApplicationByType(appType).getAid();
8108 } catch (Exception e) {
8109 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8110 }
8111 return aid;
8112 } finally {
8113 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008114 }
Youhan Wange64578a2016-05-02 15:32:42 -07008115 }
8116
Youhan Wang4001d252016-05-11 10:29:41 -07008117 /**
8118 * Return the Electronic Serial Number.
8119 *
8120 * @param subId the subscription ID that this request applies to.
8121 * @return ESN or null if error.
8122 */
8123 @Override
8124 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008125 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008126 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127
8128 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008129 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008130 if (phone == null) {
8131 return null;
8132 }
8133 String esn = null;
8134 try {
8135 esn = phone.getEsn();
8136 } catch (Exception e) {
8137 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8138 }
8139 return esn;
8140 } finally {
8141 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008142 }
Youhan Wang4001d252016-05-11 10:29:41 -07008143 }
8144
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008145 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008146 * Return the Preferred Roaming List Version.
8147 *
8148 * @param subId the subscription ID that this request applies to.
8149 * @return PRLVersion or null if error.
8150 */
8151 @Override
8152 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008153 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008154 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155
8156 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008157 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158 if (phone == null) {
8159 return null;
8160 }
8161 String cdmaPrlVersion = null;
8162 try {
8163 cdmaPrlVersion = phone.getCdmaPrlVersion();
8164 } catch (Exception e) {
8165 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8166 }
8167 return cdmaPrlVersion;
8168 } finally {
8169 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008170 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008171 }
8172
8173 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008174 * Get snapshot of Telephony histograms
8175 * @return List of Telephony histograms
8176 * @hide
8177 */
8178 @Override
8179 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8181 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008182
8183 final long identity = Binder.clearCallingIdentity();
8184 try {
8185 return RIL.getTelephonyRILTimingHistograms();
8186 } finally {
8187 Binder.restoreCallingIdentity(identity);
8188 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008189 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008190
8191 /**
8192 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008193 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8194 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008195 * Require system privileges. In the future we may add this to carrier APIs.
8196 *
Michele Berionne482f8202018-11-27 18:57:59 -08008197 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008198 */
8199 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008200 @TelephonyManager.SetCarrierRestrictionResult
8201 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008202 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008203 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008204
Michele Berionne482f8202018-11-27 18:57:59 -08008205 if (carrierRestrictionRules == null) {
8206 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008207 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209 final long identity = Binder.clearCallingIdentity();
8210 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008211 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008212 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008213 } finally {
8214 Binder.restoreCallingIdentity(identity);
8215 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008216 }
8217
8218 /**
8219 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008220 * Get the allowed carrier list and the excluded carrier list, including the priority between
8221 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008222 * Require system privileges. In the future we may add this to carrier APIs.
8223 *
Michele Berionne482f8202018-11-27 18:57:59 -08008224 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008225 */
8226 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008227 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008228 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008229 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008230
8231 final long identity = Binder.clearCallingIdentity();
8232 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008233 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8234 if (response instanceof CarrierRestrictionRules) {
8235 return (CarrierRestrictionRules) response;
8236 }
8237 // Response is an Exception of some kind,
8238 // which is signalled to the user as a NULL retval
8239 return null;
8240 } catch (Exception e) {
8241 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8242 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008243 } finally {
8244 Binder.restoreCallingIdentity(identity);
8245 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008246 }
8247
fionaxu59545b42016-05-25 15:53:37 -07008248 /**
fionaxu59545b42016-05-25 15:53:37 -07008249 * Action set from carrier signalling broadcast receivers to enable/disable radio
8250 * @param subId the subscription ID that this action applies to.
8251 * @param enabled control enable or disable radio.
8252 * {@hide}
8253 */
8254 @Override
8255 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8256 enforceModifyPermission();
8257 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258
8259 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008260 if (phone == null) {
8261 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8262 return;
8263 }
8264 try {
8265 phone.carrierActionSetRadioEnabled(enabled);
8266 } catch (Exception e) {
8267 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008268 } finally {
8269 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008270 }
8271 }
8272
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008273 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008274 * Enable or disable Voice over NR (VoNR)
8275 * @param subId the subscription ID that this action applies to.
8276 * @param enabled enable or disable VoNR.
8277 * @return operation result.
8278 */
8279 @Override
8280 public int setVoNrEnabled(int subId, boolean enabled) {
8281 enforceModifyPermission();
8282 final Phone phone = getPhone(subId);
8283
8284 final long identity = Binder.clearCallingIdentity();
8285 if (phone == null) {
8286 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8287 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8288 }
8289
8290 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8291 try {
8292 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8293 workSource);
8294 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008295
8296 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8297 if (DBG) {
8298 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8299 }
8300 SubscriptionManager.setSubscriptionProperty(
8301 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8302 (enabled ? "1" : "0"));
8303 }
8304
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008305 return result;
8306 } finally {
8307 Binder.restoreCallingIdentity(identity);
8308 }
8309 }
8310
8311 /**
8312 * Is voice over NR enabled
8313 * @return true if VoNR is enabled else false
8314 */
8315 @Override
8316 public boolean isVoNrEnabled(int subId) {
8317 enforceReadPrivilegedPermission("isVoNrEnabled");
8318 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8319 final long identity = Binder.clearCallingIdentity();
8320 try {
8321 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8322 null, subId, workSource);
8323 if (DBG) log("isVoNrEnabled: " + isEnabled);
8324 return isEnabled;
8325 } finally {
8326 Binder.restoreCallingIdentity(identity);
8327 }
8328 }
8329
8330 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008331 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8332 * network status based on which carrier apps could apply actions accordingly,
8333 * enable/disable default url handler for example.
8334 *
8335 * @param subId the subscription ID that this action applies to.
8336 * @param report control start/stop reporting the default network status.
8337 * {@hide}
8338 */
8339 @Override
8340 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8341 enforceModifyPermission();
8342 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343
8344 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008345 if (phone == null) {
8346 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8347 return;
8348 }
8349 try {
8350 phone.carrierActionReportDefaultNetworkStatus(report);
8351 } catch (Exception e) {
8352 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008353 } finally {
8354 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008355 }
8356 }
8357
8358 /**
fionaxud9622282017-07-17 17:51:30 -07008359 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8360 * @param subId the subscription ID that this action applies to.
8361 * {@hide}
8362 */
8363 @Override
8364 public void carrierActionResetAll(int subId) {
8365 enforceModifyPermission();
8366 final Phone phone = getPhone(subId);
8367 if (phone == null) {
8368 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8369 return;
8370 }
8371 try {
8372 phone.carrierActionResetAll();
8373 } catch (Exception e) {
8374 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8375 }
8376 }
8377
8378 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008379 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8380 * bug report is being generated.
8381 */
8382 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008383 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008384 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8385 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008386 writer.println("Permission Denial: can't dump Phone from pid="
8387 + Binder.getCallingPid()
8388 + ", uid=" + Binder.getCallingUid()
8389 + "without permission "
8390 + android.Manifest.permission.DUMP);
8391 return;
8392 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008393 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008394 }
Jack Yueb89b242016-06-22 13:27:47 -07008395
Brad Ebingerdac2f002018-04-03 15:17:52 -07008396 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008397 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8398 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8399 @NonNull String[] args) {
8400 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8401 this, in.getFileDescriptor(), out.getFileDescriptor(),
8402 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008403 }
8404
Jack Yueb89b242016-06-22 13:27:47 -07008405 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008406 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008407 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008408 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008409 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008410 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008411 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008412 */
8413 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008414 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008415 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008416 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8417 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8418 try {
8419 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008420 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008421 } catch (SecurityException se) {
8422 enforceModifyPermission();
8423 }
8424 } else {
8425 enforceModifyPermission();
8426 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008427
8428 final long identity = Binder.clearCallingIdentity();
8429 try {
8430 Phone phone = getPhone(subId);
8431 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008432 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8433 phone.carrierActionSetMeteredApnsEnabled(enabled);
8434 } else {
Jack Yuabb10902022-07-31 00:43:21 -07008435 phone.getDataSettingsManager().setDataEnabled(
8436 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008437 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008438 }
8439 } finally {
8440 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008441 }
8442 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008443
8444 /**
8445 * Get Client request stats
8446 * @return List of Client Request Stats
8447 * @hide
8448 */
8449 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008450 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8451 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008452 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008453 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008454 return null;
8455 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008456 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 if (phone != null) {
8461 return phone.getClientRequestStats();
8462 }
8463
8464 return null;
8465 } finally {
8466 Binder.restoreCallingIdentity(identity);
8467 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008468 }
8469
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008470 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008471 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008472 if (uid == Process.ROOT_UID && packageName == null) {
8473 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8474 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8475 // exception. ROOT_UID seems not to have a valid package name returned by
8476 // PackageManager, so just fake it here to avoid issues when running telephony shell
8477 // commands that plumb through the RIL as root, like so:
8478 // $ adb root
8479 // $ adb shell cmd phone ...
8480 packageName = "root";
8481 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008482 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008483 }
Jack Yueb4124c2017-02-16 15:32:43 -08008484
8485 /**
Grace Chen70990072017-03-24 17:21:30 -07008486 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008487 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008488 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008489 * @param state State of SIM (power down, power up, pass through)
8490 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8491 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8492 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008493 *
8494 **/
8495 @Override
Grace Chen70990072017-03-24 17:21:30 -07008496 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008497 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008498 Phone phone = PhoneFactory.getPhone(slotIndex);
8499
vagdeviaf9a5b92018-08-15 16:01:53 -07008500 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008502 final long identity = Binder.clearCallingIdentity();
8503 try {
8504 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008505 phone.setSimPowerState(state, null, workSource);
8506 }
8507 } finally {
8508 Binder.restoreCallingIdentity(identity);
8509 }
8510 }
8511
8512 /**
8513 * Set SIM card power state.
8514 *
8515 * @param slotIndex SIM slot id.
8516 * @param state State of SIM (power down, power up, pass through)
8517 * @param callback callback to trigger after success or failure
8518 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8519 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8520 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8521 *
8522 **/
8523 @Override
8524 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8525 IIntegerConsumer callback) {
8526 enforceModifyPermission();
8527 Phone phone = PhoneFactory.getPhone(slotIndex);
8528
8529 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8530
8531 final long identity = Binder.clearCallingIdentity();
8532 try {
8533 if (phone != null) {
8534 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8535 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008536 }
8537 } finally {
8538 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008539 }
8540 }
Shuo Qiandd210312017-04-12 22:11:33 +00008541
Tyler Gunn65d45c22017-06-05 11:22:26 -07008542 private boolean isUssdApiAllowed(int subId) {
8543 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008544 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008545 if (configManager == null) {
8546 return false;
8547 }
8548 PersistableBundle pb = configManager.getConfigForSubId(subId);
8549 if (pb == null) {
8550 return false;
8551 }
8552 return pb.getBoolean(
8553 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8554 }
8555
Shuo Qiandd210312017-04-12 22:11:33 +00008556 /**
8557 * Check if phone is in emergency callback mode
8558 * @return true if phone is in emergency callback mode
8559 * @param subId sub id
8560 */
goneil9c5f4872017-12-05 14:07:56 -08008561 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008562 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008563 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008564 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008565
8566 final long identity = Binder.clearCallingIdentity();
8567 try {
8568 if (phone != null) {
8569 return phone.isInEcm();
8570 } else {
8571 return false;
8572 }
8573 } finally {
8574 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008575 }
8576 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008577
8578 /**
8579 * Get the current signal strength information for the given subscription.
8580 * Because this information is not updated when the device is in a low power state
8581 * it should not be relied-upon to be current.
8582 * @param subId Subscription index
8583 * @return the most recent cached signal strength info from the modem
8584 */
8585 @Override
8586 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008587 final long identity = Binder.clearCallingIdentity();
8588 try {
8589 Phone p = getPhone(subId);
8590 if (p == null) {
8591 return null;
8592 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008594 return p.getSignalStrength();
8595 } finally {
8596 Binder.restoreCallingIdentity(identity);
8597 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008598 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008599
Pengquan Meng77b7f132018-08-22 14:49:57 -07008600 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008601 * Get the current modem radio state for the given slot.
8602 * @param slotIndex slot index.
8603 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008604 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008605 * @return the current radio power state from the modem
8606 */
8607 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008608 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008609 Phone phone = PhoneFactory.getPhone(slotIndex);
8610 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8612 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008613 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8614 }
8615
8616 final long identity = Binder.clearCallingIdentity();
8617 try {
8618 return phone.getRadioPowerState();
8619 } finally {
8620 Binder.restoreCallingIdentity(identity);
8621 }
8622 }
8623 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8624 }
8625
8626 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008627 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8628 *
8629 * <p>Requires one of the following permissions:
8630 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008631 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008632 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8633 * privileges.
8634 *
8635 * @param subId subscription id
8636 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8637 * {@code false}.
8638 */
8639 @Override
8640 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008641 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008642 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008643 try {
8644 mApp.enforceCallingOrSelfPermission(
8645 android.Manifest.permission.ACCESS_NETWORK_STATE,
8646 functionName);
8647 } catch (Exception e) {
8648 mApp.enforceCallingOrSelfPermission(
8649 permission.READ_BASIC_PHONE_STATE, functionName);
8650 }
Shuo Qian093013d2020-08-13 15:42:55 -07008651 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008652 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008653 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008654 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008655
Pengquan Menga1bb6272018-09-06 09:59:22 -07008656 boolean isEnabled = false;
8657 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008658 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008659 Phone phone = getPhone(subId);
8660 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008661 } finally {
8662 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008663 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008664 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008665 }
8666
8667
8668 /**
8669 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8670 *
8671 * <p> Requires permission:
8672 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8673 * privileges.
8674 *
8675 * @param subId subscription id
8676 * @param isEnabled {@code true} means enable, {@code false} means disable.
8677 */
8678 @Override
8679 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8681 mApp, subId, "setDataRoamingEnabled");
8682
Pengquan Menga1bb6272018-09-06 09:59:22 -07008683 final long identity = Binder.clearCallingIdentity();
8684 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008685 Phone phone = getPhone(subId);
8686 if (phone != null) {
8687 phone.setDataRoamingEnabled(isEnabled);
8688 }
8689 } finally {
8690 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008691 }
8692 }
8693
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008694 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008695 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008696 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008697 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008698 mApp, subId, "isManualNetworkSelectionAllowed");
8699
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008700 boolean isAllowed = true;
8701 final long identity = Binder.clearCallingIdentity();
8702 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008703 Phone phone = getPhone(subId);
8704 if (phone != null) {
8705 isAllowed = phone.isCspPlmnEnabled();
8706 }
8707 } finally {
8708 Binder.restoreCallingIdentity(identity);
8709 }
8710 return isAllowed;
8711 }
8712
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008713 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8714 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008715 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008716 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008717 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008718 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8719 if (phone == null) {
8720 return false;
8721 }
8722 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8723 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8724 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008725 }
8726
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008727 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008728 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008729 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008730 mApp.getSystemService(AppOpsManager.class)
8731 .checkPackage(Binder.getCallingUid(), callingPackage);
8732
Jordan Liu1e142fc2019-04-22 15:10:43 -07008733 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008734 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008735 try {
8736 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008737 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008738 } catch (SecurityException e) {
8739 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8740 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008741 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008742 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008743 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008744 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008745 }
sandeepjsb6c87872021-09-27 15:34:44 +00008746 // checking compatibility, if calling app's target SDK is T and beyond.
8747 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8748 Binder.getCallingUid())) {
8749 isIccIdAccessRestricted = true;
8750 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008751 final long identity = Binder.clearCallingIdentity();
8752 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008753 UiccController uiccController = UiccController.getInstance();
8754 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008755 if (hasReadPermission) {
8756 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008757 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008758
8759 // Remove private info if the caller doesn't have access
8760 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8761 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008762 //setting the value after compatibility check
8763 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008764 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8765 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008766 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008767 if (card == null) {
8768 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008769 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008770 continue;
8771 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008772 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8773 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008774 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008775 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008776 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008777 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8778 for (UiccPortInfo portInfo : portInfos) {
8779 UiccPort port = uiccController.getUiccPortForSlot(
8780 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8781 if (port == null) {
8782 // assume no access if port is null
8783 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8784 continue;
8785 }
8786 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8787 uiccPortInfos.add(portInfo);
8788 } else {
8789 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8790 }
8791 }
8792 filteredInfos.add(new UiccCardInfo(
8793 cardInfo.isEuicc(),
8794 cardInfo.getCardId(),
8795 null,
8796 cardInfo.getPhysicalSlotIndex(),
8797 cardInfo.isRemovable(),
8798 cardInfo.isMultipleEnabledProfilesSupported(),
8799 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008800 }
8801 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008802 } finally {
8803 Binder.restoreCallingIdentity(identity);
8804 }
8805 }
8806
sandeepjsb6c87872021-09-27 15:34:44 +00008807 /**
8808 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8809 * generally private and require carrier privileges to view.
8810 *
8811 * @hide
8812 */
8813 @NonNull
8814 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8815 List<UiccPortInfo> portinfo = new ArrayList<>();
8816 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8817 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8818 }
8819 return new UiccCardInfo(
8820 cardInfo.isEuicc(),
8821 cardInfo.getCardId(),
8822 null,
8823 cardInfo.getPhysicalSlotIndex(),
8824 cardInfo.isRemovable(),
8825 cardInfo.isMultipleEnabledProfilesSupported(),
8826 portinfo
8827 );
8828 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008829
sandeepjsb6c87872021-09-27 15:34:44 +00008830 /**
8831 * @hide
8832 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8833 * These values are generally private and require carrier privileges to view.
8834 */
8835 @NonNull
8836 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8837 return new UiccPortInfo(
8838 UiccPortInfo.ICCID_REDACTED,
8839 portInfo.getPortIndex(),
8840 portInfo.getLogicalSlotIndex(),
8841 portInfo.isActive()
8842 );
8843 }
8844 @Override
8845 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008846 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008847 mApp.getSystemService(AppOpsManager.class)
8848 .checkPackage(Binder.getCallingUid(), callingPackage);
8849
sandeepjsb6c87872021-09-27 15:34:44 +00008850 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008851
Aman Guptaf3c90b32022-03-17 04:54:16 +00008852 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8853 // we are reading iccId which is PII data.
8854 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008855
8856 // checking compatibility, if calling app's target SDK is T and beyond.
8857 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8858 Binder.getCallingUid())) {
8859 isLogicalSlotAccessRestricted = true;
8860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008861 final long identity = Binder.clearCallingIdentity();
8862 try {
8863 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008864 if (slots == null || slots.length == 0) {
8865 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008866 return null;
8867 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008868 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8869 for (int i = 0; i < slots.length; i++) {
8870 UiccSlot slot = slots[i];
8871 if (slot == null) {
8872 continue;
8873 }
8874
Jordan Liu7be7e652019-05-06 18:55:02 +00008875 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008876 UiccCard card = slot.getUiccCard();
8877 if (card != null) {
8878 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008879 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008880 cardId = slot.getEid();
8881 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008882 // If cardId is null, use iccId of default port as cardId.
8883 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008885 }
8886
Jordan Liu857451f2019-05-09 16:35:35 -07008887 if (cardId != null) {
8888 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8889 // if cardId is an EID, it's all digits so this is fine
8890 cardId = IccUtils.stripTrailingFs(cardId);
8891 }
8892
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008893 int cardState = 0;
8894 switch (slot.getCardState()) {
8895 case CARDSTATE_ABSENT:
8896 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8897 break;
8898 case CARDSTATE_PRESENT:
8899 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8900 break;
8901 case CARDSTATE_ERROR:
8902 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8903 break;
8904 case CARDSTATE_RESTRICTED:
8905 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8906 break;
8907 default:
8908 break;
8909
8910 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008911 List<UiccPortInfo> portInfos = new ArrayList<>();
8912 int[] portIndexes = slot.getPortList();
8913 for (int portIdx : portIndexes) {
8914 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00008915 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008916 portInfos.add(new UiccPortInfo(iccId, portIdx,
8917 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008919 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008920 slot.isEuicc(),
8921 cardId,
8922 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008923 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008924 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008925 //setting the value after compatibility check
8926 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008927 }
8928 return infos;
8929 } finally {
8930 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008931 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008932 }
8933
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008934 /* Returns null if doesn't have read permission or carrier privilege access. */
8935 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8936 boolean hasReadPermission) {
8937 String iccId = slot.getIccId(portIndex);
8938 if (hasReadPermission) { // if has read permission
8939 return iccId;
8940 } else {
8941 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8942 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8943 // if no read permission, checking carrier privilege access
8944 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8945 return iccId;
8946 }
8947 }
8948 }
8949 // No read permission or carrier privilege access.
8950 return UiccPortInfo.ICCID_REDACTED;
8951 }
8952
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008953 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008954 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008955 public boolean switchSlots(int[] physicalSlots) {
8956 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008957
8958 final long identity = Binder.clearCallingIdentity();
8959 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008960 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8961 for (int i = 0; i < physicalSlots.length; i++) {
8962 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8963 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8964 physicalSlots[i], i));
8965 }
8966 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008967 } finally {
8968 Binder.restoreCallingIdentity(identity);
8969 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008970 }
Jack Yu4c988042018-02-27 15:30:01 -08008971
8972 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008973 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8974 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8975 enforceModifyPermission();
8976
8977 final long identity = Binder.clearCallingIdentity();
8978 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008979 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00008980 } finally {
8981 Binder.restoreCallingIdentity(identity);
8982 }
8983 }
8984
8985 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008986 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008987 final long identity = Binder.clearCallingIdentity();
8988 try {
8989 return UiccController.getInstance().getCardIdForDefaultEuicc();
8990 } finally {
8991 Binder.restoreCallingIdentity(identity);
8992 }
8993 }
8994
Pengquan Meng85728fb2018-03-12 16:31:21 -07008995 /**
goneil47ffb6e2018-04-06 15:40:58 -07008996 * A test API to reload the UICC profile.
8997 *
8998 * <p>Requires that the calling app has permission
8999 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9000 * @hide
9001 */
9002 @Override
9003 public void refreshUiccProfile(int subId) {
9004 enforceModifyPermission();
9005
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
9008 Phone phone = getPhone(subId);
9009 if (phone == null) {
9010 return;
9011 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009012 UiccPort uiccPort = phone.getUiccPort();
9013 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009014 return;
9015 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009016 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009017 if (uiccProfile == null) {
9018 return;
9019 }
9020 uiccProfile.refresh();
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
9024 }
9025
9026 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009027 * Returns false if the mobile data is disabled by default, otherwise return true.
9028 */
9029 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009030 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009031 }
9032
9033 /**
9034 * Returns true if the data roaming is enabled by default, i.e the system property
9035 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9036 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9037 */
9038 private boolean getDefaultDataRoamingEnabled(int subId) {
9039 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009040 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009041 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009042 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9043 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9044 return isDataRoamingEnabled;
9045 }
9046
9047 /**
9048 * Returns the default network type for the given {@code subId}, if the default network type is
9049 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9050 */
9051 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009052 List<Integer> list = TelephonyProperties.default_network();
9053 int phoneId = mSubscriptionController.getPhoneId(subId);
9054 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9055 return list.get(phoneId);
9056 }
9057 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009058 }
fionaxua13278b2018-03-21 00:08:13 -07009059
9060 @Override
9061 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009062 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009063 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009064
9065 final long identity = Binder.clearCallingIdentity();
9066 try {
9067 final Phone phone = getPhone(subId);
9068 if (phone == null) {
9069 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9070 return;
9071 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009072 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9073 if (cpt != null) {
9074 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9075 }
9076 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009077 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9078 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009079 if (carrierPrivilegeRules == null) {
9080 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9081 } else {
9082 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009084 } finally {
9085 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009086 }
fionaxua13278b2018-03-21 00:08:13 -07009087 }
9088
9089 @Override
9090 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009091 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009092
9093 final long identity = Binder.clearCallingIdentity();
9094 try {
9095 final Phone phone = getPhone(subId);
9096 if (phone == null) {
9097 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9098 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9099 }
9100 return phone.getCarrierIdListVersion();
9101 } finally {
9102 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009103 }
fionaxua13278b2018-03-21 00:08:13 -07009104 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009105
9106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009107 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9108 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009110 mApp, subId, callingPackage, callingFeatureId,
9111 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009112 return -1;
9113 }
9114
9115 final long identity = Binder.clearCallingIdentity();
9116 try {
9117 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9118 } finally {
9119 Binder.restoreCallingIdentity(identity);
9120 }
9121 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009122
9123 @Override
9124 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009125 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009126 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009127 mApp, subId, "getCdmaRoamingMode");
9128
9129 final long identity = Binder.clearCallingIdentity();
9130 try {
9131 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9132 } finally {
9133 Binder.restoreCallingIdentity(identity);
9134 }
9135 }
9136
9137 @Override
9138 public boolean setCdmaRoamingMode(int subId, int mode) {
9139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9140 mApp, subId, "setCdmaRoamingMode");
9141
9142 final long identity = Binder.clearCallingIdentity();
9143 try {
9144 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9145 } finally {
9146 Binder.restoreCallingIdentity(identity);
9147 }
9148 }
9149
9150 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009151 public int getCdmaSubscriptionMode(int subId) {
9152 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009153 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009154 mApp, subId, "getCdmaSubscriptionMode");
9155
9156 final long identity = Binder.clearCallingIdentity();
9157 try {
9158 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9159 } finally {
9160 Binder.restoreCallingIdentity(identity);
9161 }
9162 }
9163
9164 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009165 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9167 mApp, subId, "setCdmaSubscriptionMode");
9168
9169 final long identity = Binder.clearCallingIdentity();
9170 try {
9171 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9172 } finally {
9173 Binder.restoreCallingIdentity(identity);
9174 }
9175 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009176
sqianc5eccab2018-10-19 18:46:41 -07009177 @Override
sqian8c685422019-02-22 15:55:18 -08009178 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009179 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009181 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9182 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009183 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9184 }
9185 final long identity = Binder.clearCallingIdentity();
9186 try {
sqian854d44b2018-12-12 16:48:18 -08009187 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9188 for (Phone phone: PhoneFactory.getPhones()) {
9189 if (phone.getEmergencyNumberTracker() != null
9190 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9191 emergencyNumberListInternal.put(
9192 phone.getSubId(),
9193 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9194 }
sqian11b7a0e2018-12-05 18:48:28 -08009195 }
sqian854d44b2018-12-12 16:48:18 -08009196 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009197 } finally {
9198 Binder.restoreCallingIdentity(identity);
9199 }
sqianc5eccab2018-10-19 18:46:41 -07009200 }
9201
9202 @Override
sqian8c685422019-02-22 15:55:18 -08009203 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009204 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009205 if (!exactMatch) {
9206 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009207 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009208 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009209 }
9210 final long identity = Binder.clearCallingIdentity();
9211 try {
sqian854d44b2018-12-12 16:48:18 -08009212 for (Phone phone: PhoneFactory.getPhones()) {
9213 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009214 && phone.getEmergencyNumberTracker()
9215 .isEmergencyNumber(number, exactMatch)) {
9216 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009217 }
sqian11b7a0e2018-12-05 18:48:28 -08009218 }
9219 return false;
9220 } finally {
9221 Binder.restoreCallingIdentity(identity);
9222 }
9223 }
9224
sqianf4ca7ed2019-01-15 18:32:07 -08009225 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009226 * Start emergency callback mode for GsmCdmaPhone for testing.
9227 */
9228 @Override
9229 public void startEmergencyCallbackMode() {
9230 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9231 "startEmergencyCallbackMode");
9232 enforceModifyPermission();
9233 final long identity = Binder.clearCallingIdentity();
9234 try {
9235 for (Phone phone : PhoneFactory.getPhones()) {
9236 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9237 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9238 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9239 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9240 gsmCdmaPhone.obtainMessage(
9241 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9242 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9243 }
9244 }
9245 } finally {
9246 Binder.restoreCallingIdentity(identity);
9247 }
9248 }
9249
9250 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009251 * Update emergency number list for test mode.
9252 */
9253 @Override
9254 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9255 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9256 "updateEmergencyNumberListTestMode");
9257
9258 final long identity = Binder.clearCallingIdentity();
9259 try {
9260 for (Phone phone: PhoneFactory.getPhones()) {
9261 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9262 if (tracker != null) {
9263 tracker.executeEmergencyNumberTestModeCommand(action, num);
9264 }
9265 }
9266 } finally {
9267 Binder.restoreCallingIdentity(identity);
9268 }
9269 }
9270
9271 /**
9272 * Get the full emergency number list for test mode.
9273 */
9274 @Override
9275 public List<String> getEmergencyNumberListTestMode() {
9276 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9277 "getEmergencyNumberListTestMode");
9278
9279 final long identity = Binder.clearCallingIdentity();
9280 try {
9281 Set<String> emergencyNumbers = new HashSet<>();
9282 for (Phone phone: PhoneFactory.getPhones()) {
9283 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9284 if (tracker != null) {
9285 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9286 emergencyNumbers.add(num.getNumber());
9287 }
9288 }
9289 }
9290 return new ArrayList<>(emergencyNumbers);
9291 } finally {
9292 Binder.restoreCallingIdentity(identity);
9293 }
9294 }
9295
chen xud6b45bd2018-10-30 22:27:10 -07009296 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009297 public int getEmergencyNumberDbVersion(int subId) {
9298 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9299
9300 final long identity = Binder.clearCallingIdentity();
9301 try {
9302 final Phone phone = getPhone(subId);
9303 if (phone == null) {
9304 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9305 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9306 }
9307 return phone.getEmergencyNumberDbVersion();
9308 } finally {
9309 Binder.restoreCallingIdentity(identity);
9310 }
9311 }
9312
9313 @Override
9314 public void notifyOtaEmergencyNumberDbInstalled() {
9315 enforceModifyPermission();
9316
9317 final long identity = Binder.clearCallingIdentity();
9318 try {
9319 for (Phone phone: PhoneFactory.getPhones()) {
9320 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9321 if (tracker != null) {
9322 tracker.updateOtaEmergencyNumberDatabase();
9323 }
9324 }
9325 } finally {
9326 Binder.restoreCallingIdentity(identity);
9327 }
9328 }
9329
9330 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009331 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009332 enforceActiveEmergencySessionPermission();
9333
9334 final long identity = Binder.clearCallingIdentity();
9335 try {
9336 for (Phone phone: PhoneFactory.getPhones()) {
9337 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9338 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009339 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9340 }
9341 }
9342 } finally {
9343 Binder.restoreCallingIdentity(identity);
9344 }
9345 }
9346
9347 @Override
9348 public void resetOtaEmergencyNumberDbFilePath() {
9349 enforceActiveEmergencySessionPermission();
9350
9351 final long identity = Binder.clearCallingIdentity();
9352 try {
9353 for (Phone phone: PhoneFactory.getPhones()) {
9354 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9355 if (tracker != null) {
9356 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009357 }
9358 }
9359 } finally {
9360 Binder.restoreCallingIdentity(identity);
9361 }
9362 }
9363
9364 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009365 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9366 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9367 Phone phone = getPhone(subId);
9368 if (phone == null) {
9369 return null;
9370 }
9371 final long identity = Binder.clearCallingIdentity();
9372 try {
9373 UiccProfile profile = UiccController.getInstance()
9374 .getUiccProfileForPhone(phone.getPhoneId());
9375 if (profile != null) {
9376 return profile.getCertsFromCarrierPrivilegeAccessRules();
9377 }
9378 } finally {
9379 Binder.restoreCallingIdentity(identity);
9380 }
9381 return null;
9382 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009383
9384 /**
9385 * Enable or disable a modem stack.
9386 */
9387 @Override
9388 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9389 enforceModifyPermission();
9390
9391 final long identity = Binder.clearCallingIdentity();
9392 try {
9393 Phone phone = PhoneFactory.getPhone(slotIndex);
9394 if (phone == null) {
9395 return false;
9396 } else {
9397 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9398 }
9399 } finally {
9400 Binder.restoreCallingIdentity(identity);
9401 }
9402 }
Michelecea4cf22018-12-21 15:00:11 -08009403
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009404 /**
9405 * Whether a modem stack is enabled or not.
9406 */
9407 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009408 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9409 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009410 Phone phone = PhoneFactory.getPhone(slotIndex);
9411 if (phone == null) return false;
9412
9413 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009414 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9415 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009416 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9417 }
9418
9419 final long identity = Binder.clearCallingIdentity();
9420 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009421 try {
9422 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9423 } catch (NoSuchElementException ex) {
9424 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9425 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009426 } finally {
9427 Binder.restoreCallingIdentity(identity);
9428 }
9429 }
9430
Michelecea4cf22018-12-21 15:00:11 -08009431 @Override
Michele0ea7d782019-03-19 14:58:42 -07009432 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009433 enforceModifyPermission();
9434
9435 final long identity = Binder.clearCallingIdentity();
9436 try {
9437 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009438 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009439 .commit();
9440 } finally {
9441 Binder.restoreCallingIdentity(identity);
9442 }
9443 }
9444
9445 @Override
Michele0ea7d782019-03-19 14:58:42 -07009446 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009447 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009448 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009449 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9450 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009451 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009452 }
Michelecea4cf22018-12-21 15:00:11 -08009453
9454 final long identity = Binder.clearCallingIdentity();
9455 try {
Michele0ea7d782019-03-19 14:58:42 -07009456 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009457 } finally {
9458 Binder.restoreCallingIdentity(identity);
9459 }
9460 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009461
Michele0ea7d782019-03-19 14:58:42 -07009462 @TelephonyManager.IsMultiSimSupportedResult
9463 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009464 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9465 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9466 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009467 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9468 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009469 }
9470 // Check if the hardware supports multisim functionality. If usage of multisim is not
9471 // supported by the modem, indicate that it is restricted.
9472 PhoneCapability staticCapability =
9473 mPhoneConfigurationManager.getStaticPhoneCapability();
9474 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009475 loge("isMultiSimSupportedInternal: no static configuration available");
9476 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009477 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009478 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009479 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9480 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009481 }
9482 // Check if support of multiple SIMs is restricted by carrier
9483 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009484 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009485 }
9486
Michele0ea7d782019-03-19 14:58:42 -07009487 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009488 }
9489
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009490 /**
9491 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009492 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9493 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9494 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009495 * @param numOfSims number of active sims we want to switch to
9496 */
9497 @Override
9498 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009499 if (numOfSims == 1) {
9500 enforceModifyPermission();
9501 } else {
9502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9503 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9504 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009505 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009506
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009507 try {
Michele30b57b22019-03-01 12:01:14 -08009508 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009509 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009510 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9511 return;
9512 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009513 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9514 } finally {
9515 Binder.restoreCallingIdentity(identity);
9516 }
9517 }
9518
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009519 @Override
9520 public boolean isApplicationOnUicc(int subId, int appType) {
9521 enforceReadPrivilegedPermission("isApplicationOnUicc");
9522 Phone phone = getPhone(subId);
9523 if (phone == null) {
9524 return false;
9525 }
9526 final long identity = Binder.clearCallingIdentity();
9527 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009528 UiccPort uiccPort = phone.getUiccPort();
9529 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009530 return false;
9531 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009532 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009533 if (uiccProfile == null) {
9534 return false;
9535 }
9536 if (TelephonyManager.APPTYPE_SIM <= appType
9537 && appType <= TelephonyManager.APPTYPE_ISIM) {
9538 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9539 }
9540 return false;
9541 } finally {
9542 Binder.restoreCallingIdentity(identity);
9543 }
9544 }
9545
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009546 /**
chen xub4baa772019-04-03 10:23:41 -07009547 * Get whether making changes to modem configurations will trigger reboot.
9548 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009549 */
9550 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009551 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9552 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009553 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009554 mApp, subId, callingPackage, callingFeatureId,
9555 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009556 return false;
9557 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009558 final long identity = Binder.clearCallingIdentity();
9559 try {
9560 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9561 } finally {
9562 Binder.restoreCallingIdentity(identity);
9563 }
9564 }
9565
Nathan Harold29f5f052019-02-15 13:41:57 -08009566 private void updateModemStateMetrics() {
9567 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9568 // TODO: check the state for each modem if the api is ready.
9569 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9570 }
9571
Pengquan Meng3889a572019-01-23 11:16:29 -08009572 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009573 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009574 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009575 // Verify that the callingPackage belongs to the calling UID
9576 mApp.getSystemService(AppOpsManager.class)
9577 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009578 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009579 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009580 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009581 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9582 if (slotInfos != null) {
9583 for (int i = 0; i < slotInfos.length; i++) {
9584 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9585 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9586 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9587 portInfo.getLogicalSlotIndex()));
9588 }
9589 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009590 }
9591 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009592 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009593 } finally {
9594 Binder.restoreCallingIdentity(identity);
9595 }
9596 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009597
9598 /**
9599 * Get the IRadio HAL Version
9600 */
9601 @Override
9602 public int getRadioHalVersion() {
9603 Phone phone = getDefaultPhone();
9604 if (phone == null) return -1;
9605 HalVersion hv = phone.getHalVersion();
9606 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9607 return hv.major * 100 + hv.minor;
9608 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009609
9610 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009611 * Get the current calling package name.
9612 * @return the current calling package name
9613 */
9614 @Override
9615 public String getCurrentPackageName() {
9616 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9617 }
9618
9619 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009620 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9621 * corresponding network requests on a subId.
9622 *
9623 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009624 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009625 * 2) APN is un-metered for this subscription, or
9626 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009627 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009628 *
9629 * @return whether data is allowed for a apn type.
9630 *
9631 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009632 */
9633 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009634 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009635 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9636 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009637
9638 // Now that all security checks passes, perform the operation as ourselves.
9639 final long identity = Binder.clearCallingIdentity();
9640 try {
9641 Phone phone = getPhone(subId);
9642 if (phone == null) return false;
9643
Jack Yu27422a52022-03-21 10:38:05 -07009644 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009645 boolean isDataEnabled;
Jack Yuabb10902022-07-31 00:43:21 -07009646 isMetered = phone.getDataNetworkController().getDataConfigManager()
9647 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9648 phone.getServiceState().getDataRoaming());
9649 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009650 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009651 } finally {
9652 Binder.restoreCallingIdentity(identity);
9653 }
9654 }
9655
9656 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009657 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009658 enforceReadPrivilegedPermission("isApnMetered");
9659
9660 // Now that all security checks passes, perform the operation as ourselves.
9661 final long identity = Binder.clearCallingIdentity();
9662 try {
9663 Phone phone = getPhone(subId);
9664 if (phone == null) return true; // By default return true.
Jack Yuabb10902022-07-31 00:43:21 -07009665 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9666 DataUtils.apnTypeToNetworkCapability(apnType),
9667 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009668 } finally {
9669 Binder.restoreCallingIdentity(identity);
9670 }
9671 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009672
9673 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009674 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9675 int subscriptionId, IBooleanConsumer resultCallback) {
9676 enforceModifyPermission();
9677 long token = Binder.clearCallingIdentity();
9678 try {
9679 Phone phone = getPhone(subscriptionId);
9680 if (phone == null) {
9681 try {
9682 if (resultCallback != null) {
9683 resultCallback.accept(false);
9684 }
9685 } catch (RemoteException e) {
9686 // ignore
9687 }
9688 return;
9689 }
9690 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9691 Pair.create(specifiers, (x) -> {
9692 try {
9693 if (resultCallback != null) {
9694 resultCallback.accept(x);
9695 }
9696 } catch (RemoteException e) {
9697 // ignore
9698 }
9699 });
9700 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9701 } finally {
9702 Binder.restoreCallingIdentity(token);
9703 }
9704 }
9705
9706 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009707 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9708 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009709 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009710 mApp, subId, "getSystemSelectionChannels");
9711 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9712 final long identity = Binder.clearCallingIdentity();
9713 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009714 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9715 if (result instanceof IllegalStateException) {
9716 throw (IllegalStateException) result;
9717 }
9718 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009719 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9720 return specifiers;
9721 } finally {
9722 Binder.restoreCallingIdentity(identity);
9723 }
9724 }
9725
9726 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009727 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009728 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009729 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009730 }
9731
9732 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009733 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9734 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009735 if (callingPackage == null) {
9736 callingPackage = getCurrentPackageName();
9737 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009738 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9739 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009740 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9741 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009742 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9743 }
9744 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9745 Intent intent = new Intent();
9746 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9747 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9748 // Bring up choose default SMS subscription dialog right now
9749 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9750 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9751 mApp.startActivity(intent);
9752 }
chen xud5ca2d52019-05-28 15:20:57 -07009753
9754 @Override
9755 public String getMmsUAProfUrl(int subId) {
9756 //TODO investigate if this API should require proper permission check in R b/133791609
9757 final long identity = Binder.clearCallingIdentity();
9758 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009759 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9760 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9761 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9762 return carrierUAProfUrl;
9763 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009764 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9765 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009766 } finally {
9767 Binder.restoreCallingIdentity(identity);
9768 }
9769 }
9770
9771 @Override
9772 public String getMmsUserAgent(int subId) {
9773 //TODO investigate if this API should require proper permission check in R b/133791609
9774 final long identity = Binder.clearCallingIdentity();
9775 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009776 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9777 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9778 if (!TextUtils.isEmpty(carrierUserAgent)) {
9779 return carrierUserAgent;
9780 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009781 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9782 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009783 } finally {
9784 Binder.restoreCallingIdentity(identity);
9785 }
9786 }
Jack Yub07d4972019-05-28 16:12:25 -07009787
9788 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009789 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9790 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009791
Jack Yub07d4972019-05-28 16:12:25 -07009792 final long identity = Binder.clearCallingIdentity();
9793 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009794 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009795 if (phone == null) return false;
9796
Ling Ma58448e42022-09-16 15:22:36 -07009797 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009798 } finally {
9799 Binder.restoreCallingIdentity(identity);
9800 }
9801 }
9802
9803 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009804 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009805 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009806 enforceModifyPermission();
9807
changbettyd5c246e2019-12-24 15:40:37 +08009808 final long identity = Binder.clearCallingIdentity();
9809 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009810 Phone phone = getPhone(subscriptionId);
9811 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009812
Ling Ma58448e42022-09-16 15:22:36 -07009813 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +08009814 } finally {
9815 Binder.restoreCallingIdentity(identity);
9816 }
9817 }
9818
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009819 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009820 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009821 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9822 * otherwise.
9823 */
9824 @Override
9825 public void setCepEnabled(boolean isCepEnabled) {
9826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9827
9828 final long identity = Binder.clearCallingIdentity();
9829 try {
9830 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9831 for (Phone phone : PhoneFactory.getPhones()) {
9832 Phone defaultPhone = phone.getImsPhone();
9833 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9834 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9835 ImsPhoneCallTracker imsPhoneCallTracker =
9836 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9837 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9838 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9839 + imsPhone.getMsisdn());
9840 }
9841 }
9842 } finally {
9843 Binder.restoreCallingIdentity(identity);
9844 }
9845 }
allenwtsu46dcc572020-01-08 18:24:03 +08009846
9847 /**
9848 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9849 *
9850 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9851 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9852 * before being read.
9853 */
9854 @Override
9855 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9856 isCompressed) {
9857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9858 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009859 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9860 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9861 }
9862 if (!isImsAvailableOnDevice()) {
9863 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9864 "IMS not available on device.");
9865 }
9866
9867 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009868 try {
Hui Wang761a6682020-10-31 05:12:53 +00009869 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9870 } finally {
9871 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009872 }
9873 }
zoey chene02881a2019-12-30 16:11:23 +08009874
9875 @Override
9876 public boolean isIccLockEnabled(int subId) {
9877 enforceReadPrivilegedPermission("isIccLockEnabled");
9878
9879 // Now that all security checks passes, perform the operation as ourselves.
9880 final long identity = Binder.clearCallingIdentity();
9881 try {
9882 Phone phone = getPhone(subId);
9883 if (phone != null && phone.getIccCard() != null) {
9884 return phone.getIccCard().getIccLockEnabled();
9885 } else {
9886 return false;
9887 }
9888 } finally {
9889 Binder.restoreCallingIdentity(identity);
9890 }
9891 }
9892
9893 /**
9894 * Set the ICC pin lock enabled or disabled.
9895 *
9896 * @return an integer representing the status of IccLock enabled or disabled in the following
9897 * three cases:
9898 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9899 * successfully.
9900 * - Positive number and zero for remaining password attempts.
9901 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9902 *
9903 */
9904 @Override
9905 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9906 enforceModifyPermission();
9907
9908 Phone phone = getPhone(subId);
9909 if (phone == null) {
9910 return 0;
9911 }
9912 // Now that all security checks passes, perform the operation as ourselves.
9913 final long identity = Binder.clearCallingIdentity();
9914 try {
9915 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9916 new Pair<Boolean, String>(enabled, password), phone, null);
9917 return attemptsRemaining;
9918
9919 } catch (Exception e) {
9920 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9921 } finally {
9922 Binder.restoreCallingIdentity(identity);
9923 }
9924 return 0;
9925 }
9926
9927 /**
9928 * Change the ICC password used in ICC pin lock.
9929 *
9930 * @return an integer representing the status of IccLock changed in the following three cases:
9931 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9932 * - Positive number and zero for remaining password attempts.
9933 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9934 *
9935 */
9936 @Override
9937 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9938 enforceModifyPermission();
9939
9940 Phone phone = getPhone(subId);
9941 if (phone == null) {
9942 return 0;
9943 }
9944 // Now that all security checks passes, perform the operation as ourselves.
9945 final long identity = Binder.clearCallingIdentity();
9946 try {
9947 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9948 new Pair<String, String>(oldPassword, newPassword), phone, null);
9949 return attemptsRemaining;
9950
9951 } catch (Exception e) {
9952 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9953 } finally {
9954 Binder.restoreCallingIdentity(identity);
9955 }
9956 return 0;
9957 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009958
9959 /**
9960 * Request for receiving user activity notification
9961 */
9962 @Override
9963 public void requestUserActivityNotification() {
9964 if (!mNotifyUserActivity.get()
9965 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9966 mNotifyUserActivity.set(true);
9967 }
9968 }
9969
9970 /**
9971 * Called when userActivity is signalled in the power manager.
9972 * This is safe to call from any thread, with any window manager locks held or not.
9973 */
9974 @Override
9975 public void userActivity() {
9976 // ***************************************
9977 // * Inherited from PhoneWindowManager *
9978 // ***************************************
9979 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9980 // WITH ITS LOCKS HELD.
9981 //
9982 // This code must be VERY careful about the locks
9983 // it acquires.
9984 // In fact, the current code acquires way too many,
9985 // and probably has lurking deadlocks.
9986
9987 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9988 throw new SecurityException("Only the OS may call notifyUserActivity()");
9989 }
9990
9991 if (mNotifyUserActivity.getAndSet(false)) {
9992 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9993 USER_ACTIVITY_NOTIFICATION_DELAY);
9994 }
9995 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009996
9997 @Override
9998 public boolean canConnectTo5GInDsdsMode() {
9999 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10000 }
Jack Yud10cdd42020-09-28 20:28:01 -070010001
10002 @Override
10003 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10004 String callingFeatureId) {
10005 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10006 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10007 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10008 }
10009
10010 Phone phone = getPhone(subId);
10011 if (phone == null) {
10012 throw new RuntimeException("phone is not available");
10013 }
10014 // Now that all security checks passes, perform the operation as ourselves.
10015 final long identity = Binder.clearCallingIdentity();
10016 try {
10017 return phone.getEquivalentHomePlmns();
10018 } finally {
10019 Binder.restoreCallingIdentity(identity);
10020 }
10021 }
Daniel Bright59e67312020-11-13 11:49:37 -080010022
10023 @Override
10024 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010025 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10026 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010027 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010028 if (radioInterfaceCapabilities == null) {
10029 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010030 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010031 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010032 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010033
Hui Wang641e81c2020-10-12 12:14:23 -070010034 @Override
10035 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10036 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010037 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10038 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10039 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10040 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10041 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010042 if (DBG) {
10043 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10044 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10045 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10046 }
10047
10048 if (!SubscriptionManager.isValidSubscriptionId(subId)
10049 || appType < TelephonyManager.APPTYPE_UNKNOWN
10050 || appType > TelephonyManager.APPTYPE_ISIM
10051 || nafUrl == null || securityProtocol == null || callback == null) {
10052 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10053 if (callback != null) {
10054 try {
10055 callback.onAuthenticationFailure(
10056 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10057 } catch (RemoteException exception) {
10058 log("Fail to notify onAuthenticationFailure due to " + exception);
10059 }
10060 return;
10061 }
10062 }
10063
10064 final long token = Binder.clearCallingIdentity();
10065 try {
10066 getGbaManager(subId).bootstrapAuthenticationRequest(
10067 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10068 forceBootStrapping, callback));
10069 } finally {
10070 Binder.restoreCallingIdentity(token);
10071 }
10072 }
10073
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010074 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010075 * Attempts to set the radio power state for all phones for thermal reason.
10076 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010077 * requested radio power state will actually be set. See {@link
10078 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10079 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010080 * @param enable {@code true} if trying to turn radio on.
10081 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10082 * false}.
10083 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010084 private boolean setRadioPowerForThermal(boolean enable) {
10085 boolean isPhoneAvailable = false;
10086 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10087 Phone phone = PhoneFactory.getPhone(i);
10088 if (phone != null) {
10089 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10090 isPhoneAvailable = true;
10091 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010092 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010093
10094 // return true if successfully informed the phone object about the thermal radio power
10095 // request.
10096 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010097 }
10098
10099 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010100 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010101 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10102 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10103 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10104 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10105 throw new IllegalArgumentException("modem does not support data throttling");
10106 }
10107
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010108 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10109 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010110 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010111 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10112 }
10113
Sarah Chinecc78c42022-03-31 21:16:48 -070010114 setDataEnabledForReason(
10115 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010116
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010117 if (isDataThrottlingSupported) {
10118 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010119 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010120 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10121 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10122 } else if (thermalMitigationResult
10123 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010124 log("Modem likely does not support data throttling on secondary carrier. Data " +
10125 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10126 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010127 }
10128 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010129 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010130
10131 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010132 }
10133
Jack Nudelman644b91a2021-03-12 14:09:48 -080010134 private static List<String> getThermalMitigationAllowlist(Context context) {
10135 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10136 for (String pckg : context.getResources()
10137 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10138 sThermalMitigationAllowlistedPackages.add(pckg);
10139 }
10140 }
10141
10142 return sThermalMitigationAllowlistedPackages;
10143 }
10144
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010145 private boolean isAnyPhoneInEmergencyState() {
10146 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10147 if (tm.isInEmergencyCall()) {
10148 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10149 return true;
10150 }
10151 for (Phone phone : PhoneFactory.getPhones()) {
10152 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10153 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10154 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10155 + phone.isInEcm());
10156 return true;
10157 }
10158 }
10159
10160 return false;
10161 }
10162
Jack Nudelman644b91a2021-03-12 14:09:48 -080010163 /**
10164 * Used by shell commands to add an authorized package name for thermal mitigation.
10165 * @param packageName name of package to be allowlisted
10166 * @param context
10167 */
10168 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10169 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10170 sThermalMitigationAllowlistedPackages.add(packageName);
10171 }
10172
10173 /**
10174 * Used by shell commands to remove an authorized package name for thermal mitigation.
10175 * @param packageName name of package to remove from allowlist
10176 * @param context
10177 */
10178 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10179 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10180 sThermalMitigationAllowlistedPackages.remove(packageName);
10181 }
10182
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010183 /**
10184 * Thermal mitigation request to control functionalities at modem.
10185 *
10186 * @param subId the id of the subscription.
10187 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010188 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010189 *
10190 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10191 */
10192 @Override
10193 @ThermalMitigationResult
10194 public int sendThermalMitigationRequest(
10195 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010196 ThermalMitigationRequest thermalMitigationRequest,
10197 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010198 enforceModifyPermission();
10199
Jack Nudelman644b91a2021-03-12 14:09:48 -080010200 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10201 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10202 .contains(callingPackage)) {
10203 throw new SecurityException("Calling package must be configured in the device config. "
10204 + "calling package: " + callingPackage);
10205 }
10206
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010207 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10208 final long identity = Binder.clearCallingIdentity();
10209
10210 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10211 try {
10212 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10213 switch (thermalMitigationAction) {
10214 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10215 thermalMitigationResult =
10216 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010217 thermalMitigationRequest.getDataThrottlingRequest(),
10218 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010219 break;
10220 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10221 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10222 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10223 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10224 }
10225
10226 // Ensure that radio is on. If not able to power on due to phone being
10227 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010228 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010229 thermalMitigationResult =
10230 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10231 break;
10232 }
10233
10234 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010235 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010236 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10237 break;
10238 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10239 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10240 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10241 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10242 }
10243
10244 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10245 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010246 Phone phone = getPhone(subId);
10247 if (phone == null) {
10248 thermalMitigationResult =
10249 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10250 break;
10251 }
10252
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010253 TelephonyConnectionService service =
10254 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010255 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010256 Log.e(LOG_TAG, "An emergency call is pending");
10257 thermalMitigationResult =
10258 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10259 break;
10260 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010261 thermalMitigationResult =
10262 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10263 break;
10264 }
10265 } else {
10266 thermalMitigationResult =
10267 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10268 break;
10269 }
10270
10271 // Turn radio off. If not able to power off due to phone being unavailable,
10272 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010273 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010274 thermalMitigationResult =
10275 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10276 break;
10277 }
10278 thermalMitigationResult =
10279 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10280 break;
10281 default:
10282 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10283 + "not exist. Requested action: " + thermalMitigationAction);
10284 }
10285 } catch (IllegalArgumentException e) {
10286 throw e;
10287 } catch (Exception e) {
10288 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10289 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10290 } finally {
10291 Binder.restoreCallingIdentity(identity);
10292 }
10293
10294 if (DBG) {
10295 log("thermalMitigationRequest returning with thermalMitigationResult: "
10296 + thermalMitigationResult);
10297 }
10298
10299 return thermalMitigationResult;
10300 }
Hui Wang641e81c2020-10-12 12:14:23 -070010301
10302 /**
10303 * Set the GbaService Package Name that Telephony will bind to.
10304 *
10305 * @param subId The sim that the GbaService is associated with.
10306 * @param packageName The name of the package to be replaced with.
10307 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10308 */
10309 @Override
10310 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10311 enforceModifyPermission();
10312
10313 final long identity = Binder.clearCallingIdentity();
10314 try {
10315 return getGbaManager(subId).overrideServicePackage(packageName);
10316 } finally {
10317 Binder.restoreCallingIdentity(identity);
10318 }
10319 }
10320
10321 /**
10322 * Return the package name of the currently bound GbaService.
10323 *
10324 * @param subId The sim that the GbaService is associated with.
10325 * @return the package name of the GbaService configuration, null if GBA is not supported.
10326 */
10327 @Override
10328 public String getBoundGbaService(int subId) {
10329 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10330
10331 final long identity = Binder.clearCallingIdentity();
10332 try {
10333 return getGbaManager(subId).getServicePackage();
10334 } finally {
10335 Binder.restoreCallingIdentity(identity);
10336 }
10337 }
10338
10339 /**
10340 * Set the release time for telephony to unbind GbaService.
10341 *
10342 * @param subId The sim that the GbaService is associated with.
10343 * @param interval The release time to unbind GbaService by millisecond.
10344 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10345 */
10346 @Override
10347 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10348 enforceModifyPermission();
10349
10350 final long identity = Binder.clearCallingIdentity();
10351 try {
10352 return getGbaManager(subId).overrideReleaseTime(interval);
10353 } finally {
10354 Binder.restoreCallingIdentity(identity);
10355 }
10356 }
10357
10358 /**
10359 * Return the release time for telephony to unbind GbaService.
10360 *
10361 * @param subId The sim that the GbaService is associated with.
10362 * @return The release time to unbind GbaService by millisecond.
10363 */
10364 @Override
10365 public int getGbaReleaseTime(int subId) {
10366 enforceReadPrivilegedPermission("getGbaReleaseTime");
10367
10368 final long identity = Binder.clearCallingIdentity();
10369 try {
10370 return getGbaManager(subId).getReleaseTime();
10371 } finally {
10372 Binder.restoreCallingIdentity(identity);
10373 }
10374 }
10375
10376 private GbaManager getGbaManager(int subId) {
10377 GbaManager instance = GbaManager.getInstance(subId);
10378 if (instance == null) {
10379 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10380 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10381 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10382 }
10383 return instance;
10384 }
Hui Wang761a6682020-10-31 05:12:53 +000010385
10386 /**
10387 * indicate whether the device and the carrier can support
10388 * RCS VoLTE single registration.
10389 */
10390 @Override
10391 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010392 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10393 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10394 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10395 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010396
10397 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10398 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10399 }
10400
10401 final long identity = Binder.clearCallingIdentity();
10402 try {
10403 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10404 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010405 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10406 if (isCapable != null) {
10407 return isCapable;
10408 }
Hui Wang761a6682020-10-31 05:12:53 +000010409 }
Hui Wang67af90e2021-06-04 16:57:15 -070010410 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10411 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010412 } finally {
10413 Binder.restoreCallingIdentity(identity);
10414 }
10415 }
10416
10417 /**
10418 * Register RCS provisioning callback.
10419 */
10420 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010421 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010422 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010423 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010424 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010425 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10426 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010427
10428 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10429 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10430 }
10431 if (!isImsAvailableOnDevice()) {
10432 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10433 "IMS not available on device.");
10434 }
10435
10436 final long identity = Binder.clearCallingIdentity();
10437 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010438 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010439 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010440 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10441 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010442 }
Hui Wang761a6682020-10-31 05:12:53 +000010443 } finally {
10444 Binder.restoreCallingIdentity(identity);
10445 }
10446 }
10447
10448 /**
10449 * Unregister RCS provisioning callback.
10450 */
10451 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010452 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010453 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010454 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010455 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010456 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10457 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010458
10459 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10460 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10461 }
10462 if (!isImsAvailableOnDevice()) {
10463 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10464 "IMS not available on device.");
10465 }
10466
10467 final long identity = Binder.clearCallingIdentity();
10468 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010469 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010470 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010471 } finally {
10472 Binder.restoreCallingIdentity(identity);
10473 }
10474 }
10475
10476 /**
10477 * trigger RCS reconfiguration.
10478 */
10479 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010480 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10481 "triggerRcsReconfiguration",
10482 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010483
10484 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10485 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10486 }
10487 if (!isImsAvailableOnDevice()) {
10488 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10489 "IMS not available on device.");
10490 }
10491
10492 final long identity = Binder.clearCallingIdentity();
10493 try {
10494 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10495 } finally {
10496 Binder.restoreCallingIdentity(identity);
10497 }
10498 }
10499
10500 /**
10501 * Provide the client configuration parameters of the RCS application.
10502 */
10503 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010504 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10505 "setRcsClientConfiguration",
10506 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010507
10508 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10509 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10510 }
10511 if (!isImsAvailableOnDevice()) {
10512 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10513 "IMS not available on device.");
10514 }
10515
10516 final long identity = Binder.clearCallingIdentity();
10517
10518 try {
10519 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10520 if (configBinder == null) {
10521 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010522 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10523 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010524 } else {
10525 configBinder.setRcsClientConfiguration(rcc);
10526 }
joonhunshin3e154242021-09-17 06:33:39 +000010527
10528 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10529 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010530 } catch (RemoteException e) {
10531 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010532 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10533 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010534 } finally {
10535 Binder.restoreCallingIdentity(identity);
10536 }
10537 }
10538
10539 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010540 * Enables or disables the test mode for RCS VoLTE single registration.
10541 */
10542 @Override
10543 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10544 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10545 "setRcsSingleRegistrationTestModeEnabled");
10546
10547 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10548 }
10549
10550 /**
10551 * Gets the test mode for RCS VoLTE single registration.
10552 */
10553 @Override
10554 public boolean getRcsSingleRegistrationTestModeEnabled() {
10555 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10556 "getRcsSingleRegistrationTestModeEnabled");
10557
10558 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10559 }
10560
10561 /**
Hui Wang761a6682020-10-31 05:12:53 +000010562 * Overrides the config of RCS VoLTE single registration enabled for the device.
10563 */
10564 @Override
10565 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10566 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10567 "setDeviceSingleRegistrationEnabledOverride");
10568 enforceModifyPermission();
10569
10570 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10571 : Boolean.parseBoolean(enabledStr);
10572 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010573 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010574 }
10575
10576 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010577 * Sends a device to device communication message. Only usable via shell.
10578 * @param message message to send.
10579 * @param value message value.
10580 */
10581 @Override
10582 public void sendDeviceToDeviceMessage(int message, int value) {
10583 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010584 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010585 enforceModifyPermission();
10586
10587 final long identity = Binder.clearCallingIdentity();
10588 try {
10589 TelephonyConnectionService service =
10590 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10591 if (service == null) {
10592 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10593 return;
10594 }
10595 service.sendTestDeviceToDeviceMessage(message, value);
10596 } finally {
10597 Binder.restoreCallingIdentity(identity);
10598 }
10599 }
10600
Tyler Gunnbabbda02021-02-10 11:05:02 -080010601 /**
10602 * Sets the specified device to device transport active.
10603 * @param transport The transport to set active.
10604 */
10605 @Override
10606 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10607 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10608 "setActiveDeviceToDeviceTransport");
10609 enforceModifyPermission();
10610
10611 final long identity = Binder.clearCallingIdentity();
10612 try {
10613 TelephonyConnectionService service =
10614 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10615 if (service == null) {
10616 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10617 return;
10618 }
10619 service.setActiveDeviceToDeviceTransport(transport);
10620 } finally {
10621 Binder.restoreCallingIdentity(identity);
10622 }
10623 }
Tyler Gunn92479152021-01-20 16:30:10 -080010624
Tyler Gunnd4339262021-05-03 14:46:49 -070010625 @Override
10626 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10627 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10628 "setDeviceToDeviceForceEnabled");
10629
10630 final long identity = Binder.clearCallingIdentity();
10631 try {
10632 Arrays.stream(PhoneFactory.getPhones()).forEach(
10633 p -> {
10634 Phone thePhone = p.getImsPhone();
10635 if (thePhone != null && thePhone instanceof ImsPhone) {
10636 ImsPhone imsPhone = (ImsPhone) thePhone;
10637 CallTracker tracker = imsPhone.getCallTracker();
10638 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10639 ImsPhoneCallTracker imsPhoneCallTracker =
10640 (ImsPhoneCallTracker) tracker;
10641 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10642 }
10643 }
10644 }
10645 );
10646 } finally {
10647 Binder.restoreCallingIdentity(identity);
10648 }
10649 }
10650
Tyler Gunn92479152021-01-20 16:30:10 -080010651 /**
Hui Wang761a6682020-10-31 05:12:53 +000010652 * Gets the config of RCS VoLTE single registration enabled for the device.
10653 */
10654 @Override
10655 public boolean getDeviceSingleRegistrationEnabled() {
10656 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10657 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10658 }
10659
10660 /**
10661 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10662 */
10663 @Override
10664 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10665 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10666 "setCarrierSingleRegistrationEnabledOverride");
10667 enforceModifyPermission();
10668
10669 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10670 : Boolean.parseBoolean(enabledStr);
10671 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10672 subId, enabled);
10673 }
10674
10675 /**
10676 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10677 */
10678 @Override
10679 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10680 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10681 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10682 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010683
10684 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010685 * Overrides the ims feature validation result
10686 */
10687 @Override
10688 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10689 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10690 "setImsFeatureValidationOverride");
10691
10692 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10693 : Boolean.parseBoolean(enabledStr);
10694 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10695 subId, enabled);
10696 }
10697
10698 /**
10699 * Gets the ims feature validation override value
10700 */
10701 @Override
10702 public boolean getImsFeatureValidationOverride(int subId) {
10703 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10704 "getImsFeatureValidationOverride");
10705 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10706 }
10707
10708 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010709 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10710 * their mobile plan.
10711 */
10712 @Override
10713 public String getMobileProvisioningUrl() {
10714 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10715 final long identity = Binder.clearCallingIdentity();
10716 try {
10717 return getDefaultPhone().getMobileProvisioningUrl();
10718 } finally {
10719 Binder.restoreCallingIdentity(identity);
10720 }
10721 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010722
James.cf Linbcdf8b32021-01-14 16:44:13 +080010723 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010724 * Get the EAB contact from the EAB database.
10725 */
10726 @Override
10727 public String getContactFromEab(String contact) {
10728 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10729 enforceModifyPermission();
10730 final long identity = Binder.clearCallingIdentity();
10731 try {
10732 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10733 } finally {
10734 Binder.restoreCallingIdentity(identity);
10735 }
10736 }
10737
10738 /**
Calvin Pana1434322021-07-01 19:27:01 +080010739 * Get the EAB capability from the EAB database.
10740 */
10741 @Override
10742 public String getCapabilityFromEab(String contact) {
10743 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10744 enforceModifyPermission();
10745 final long identity = Binder.clearCallingIdentity();
10746 try {
10747 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10748 } finally {
10749 Binder.restoreCallingIdentity(identity);
10750 }
10751 }
10752
10753 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010754 * Remove the EAB contacts from the EAB database.
10755 */
10756 @Override
10757 public int removeContactFromEab(int subId, String contacts) {
10758 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10759 enforceModifyPermission();
10760 final long identity = Binder.clearCallingIdentity();
10761 try {
10762 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10763 } finally {
10764 Binder.restoreCallingIdentity(identity);
10765 }
10766 }
10767
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010768 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010769 public boolean getDeviceUceEnabled() {
10770 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10771 final long identity = Binder.clearCallingIdentity();
10772 try {
10773 return mApp.getDeviceUceEnabled();
10774 } finally {
10775 Binder.restoreCallingIdentity(identity);
10776 }
10777 }
10778
10779 @Override
10780 public void setDeviceUceEnabled(boolean isEnabled) {
10781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10782 final long identity = Binder.clearCallingIdentity();
10783 try {
10784 mApp.setDeviceUceEnabled(isEnabled);
10785 } finally {
10786 Binder.restoreCallingIdentity(identity);
10787 }
10788 }
10789
Brad Ebinger14d467f2021-02-12 06:18:28 +000010790 /**
10791 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10792 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10793 */
10794 // Used for SHELL command only right now.
10795 @Override
10796 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10797 List<String> featureTags) {
10798 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10799 "addUceRegistrationOverrideShell");
10800 final long identity = Binder.clearCallingIdentity();
10801 try {
10802 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10803 new ArraySet<>(featureTags));
10804 } catch (ImsException e) {
10805 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10806 } finally {
10807 Binder.restoreCallingIdentity(identity);
10808 }
10809 }
10810
10811 /**
10812 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10813 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10814 */
10815 // Used for SHELL command only right now.
10816 @Override
10817 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10818 List<String> featureTags) {
10819 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10820 "removeUceRegistrationOverrideShell");
10821 final long identity = Binder.clearCallingIdentity();
10822 try {
10823 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10824 new ArraySet<>(featureTags));
10825 } catch (ImsException e) {
10826 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10827 } finally {
10828 Binder.restoreCallingIdentity(identity);
10829 }
10830 }
10831
10832 /**
10833 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10834 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10835 */
10836 // Used for SHELL command only right now.
10837 @Override
10838 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10839 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10840 "clearUceRegistrationOverrideShell");
10841 final long identity = Binder.clearCallingIdentity();
10842 try {
10843 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10844 } catch (ImsException e) {
10845 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10846 } finally {
10847 Binder.restoreCallingIdentity(identity);
10848 }
10849 }
10850
10851 /**
10852 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10853 */
10854 // Used for SHELL command only right now.
10855 @Override
10856 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10857 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10858 "getLatestRcsContactUceCapabilityShell");
10859 final long identity = Binder.clearCallingIdentity();
10860 try {
10861 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10862 } catch (ImsException e) {
10863 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10864 } finally {
10865 Binder.restoreCallingIdentity(identity);
10866 }
10867 }
10868
10869 /**
10870 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10871 * device does not have an active PUBLISH.
10872 */
10873 // Used for SHELL command only right now.
10874 @Override
10875 public String getLastUcePidfXmlShell(int subId) {
10876 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10877 final long identity = Binder.clearCallingIdentity();
10878 try {
10879 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10880 } catch (ImsException e) {
10881 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10882 } finally {
10883 Binder.restoreCallingIdentity(identity);
10884 }
10885 }
10886
James.cf Line8713a42021-04-29 16:04:26 +080010887 /**
10888 * Remove UCE requests cannot be sent to the network status.
10889 */
10890 // Used for SHELL command only right now.
10891 @Override
10892 public boolean removeUceRequestDisallowedStatus(int subId) {
10893 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10894 final long identity = Binder.clearCallingIdentity();
10895 try {
10896 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10897 } catch (ImsException e) {
10898 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10899 } finally {
10900 Binder.restoreCallingIdentity(identity);
10901 }
10902 }
10903
James.cf Lin18bb9002021-05-25 01:37:38 +080010904 /**
10905 * Remove UCE requests cannot be sent to the network status.
10906 */
10907 // Used for SHELL command only.
10908 @Override
10909 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10910 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10911 final long identity = Binder.clearCallingIdentity();
10912 try {
10913 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10914 } catch (ImsException e) {
10915 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10916 } finally {
10917 Binder.restoreCallingIdentity(identity);
10918 }
10919 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010920
James.cf Lin4b784aa2021-01-31 03:25:15 +080010921 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010922 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10923 String callingPackage) {
10924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10925 mApp, subId, "setSignalStrengthUpdateRequest");
10926
10927 final int callingUid = Binder.getCallingUid();
10928 // Verify that tha callingPackage belongs to the calling UID
10929 mApp.getSystemService(AppOpsManager.class)
10930 .checkPackage(callingUid, callingPackage);
10931
Rambo Wang3607f502021-02-01 21:51:40 -080010932 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010933
10934 final long identity = Binder.clearCallingIdentity();
10935 try {
10936 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10937 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10938
10939 if (result instanceof IllegalStateException) {
10940 throw (IllegalStateException) result;
10941 }
10942 } finally {
10943 Binder.restoreCallingIdentity(identity);
10944 }
10945 }
10946
10947 @Override
10948 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10949 String callingPackage) {
10950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10951 mApp, subId, "clearSignalStrengthUpdateRequest");
10952
10953 final int callingUid = Binder.getCallingUid();
10954 // Verify that tha callingPackage belongs to the calling UID
10955 mApp.getSystemService(AppOpsManager.class)
10956 .checkPackage(callingUid, callingPackage);
10957
10958 final long identity = Binder.clearCallingIdentity();
10959 try {
10960 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10961 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10962
10963 if (result instanceof IllegalStateException) {
10964 throw (IllegalStateException) result;
10965 }
10966 } finally {
10967 Binder.restoreCallingIdentity(identity);
10968 }
10969 }
10970
Rambo Wang3607f502021-02-01 21:51:40 -080010971 private static void validateSignalStrengthUpdateRequest(Context context,
10972 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010973 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10974 // phone/system process do not have further restriction on request
10975 return;
10976 }
10977
10978 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010979 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010980 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010981 context.enforceCallingOrSelfPermission(
10982 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10983 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010984 }
10985
10986 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10987 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10988 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10989 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10990 || info.isEnabled()) {
10991 throw new IllegalArgumentException(
10992 "Only system can set hide fields in SignalThresholdInfo");
10993 }
10994
10995 // Thresholds length for each RAN need in range. This has been validated in
10996 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10997 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10998 final int[] thresholds = info.getThresholds();
10999 Objects.requireNonNull(thresholds);
11000 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11001 || thresholds.length
11002 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11003 throw new IllegalArgumentException(
11004 "thresholds length is out of range: " + thresholds.length);
11005 }
11006 }
11007 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011008
11009 /**
11010 * Gets the current phone capability.
11011 *
11012 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11013 * @return the PhoneCapability which describes the data connection capability of modem.
11014 * It's used to evaluate possible phone config change, for example from single
11015 * SIM device to multi-SIM device.
11016 */
11017 @Override
11018 public PhoneCapability getPhoneCapability() {
11019 enforceReadPrivilegedPermission("getPhoneCapability");
11020 final long identity = Binder.clearCallingIdentity();
11021 try {
11022 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11023 } finally {
11024 Binder.restoreCallingIdentity(identity);
11025 }
11026 }
Michele Berionne5e411512020-11-13 02:36:59 +000011027
11028 /**
11029 * Prepare TelephonyManager for an unattended reboot. The reboot is
11030 * required to be done shortly after the API is invoked.
11031 */
11032 @Override
11033 @TelephonyManager.PrepareUnattendedRebootResult
11034 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011035 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011036 enforceRebootPermission();
11037
11038 final long identity = Binder.clearCallingIdentity();
11039 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011040 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011041 } finally {
11042 Binder.restoreCallingIdentity(identity);
11043 }
11044 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011045
11046 /**
11047 * Request to get the current slicing configuration including URSP rules and
11048 * NSSAIs (configured, allowed and rejected).
11049 *
11050 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11051 */
11052 @Override
11053 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011054 TelephonyPermissions
11055 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11056 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011057
11058 final long identity = Binder.clearCallingIdentity();
11059 try {
11060 Phone phone = getDefaultPhone();
11061 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11062 } finally {
11063 Binder.restoreCallingIdentity(identity);
11064 }
11065 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011066
11067 /**
11068 * Register an IMS connection state callback
11069 */
11070 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011071 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11072 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011073 if (feature == ImsFeature.FEATURE_MMTEL) {
11074 // ImsMmTelManager
11075 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11076 TelephonyPermissions
11077 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11078 mApp, subId, "registerImsStateCallback");
11079 } else if (feature == ImsFeature.FEATURE_RCS) {
11080 // ImsRcsManager or SipDelegateManager
11081 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11082 Binder.getCallingUid(), "registerImsStateCallback",
11083 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11084 Manifest.permission.READ_PRECISE_PHONE_STATE,
11085 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11086 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11087 }
11088
11089 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11090 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11091 "IMS not available on device.");
11092 }
11093
11094 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11095 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11096 }
11097
11098 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11099 if (controller == null) {
11100 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11101 "IMS not available on device.");
11102 }
11103
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011104 if (callingPackage == null) {
11105 callingPackage = getCurrentPackageName();
11106 }
11107
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011108 final long token = Binder.clearCallingIdentity();
11109 try {
11110 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011111 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011112 } catch (ImsException e) {
11113 throw new ServiceSpecificException(e.getCode());
11114 } finally {
11115 Binder.restoreCallingIdentity(token);
11116 }
11117 }
11118
11119 /**
11120 * Unregister an IMS connection state callback
11121 */
11122 @Override
11123 public void unregisterImsStateCallback(IImsStateCallback cb) {
11124 final long token = Binder.clearCallingIdentity();
11125 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11126 if (controller == null) {
11127 return;
11128 }
11129 try {
11130 controller.unregisterImsStateCallback(cb);
11131 } finally {
11132 Binder.restoreCallingIdentity(token);
11133 }
11134 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011135
11136 /**
11137 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11138 *
11139 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11140 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11141 * SecurityException.
11142 * If there is current registered network this value will be same as the registered cell
11143 * identity. If the device goes out of service the previous cell identity is cached and
11144 * will be returned. If the cache age of the Cell identity is more than 24 hours
11145 * it will be cleared and null will be returned.
11146 *
11147 */
11148 @Override
11149 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11150 String callingFeatureId) {
11151 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11152 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11153 LocationAccessPolicy.checkLocationPermission(mApp,
11154 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11155 .setCallingPackage(callingPackage)
11156 .setCallingFeatureId(callingFeatureId)
11157 .setCallingPid(Binder.getCallingPid())
11158 .setCallingUid(Binder.getCallingUid())
11159 .setMethod("getLastKnownCellIdentity")
11160 .setLogAsInfo(true)
11161 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11162 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11163 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11164 .build());
11165
11166 boolean hasFinePermission =
11167 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11168 if (!hasFinePermission
11169 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11170 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011171 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011172 }
11173
11174 final long identity = Binder.clearCallingIdentity();
11175 try {
11176 Phone phone = getPhone(subId);
11177 if (phone == null) return null;
11178 ServiceStateTracker sst = phone.getServiceStateTracker();
11179 if (sst == null) return null;
11180 return sst.getLastKnownCellIdentity();
11181 } finally {
11182 Binder.restoreCallingIdentity(identity);
11183 }
11184 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011185
jimsun3b9ccac2021-10-26 15:01:23 +080011186 /**
11187 * Sets the modem service class Name that Telephony will bind to.
11188 *
11189 * @param serviceName The class name of the modem service.
11190 * @return true if the operation is succeed, otherwise false.
11191 */
11192 public boolean setModemService(String serviceName) {
11193 Log.d(LOG_TAG, "setModemService - " + serviceName);
11194 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11196 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11197 "setModemService");
11198 return mPhoneConfigurationManager.setModemService(serviceName);
11199 }
11200
11201 /**
11202 * Return the class name of the currently bounded modem service.
11203 *
11204 * @return the class name of the modem service.
11205 */
11206 public String getModemService() {
11207 String result;
11208 Log.d(LOG_TAG, "getModemService");
11209 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11210 TelephonyPermissions
11211 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11212 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11213 "getModemService");
11214 result = mPhoneConfigurationManager.getModemService();
11215 Log.d(LOG_TAG, "result = " + result);
11216 return result;
11217 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011218
11219 @Override
11220 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11221 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11222 mApp.enforceCallingOrSelfPermission(
11223 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11224 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11225
11226 final long identity = Binder.clearCallingIdentity();
11227 try {
11228 Phone phone = getPhone(subId);
11229 if (phone == null) return;
11230 phone.setVoiceServiceStateOverride(hasService);
11231 } finally {
11232 Binder.restoreCallingIdentity(identity);
11233 }
11234 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011235
11236 /**
11237 * set removable eSIM as default eUICC.
11238 *
11239 * @hide
11240 */
11241 @Override
11242 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11243 enforceModifyPermission();
11244 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11245
11246 final long identity = Binder.clearCallingIdentity();
11247 try {
11248 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11249 } finally {
11250 Binder.restoreCallingIdentity(identity);
11251 }
11252 }
11253
11254 /**
11255 * Returns whether the removable eSIM is default eUICC or not.
11256 *
11257 * @hide
11258 */
11259 @Override
11260 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11261 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11262 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11263
11264 final long identity = Binder.clearCallingIdentity();
11265 try {
11266 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11267 } finally {
11268 Binder.restoreCallingIdentity(identity);
11269 }
11270 }
11271
11272
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011273}