blob: 837df86a074e74f8ccc0f22034636dd8cfe60ebb [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;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700187import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700189import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800190import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700191import com.android.internal.telephony.imsphone.ImsPhone;
192import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000193import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800194import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700195import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196import com.android.internal.telephony.uicc.IccIoResult;
197import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800198import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700199import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000202import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800203import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000204import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800205import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700206import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700207import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800208import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800209import com.android.phone.callcomposer.CallComposerPictureManager;
210import com.android.phone.callcomposer.CallComposerPictureTransfer;
211import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700212import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700213import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800214import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700215import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700216import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800217import com.android.services.telephony.TelecomAccountRegistry;
218import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800219import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800220
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700222import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.io.IOException;
224import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700225import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800227import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000228import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800229import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800230import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800231import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800232import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100233import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800234import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700235import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800236import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800237import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800238import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800239import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800240import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241
242/**
243 * Implementation of the ITelephony interface.
244 */
Santos Cordon117fee72014-05-16 17:56:12 -0700245public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246 private static final String LOG_TAG = "PhoneInterfaceManager";
247 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
248 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800249 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250
251 // Message codes used with mMainThreadHandler
252 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700253 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
254 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700255 private static final int CMD_OPEN_CHANNEL = 9;
256 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
257 private static final int CMD_CLOSE_CHANNEL = 11;
258 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800259 private static final int CMD_NV_READ_ITEM = 13;
260 private static final int EVENT_NV_READ_ITEM_DONE = 14;
261 private static final int CMD_NV_WRITE_ITEM = 15;
262 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
263 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
264 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_RESET_MODEM_CONFIG = 19;
266 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800267 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
268 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800269 private static final int CMD_SEND_ENVELOPE = 25;
270 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000271 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
272 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700273 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
274 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
275 private static final int CMD_EXCHANGE_SIM_IO = 31;
276 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800277 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
278 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700279 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
280 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700281 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
282 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700283 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
284 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
285 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
286 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700287 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
288 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
289 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
290 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700291 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800292 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
293 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000294 private static final int CMD_SWITCH_SLOTS = 50;
295 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700296 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
297 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
298 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
299 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
300 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
301 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
302 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
303 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700304 private static final int CMD_GET_ALL_CELL_INFO = 60;
305 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
306 private static final int CMD_GET_CELL_LOCATION = 62;
307 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700308 private static final int CMD_MODEM_REBOOT = 64;
309 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700310 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
311 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800312 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
313 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700314 private static final int CMD_GET_MODEM_STATUS = 70;
315 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700316 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
317 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700318 private static final int CMD_ERASE_MODEM_CONFIG = 74;
319 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800320 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
321 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
322 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
323 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800324 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
325 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800326 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800327 private static final int CMD_GET_CALL_FORWARDING = 83;
328 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
329 private static final int CMD_SET_CALL_FORWARDING = 85;
330 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
331 private static final int CMD_GET_CALL_WAITING = 87;
332 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
333 private static final int CMD_SET_CALL_WAITING = 89;
334 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700335 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
336 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
337 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
338 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700339 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
340 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800341 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
342 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800343 private static final int CMD_SET_DATA_THROTTLING = 99;
344 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800345 private static final int CMD_SET_SIM_POWER = 101;
346 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800347 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
348 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
349 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
350 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800351 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
352 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000353 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800354 private static final int CMD_GET_SLICING_CONFIG = 110;
355 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800356 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700357 private static final int CMD_ENABLE_VONR = 113;
358 private static final int EVENT_ENABLE_VONR_DONE = 114;
359 private static final int CMD_IS_VONR_ENABLED = 115;
360 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800362 // Parameters of select command.
363 private static final int SELECT_COMMAND = 0xA4;
364 private static final int SELECT_P1 = 0x04;
365 private static final int SELECT_P2 = 0;
366 private static final int SELECT_P3 = 0x10;
367
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 /** The singleton instance. */
369 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800370 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800374 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700375 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700377 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800379 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700381 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800382 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000383 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
Peter Wangdafb9ac2020-01-15 14:13:38 -0800385 /** User Activity */
386 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800387 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
388
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700389 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
390
Derek Tan97ebb422014-09-05 16:55:38 -0700391 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
392 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800393 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800394 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700395
Michelecea4cf22018-12-21 15:00:11 -0800396 // String to store multi SIM allowed
397 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
398
Derek Tan740e1672017-06-27 14:56:27 -0700399 // The AID of ISD-R.
400 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
401
yinxub1bed742017-04-17 11:45:04 -0700402 private NetworkScanRequestTracker mNetworkScanRequestTracker;
403
David Kelly5e06a7f2018-03-12 14:10:59 +0000404 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
405 private static final int MANUFACTURER_CODE_LENGTH = 8;
406
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800407 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800408 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800409
Derek Tan89e89d42014-07-08 17:00:10 -0700410 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700411 * Experiment flag to enable erase modem config on reset network, default value is false
412 */
413 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
414 "reset_network_erase_modem_config_enabled";
415
Rambo Wang0f050d82021-02-12 11:43:36 -0800416 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800417
sandeepjsb6c87872021-09-27 15:34:44 +0000418 /**
419 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
420 * one ICCID active at the same time.
421 * Apps should use below API signatures if targeting SDK is T and beyond.
422 *
423 * @hide
424 */
425 @ChangeId
426 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
427 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800428
Naina Nallurid63128d2019-09-17 14:10:30 -0700429 /**
Chen Xu540470b2021-12-14 17:15:47 -0800430 * Apps targeting on Android T and beyond will get exception whenever icc close channel
431 * operation fails.
432 */
433 @ChangeId
434 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
435 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
436
437 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 * A request object to use for transmitting data to an ICC.
439 */
440 private static final class IccAPDUArgument {
441 public int channel, cla, command, p1, p2, p3;
442 public String data;
443
444 public IccAPDUArgument(int channel, int cla, int command,
445 int p1, int p2, int p3, String data) {
446 this.channel = channel;
447 this.cla = cla;
448 this.command = command;
449 this.p1 = p1;
450 this.p2 = p2;
451 this.p3 = p3;
452 this.data = data;
453 }
454 }
455
456 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700457 * A request object to use for transmitting data to an ICC.
458 */
459 private static final class ManualNetworkSelectionArgument {
460 public OperatorInfo operatorInfo;
461 public boolean persistSelection;
462
463 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
464 this.operatorInfo = operatorInfo;
465 this.persistSelection = persistSelection;
466 }
467 }
468
469 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
471 * request after sending. The main thread will notify the request when it is complete.
472 */
473 private static final class MainThreadRequest {
474 /** The argument to use for the request */
475 public Object argument;
476 /** The result of the request that is run on the main thread */
477 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800478 // The subscriber id that this request applies to. Defaults to
479 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
480 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481
Nathan Harold92bed182018-10-12 18:16:49 -0700482 // In cases where subId is unavailable, the caller needs to specify the phone.
483 public Phone phone;
484
vagdeviaf9a5b92018-08-15 16:01:53 -0700485 public WorkSource workSource;
486
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700487 public MainThreadRequest(Object argument) {
488 this.argument = argument;
489 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800490
Nathan Harold92bed182018-10-12 18:16:49 -0700491 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
492 this.argument = argument;
493 if (phone != null) {
494 this.phone = phone;
495 }
496 this.workSource = workSource;
497 }
498
vagdeviaf9a5b92018-08-15 16:01:53 -0700499 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800500 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800501 if (subId != null) {
502 this.subId = subId;
503 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700504 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 }
507
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800508 private static final class IncomingThirdPartyCallArgs {
509 public final ComponentName component;
510 public final String callId;
511 public final String callerDisplayName;
512
513 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
514 String callerDisplayName) {
515 this.component = component;
516 this.callId = callId;
517 this.callerDisplayName = callerDisplayName;
518 }
519 }
520
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 /**
522 * A handler that processes messages on the main thread in the phone process. Since many
523 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
524 * inbound binder threads to the main thread in the phone process. The Binder thread
525 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
526 * on, which will be notified when the operation completes and will contain the result of the
527 * request.
528 *
529 * <p>If a MainThreadRequest object is provided in the msg.obj field,
530 * note that request.result must be set to something non-null for the calling thread to
531 * unblock.
532 */
533 private final class MainThreadHandler extends Handler {
534 @Override
535 public void handleMessage(Message msg) {
536 MainThreadRequest request;
537 Message onCompleted;
538 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000539 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800541 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542
543 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 case CMD_HANDLE_USSD_REQUEST: {
545 request = (MainThreadRequest) msg.obj;
546 final Phone phone = getPhoneFromRequest(request);
547 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800548 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700550
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 if (!isUssdApiAllowed(request.subId)) {
552 // Carrier does not support use of this API, return failure.
553 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
554 UssdResponse response = new UssdResponse(ussdRequest, null);
555 Bundle returnData = new Bundle();
556 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
557 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700558
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 request.result = true;
560 notifyRequester(request);
561 return;
562 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700563
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 try {
565 request.result = phone != null
566 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
567 } catch (CallStateException cse) {
568 request.result = false;
569 }
570 // Wake up the requesting thread
571 notifyRequester(request);
572 break;
pkanwar32d516d2016-10-14 19:37:38 -0700573 }
574
Yorke Lee716f67e2015-06-17 15:39:16 -0700575 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700577 final Phone phone = getPhoneFromRequest(request);
578 request.result = phone != null ?
579 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
580 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000589 uiccPort = getUiccPortFromRequest(request);
590 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800592 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800596 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000597 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800598 iccArgument.channel, iccArgument.cla, iccArgument.command,
599 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
600 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 break;
603
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 ar = (AsyncResult) msg.obj;
606 request = (MainThreadRequest) ar.userObj;
607 if (ar.exception == null && ar.result != null) {
608 request.result = ar.result;
609 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800610 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.result == null) {
612 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800613 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800615 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 } else {
617 loge("iccTransmitApduLogicalChannel: Unknown exception");
618 }
619 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 break;
622
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
624 request = (MainThreadRequest) msg.obj;
625 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000626 uiccPort = getUiccPortFromRequest(request);
627 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800629 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800633 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000634 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800635 iccArgument.cla, iccArgument.command, iccArgument.p1,
636 iccArgument.p2,
637 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 }
639 break;
640
641 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
642 ar = (AsyncResult) msg.obj;
643 request = (MainThreadRequest) ar.userObj;
644 if (ar.exception == null && ar.result != null) {
645 request.result = ar.result;
646 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800647 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 if (ar.result == null) {
649 loge("iccTransmitApduBasicChannel: Empty response");
650 } else if (ar.exception instanceof CommandException) {
651 loge("iccTransmitApduBasicChannel: CommandException: " +
652 ar.exception);
653 } else {
654 loge("iccTransmitApduBasicChannel: Unknown exception");
655 }
656 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 break;
659
660 case CMD_EXCHANGE_SIM_IO:
661 request = (MainThreadRequest) msg.obj;
662 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000663 uiccPort = getUiccPortFromRequest(request);
664 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800666 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 } else {
669 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
670 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000671 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
673 iccArgument.data, onCompleted);
674 }
675 break;
676
677 case EVENT_EXCHANGE_SIM_IO_DONE:
678 ar = (AsyncResult) msg.obj;
679 request = (MainThreadRequest) ar.userObj;
680 if (ar.exception == null && ar.result != null) {
681 request.result = ar.result;
682 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800683 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 break;
687
Derek Tan4d5e5c12014-02-04 11:54:58 -0800688 case CMD_SEND_ENVELOPE:
689 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000690 uiccPort = getUiccPortFromRequest(request);
691 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800693 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 } else {
696 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800697 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700698 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800699 break;
700
701 case EVENT_SEND_ENVELOPE_DONE:
702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800706 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800707 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700708 if (ar.result == null) {
709 loge("sendEnvelopeWithStatus: Empty response");
710 } else if (ar.exception instanceof CommandException) {
711 loge("sendEnvelopeWithStatus: CommandException: " +
712 ar.exception);
713 } else {
714 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
715 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800718 break;
719
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 case CMD_OPEN_CHANNEL:
721 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000722 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800723 IccLogicalChannelRequest openChannelRequest =
724 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000725 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700726 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800727 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800728 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700729 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700730 } else {
731 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800732 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
733 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700734 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700735 break;
736
737 case EVENT_OPEN_CHANNEL_DONE:
738 ar = (AsyncResult) msg.obj;
739 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 int[] result = (int[]) ar.result;
743 int channelId = result[0];
744 byte[] selectResponse = null;
745 if (result.length > 1) {
746 selectResponse = new byte[result.length - 1];
747 for (int i = 1; i < result.length; ++i) {
748 selectResponse[i - 1] = (byte) result[i];
749 }
750 }
751 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800752 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800753
754 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700755 if (uiccPort == null) {
756 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
757 } else {
758 IccLogicalChannelRequest channelRequest =
759 (IccLogicalChannelRequest) request.argument;
760 channelRequest.channel = channelId;
761 uiccPort.onLogicalChannelOpened(channelRequest);
762 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 if (ar.result == null) {
765 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700766 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700767 if (ar.exception != null) {
768 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
769 }
770
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700771 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700772 if (ar.exception instanceof CommandException) {
773 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800774 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700775 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700776 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700777 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700778 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700779 }
780 }
781 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800782 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700784 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700785 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 break;
787
788 case CMD_CLOSE_CHANNEL:
789 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000790 uiccPort = getUiccPortFromRequest(request);
791 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700792 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800793 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800794 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800795 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700796 } else {
797 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000798 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700799 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 break;
801
802 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 if (ar.exception == null) {
806 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800807 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700808 if (uiccPort == null) {
809 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
810 } else {
811 final int channelId = (Integer) request.argument;
812 uiccPort.onLogicalChannelClosed(channelId);
813 }
Chen Xu540470b2021-12-14 17:15:47 -0800814 } else {
815 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800816 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800817 if (ar.exception instanceof CommandException) {
818 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
819 CommandException.Error error =
820 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800821 if (error == CommandException.Error.INVALID_ARGUMENTS) {
822 // should only throw exceptions from the binder threads.
823 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800824 "iccCloseLogicalChannel: invalid argument ");
825 }
826 } else {
827 loge("iccCloseLogicalChannel: Unknown exception");
828 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800829 request.result = (exception != null) ? exception :
830 new IllegalStateException(
831 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800832 }
833 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800834 break;
835
836 case CMD_NV_READ_ITEM:
837 request = (MainThreadRequest) msg.obj;
838 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800839 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
840 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800841 break;
842
843 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800846 if (ar.exception == null && ar.result != null) {
847 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800849 request.result = "";
850 if (ar.result == null) {
851 loge("nvReadItem: Empty response");
852 } else if (ar.exception instanceof CommandException) {
853 loge("nvReadItem: CommandException: " +
854 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700855 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800856 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700857 }
858 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700859 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700860 break;
861
Jake Hambye994d462014-02-03 13:10:13 -0800862 case CMD_NV_WRITE_ITEM:
863 request = (MainThreadRequest) msg.obj;
864 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
865 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800866 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700867 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800868 break;
869
870 case EVENT_NV_WRITE_ITEM_DONE:
871 handleNullReturnEvent(msg, "nvWriteItem");
872 break;
873
874 case CMD_NV_WRITE_CDMA_PRL:
875 request = (MainThreadRequest) msg.obj;
876 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800877 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800878 break;
879
880 case EVENT_NV_WRITE_CDMA_PRL_DONE:
881 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
882 break;
883
chen xu6dac5ab2018-10-26 17:39:23 -0700884 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800885 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700886 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800887 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800888 break;
889
chen xu6dac5ab2018-10-26 17:39:23 -0700890 case EVENT_RESET_MODEM_CONFIG_DONE:
891 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800892 break;
893
Sooraj Sasindran37444802020-08-11 10:40:43 -0700894 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
895 request = (MainThreadRequest) msg.obj;
896 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
897 request);
898 Phone phone = getPhoneFromRequest(request);
899 if (phone != null) {
900 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
901 } else {
902 loge("isNRDualConnectivityEnabled: No phone object");
903 request.result = false;
904 notifyRequester(request);
905 }
906 break;
907 }
908
909 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
915 // request.result must be set to something non-null
916 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700917 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700918 request.result = ar.result;
919 } else {
920 request.result = false;
921 }
922 if (ar.result == null) {
923 loge("isNRDualConnectivityEnabled: Empty response");
924 } else if (ar.exception instanceof CommandException) {
925 loge("isNRDualConnectivityEnabled: CommandException: "
926 + ar.exception);
927 } else {
928 loge("isNRDualConnectivityEnabled: Unknown exception");
929 }
930 }
931 notifyRequester(request);
932 break;
933
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700934 case CMD_IS_VONR_ENABLED: {
935 request = (MainThreadRequest) msg.obj;
936 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
937 request);
938 Phone phone = getPhoneFromRequest(request);
939 if (phone != null) {
940 phone.isVoNrEnabled(onCompleted, request.workSource);
941 } else {
942 loge("isVoNrEnabled: No phone object");
943 request.result = false;
944 notifyRequester(request);
945 }
946 break;
947 }
948
949 case EVENT_IS_VONR_ENABLED_DONE:
950 ar = (AsyncResult) msg.obj;
951 request = (MainThreadRequest) ar.userObj;
952 if (ar.exception == null && ar.result != null) {
953 request.result = ar.result;
954 } else {
955 // request.result must be set to something non-null
956 // for the calling thread to unblock
957 if (ar.result != null) {
958 request.result = ar.result;
959 } else {
960 request.result = false;
961 }
962 if (ar.result == null) {
963 loge("isVoNrEnabled: Empty response");
964 } else if (ar.exception instanceof CommandException) {
965 loge("isVoNrEnabled: CommandException: "
966 + ar.exception);
967 } else {
968 loge("isVoNrEnabled: Unknown exception");
969 }
970 }
971 notifyRequester(request);
972 break;
973
Sooraj Sasindran37444802020-08-11 10:40:43 -0700974 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
975 request = (MainThreadRequest) msg.obj;
976 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
977 Phone phone = getPhoneFromRequest(request);
978 if (phone != null) {
979 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
980 request.workSource);
981 } else {
982 loge("enableNrDualConnectivity: No phone object");
983 request.result =
984 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
985 notifyRequester(request);
986 }
987 break;
988 }
989
990 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
991 ar = (AsyncResult) msg.obj;
992 request = (MainThreadRequest) ar.userObj;
993 if (ar.exception == null) {
994 request.result =
995 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
996 } else {
997 request.result =
998 TelephonyManager
999 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1000 if (ar.exception instanceof CommandException) {
1001 CommandException.Error error =
1002 ((CommandException) (ar.exception)).getCommandError();
1003 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1004 request.result =
1005 TelephonyManager
1006 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001007 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1008 request.result =
1009 TelephonyManager
1010 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001011 }
1012 loge("enableNrDualConnectivity" + ": CommandException: "
1013 + ar.exception);
1014 } else {
1015 loge("enableNrDualConnectivity" + ": Unknown exception");
1016 }
1017 }
1018 notifyRequester(request);
1019 break;
1020 }
1021
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001022 case CMD_ENABLE_VONR: {
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1025 Phone phone = getPhoneFromRequest(request);
1026 if (phone != null) {
1027 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1028 request.workSource);
1029 } else {
1030 loge("setVoNrEnabled: No phone object");
1031 request.result =
1032 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1033 notifyRequester(request);
1034 }
1035 break;
1036 }
1037
1038 case EVENT_ENABLE_VONR_DONE: {
1039 ar = (AsyncResult) msg.obj;
1040 request = (MainThreadRequest) ar.userObj;
1041 if (ar.exception == null) {
1042 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1043 } else {
1044 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1045 if (ar.exception instanceof CommandException) {
1046 CommandException.Error error =
1047 ((CommandException) (ar.exception)).getCommandError();
1048 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1049 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1050 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1051 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1052 } else {
1053 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1054 }
1055 loge("setVoNrEnabled" + ": CommandException: "
1056 + ar.exception);
1057 } else {
1058 loge("setVoNrEnabled" + ": Unknown exception");
1059 }
1060 }
1061 notifyRequester(request);
1062 break;
1063 }
1064
SongFerngWang3ef3e072020-12-21 16:41:52 +08001065 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001066 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001067 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1068 request);
1069 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001070 break;
1071
SongFerngWang3ef3e072020-12-21 16:41:52 +08001072 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 if (ar.exception == null && ar.result != null) {
1076 request.result = ar.result; // Integer
1077 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301078 // request.result must be set to something non-null
1079 // for the calling thread to unblock
1080 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001081 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001082 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001083 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001084 loge("getAllowedNetworkTypesBitmask: CommandException: "
1085 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001086 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001087 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001088 }
1089 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001090 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001091 break;
1092
SongFerngWang3ef3e072020-12-21 16:41:52 +08001093 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001095 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1096 request);
1097 Pair<Integer, Long> reasonWithNetworkTypes =
1098 (Pair<Integer, Long>) request.argument;
1099 getPhoneFromRequest(request).setAllowedNetworkTypes(
1100 reasonWithNetworkTypes.first,
1101 reasonWithNetworkTypes.second,
1102 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001103 break;
1104
SongFerngWang3ef3e072020-12-21 16:41:52 +08001105 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1106 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001107 break;
1108
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001109 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1110 request = (MainThreadRequest)msg.obj;
1111 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001112 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001113 break;
1114
1115 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1116 ar = (AsyncResult)msg.obj;
1117 request = (MainThreadRequest)ar.userObj;
1118 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001119 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001120 break;
1121
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001122 case CMD_SET_VOICEMAIL_NUMBER:
1123 request = (MainThreadRequest) msg.obj;
1124 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1125 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001126 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1127 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001128 break;
1129
1130 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1131 handleNullReturnEvent(msg, "setVoicemailNumber");
1132 break;
1133
Stuart Scott54788802015-03-30 13:18:01 -07001134 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1135 request = (MainThreadRequest) msg.obj;
1136 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1137 request);
1138 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1139 break;
1140
1141 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1142 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1143 break;
1144
Shishir Agrawal302c8692015-06-19 13:49:39 -07001145 case CMD_PERFORM_NETWORK_SCAN:
1146 request = (MainThreadRequest) msg.obj;
1147 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1148 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1149 break;
1150
Hall Liu27d24262020-09-18 19:04:59 -07001151 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001152 request = (MainThreadRequest) msg.obj;
1153 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001154 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1155 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1156 request.argument;
1157 int callForwardingReason = args.first;
1158 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001159 break;
Hall Liu27d24262020-09-18 19:04:59 -07001160 }
1161 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001162 ar = (AsyncResult) msg.obj;
1163 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001164 TelephonyManager.CallForwardingInfoCallback callback =
1165 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1166 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001167 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001168 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001169 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1170 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1171 // Service Class is a bit mask per 3gpp 27.007. Search for
1172 // any service for voice call.
1173 if ((callForwardInfo.serviceClass
1174 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001175 callForwardingInfo = new CallForwardingInfo(
1176 callForwardInfo.status
1177 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001178 callForwardInfo.reason,
1179 callForwardInfo.number,
1180 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001181 break;
1182 }
1183 }
1184 // Didn't find a call forward info for voice call.
1185 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001186 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1187 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001188 }
Hall Liu27d24262020-09-18 19:04:59 -07001189 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001190 } else {
1191 if (ar.result == null) {
1192 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1193 }
1194 if (ar.exception != null) {
1195 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1196 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001197 int errorCode = TelephonyManager
1198 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001199 if (ar.exception instanceof CommandException) {
1200 CommandException.Error error =
1201 ((CommandException) (ar.exception)).getCommandError();
1202 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001203 errorCode = TelephonyManager
1204 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001205 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001206 errorCode = TelephonyManager
1207 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001208 }
1209 }
Hall Liu27d24262020-09-18 19:04:59 -07001210 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001211 }
Shuo Qian4a594052020-01-23 11:59:30 -08001212 break;
Hall Liu27d24262020-09-18 19:04:59 -07001213 }
Shuo Qian4a594052020-01-23 11:59:30 -08001214
Hall Liu27d24262020-09-18 19:04:59 -07001215 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001216 request = (MainThreadRequest) msg.obj;
1217 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001218 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001219 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001220 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1221 request.argument).first;
1222 request.phone.setCallForwardingOption(
1223 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001224 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001225 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001226 callForwardingInfoToSet.getReason(),
1227 callForwardingInfoToSet.getNumber(),
1228 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1229 break;
Hall Liu27d24262020-09-18 19:04:59 -07001230 }
Shuo Qian4a594052020-01-23 11:59:30 -08001231
Hall Liu27d24262020-09-18 19:04:59 -07001232 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001233 ar = (AsyncResult) msg.obj;
1234 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001235 Consumer<Integer> callback =
1236 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1237 request.argument).second;
1238 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001239 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001240 int errorCode = TelephonyManager.CallForwardingInfoCallback
1241 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001242 if (ar.exception instanceof CommandException) {
1243 CommandException.Error error =
1244 ((CommandException) (ar.exception)).getCommandError();
1245 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001246 errorCode = TelephonyManager.CallForwardingInfoCallback
1247 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001248 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001249 errorCode = TelephonyManager.CallForwardingInfoCallback
1250 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001251 }
1252 }
1253 callback.accept(errorCode);
1254 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001255 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001256 }
Shuo Qian4a594052020-01-23 11:59:30 -08001257 break;
Hall Liu27d24262020-09-18 19:04:59 -07001258 }
Shuo Qian4a594052020-01-23 11:59:30 -08001259
Hall Liu27d24262020-09-18 19:04:59 -07001260 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001261 request = (MainThreadRequest) msg.obj;
1262 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1263 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1264 break;
Hall Liu27d24262020-09-18 19:04:59 -07001265 }
Shuo Qian4a594052020-01-23 11:59:30 -08001266
Hall Liu27d24262020-09-18 19:04:59 -07001267 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001268 ar = (AsyncResult) msg.obj;
1269 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001270 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001271 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001272 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001273 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001274 // Service Class is a bit mask per 3gpp 27.007.
1275 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001276 if (callForwardResults.length > 1
1277 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001278 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001279 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001280 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1281 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001282 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001283 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001284 }
1285 } else {
1286 if (ar.result == null) {
1287 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1288 }
1289 if (ar.exception != null) {
1290 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1291 }
1292 if (ar.exception instanceof CommandException) {
1293 CommandException.Error error =
1294 ((CommandException) (ar.exception)).getCommandError();
1295 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001296 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001297 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001298 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1299 callWaitingStatus =
1300 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001301 }
1302 }
1303 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001304 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001305 break;
Hall Liu27d24262020-09-18 19:04:59 -07001306 }
Shuo Qian4a594052020-01-23 11:59:30 -08001307
Hall Liu27d24262020-09-18 19:04:59 -07001308 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001309 request = (MainThreadRequest) msg.obj;
1310 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001311 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1312 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001313 break;
Hall Liu27d24262020-09-18 19:04:59 -07001314 }
Shuo Qian4a594052020-01-23 11:59:30 -08001315
Hall Liu27d24262020-09-18 19:04:59 -07001316 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001317 ar = (AsyncResult) msg.obj;
1318 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001319 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1320 Consumer<Integer> callback =
1321 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1322 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001323 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001324 if (ar.exception instanceof CommandException) {
1325 CommandException.Error error =
1326 ((CommandException) (ar.exception)).getCommandError();
1327 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1328 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001329 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1330 callback.accept(
1331 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001332 } else {
1333 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1334 }
1335 } else {
1336 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1337 }
1338 } else {
1339 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1340 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001341 }
Shuo Qian4a594052020-01-23 11:59:30 -08001342 break;
Hall Liu27d24262020-09-18 19:04:59 -07001343 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001344 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1345 ar = (AsyncResult) msg.obj;
1346 request = (MainThreadRequest) ar.userObj;
1347 CellNetworkScanResult cellScanResult;
1348 if (ar.exception == null && ar.result != null) {
1349 cellScanResult = new CellNetworkScanResult(
1350 CellNetworkScanResult.STATUS_SUCCESS,
1351 (List<OperatorInfo>) ar.result);
1352 } else {
1353 if (ar.result == null) {
1354 loge("getCellNetworkScanResults: Empty response");
1355 }
1356 if (ar.exception != null) {
1357 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1358 }
1359 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1360 if (ar.exception instanceof CommandException) {
1361 CommandException.Error error =
1362 ((CommandException) (ar.exception)).getCommandError();
1363 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1364 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1365 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1366 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1367 }
1368 }
1369 cellScanResult = new CellNetworkScanResult(errorCode, null);
1370 }
1371 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001372 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001373 break;
1374
1375 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1376 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001377 ManualNetworkSelectionArgument selArg =
1378 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001379 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1380 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001381 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1382 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001383 break;
1384
1385 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001386 ar = (AsyncResult) msg.obj;
1387 request = (MainThreadRequest) ar.userObj;
1388 if (ar.exception == null) {
1389 request.result = true;
1390 } else {
1391 request.result = false;
1392 loge("setNetworkSelectionModeManual " + ar.exception);
1393 }
1394 notifyRequester(request);
1395 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001396 break;
1397
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001398 case CMD_GET_MODEM_ACTIVITY_INFO:
1399 request = (MainThreadRequest) msg.obj;
1400 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001401 if (defaultPhone != null) {
1402 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001403 } else {
1404 ResultReceiver result = (ResultReceiver) request.argument;
1405 Bundle bundle = new Bundle();
1406 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001407 new ModemActivityInfo(0, 0, 0,
1408 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001409 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001410 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001411 break;
1412
Hall Liud0f208c2020-10-14 16:54:44 -07001413 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001414 ar = (AsyncResult) msg.obj;
1415 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001416 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001417 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001418 if (mLastModemActivityInfo == null) {
1419 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1420 mLastModemActivitySpecificInfo[0] =
1421 new ActivityStatsTechSpecificInfo(
1422 0,
1423 0,
1424 new int[ModemActivityInfo.getNumTxPowerLevels()],
1425 0);
1426 mLastModemActivityInfo =
1427 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1428 }
1429
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001430 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001431 // Update the last modem activity info and the result of the request.
1432 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1433 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001434 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001435 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001436 mLastModemActivityInfo =
1437 new ModemActivityInfo(
1438 mLastModemActivityInfo.getTimestampMillis(),
1439 mLastModemActivityInfo.getSleepTimeMillis(),
1440 mLastModemActivityInfo.getIdleTimeMillis(),
1441 mLastModemActivitySpecificInfo);
1442
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001443 } else {
1444 if (ar.result == null) {
1445 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001446 error = TelephonyManager.ModemActivityInfoException
1447 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001448 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001449 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001450 error = TelephonyManager.ModemActivityInfoException
1451 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001452 } else {
1453 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001454 error = TelephonyManager.ModemActivityInfoException
1455 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001456 }
1457 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001458 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001459 if (mLastModemActivityInfo != null) {
1460 bundle.putParcelable(
1461 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1462 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001463 } else {
1464 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1465 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001466 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001467 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001469 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001470
Meng Wang1a7c35a2016-05-05 20:56:15 -07001471 case CMD_SET_ALLOWED_CARRIERS:
1472 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001473 CarrierRestrictionRules argument =
1474 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001475 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001476 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001477 break;
1478
1479 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1480 ar = (AsyncResult) msg.obj;
1481 request = (MainThreadRequest) ar.userObj;
1482 if (ar.exception == null && ar.result != null) {
1483 request.result = ar.result;
1484 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001485 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1486 if (ar.exception instanceof CommandException) {
1487 loge("setAllowedCarriers: CommandException: " + ar.exception);
1488 CommandException.Error error =
1489 ((CommandException) (ar.exception)).getCommandError();
1490 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1491 request.result =
1492 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1493 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001494 } else {
1495 loge("setAllowedCarriers: Unknown exception");
1496 }
1497 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001498 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001499 break;
1500
1501 case CMD_GET_ALLOWED_CARRIERS:
1502 request = (MainThreadRequest) msg.obj;
1503 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001504 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001505 break;
1506
1507 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1508 ar = (AsyncResult) msg.obj;
1509 request = (MainThreadRequest) ar.userObj;
1510 if (ar.exception == null && ar.result != null) {
1511 request.result = ar.result;
1512 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001513 request.result = new IllegalStateException(
1514 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001515 if (ar.result == null) {
1516 loge("getAllowedCarriers: Empty response");
1517 } else if (ar.exception instanceof CommandException) {
1518 loge("getAllowedCarriers: CommandException: " +
1519 ar.exception);
1520 } else {
1521 loge("getAllowedCarriers: Unknown exception");
1522 }
1523 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001524 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001525 break;
1526
Nathan Haroldb3014052017-01-25 15:57:32 -08001527 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1528 ar = (AsyncResult) msg.obj;
1529 request = (MainThreadRequest) ar.userObj;
1530 if (ar.exception == null && ar.result != null) {
1531 request.result = ar.result;
1532 } else {
1533 request.result = new IllegalArgumentException(
1534 "Failed to retrieve Forbidden Plmns");
1535 if (ar.result == null) {
1536 loge("getForbiddenPlmns: Empty response");
1537 } else {
1538 loge("getForbiddenPlmns: Unknown exception");
1539 }
1540 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001541 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001542 break;
1543
1544 case CMD_GET_FORBIDDEN_PLMNS:
1545 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001546 uiccPort = getUiccPortFromRequest(request);
1547 if (uiccPort == null) {
1548 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001549 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001550 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001551 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001552 break;
1553 }
1554 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001555 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001556 if (uiccApp == null) {
1557 loge("getForbiddenPlmns() no app with specified type -- "
1558 + appType);
1559 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001560 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001561 break;
1562 } else {
1563 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1564 + " specified type -- " + appType);
1565 }
1566 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1567 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1568 onCompleted);
1569 break;
1570
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001571 case CMD_SWITCH_SLOTS:
1572 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001573 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001574 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001575 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001576 break;
1577
1578 case EVENT_SWITCH_SLOTS_DONE:
1579 ar = (AsyncResult) msg.obj;
1580 request = (MainThreadRequest) ar.userObj;
1581 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001582 notifyRequester(request);
1583 break;
1584 case CMD_GET_NETWORK_SELECTION_MODE:
1585 request = (MainThreadRequest) msg.obj;
1586 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1587 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1588 break;
1589
1590 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1591 ar = (AsyncResult) msg.obj;
1592 request = (MainThreadRequest) ar.userObj;
1593 if (ar.exception != null) {
1594 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1595 } else {
1596 int mode = ((int[]) ar.result)[0];
1597 if (mode == 0) {
1598 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1599 } else {
1600 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1601 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001602 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001603 notifyRequester(request);
1604 break;
1605 case CMD_GET_CDMA_ROAMING_MODE:
1606 request = (MainThreadRequest) msg.obj;
1607 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1608 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1609 break;
1610 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1611 ar = (AsyncResult) msg.obj;
1612 request = (MainThreadRequest) ar.userObj;
1613 if (ar.exception != null) {
1614 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1615 } else {
1616 request.result = ((int[]) ar.result)[0];
1617 }
1618 notifyRequester(request);
1619 break;
1620 case CMD_SET_CDMA_ROAMING_MODE:
1621 request = (MainThreadRequest) msg.obj;
1622 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1623 int mode = (int) request.argument;
1624 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1625 break;
1626 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1627 ar = (AsyncResult) msg.obj;
1628 request = (MainThreadRequest) ar.userObj;
1629 request.result = ar.exception == null;
1630 notifyRequester(request);
1631 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001632 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1633 request = (MainThreadRequest) msg.obj;
1634 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1635 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1636 break;
1637 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1638 ar = (AsyncResult) msg.obj;
1639 request = (MainThreadRequest) ar.userObj;
1640 if (ar.exception != null) {
1641 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1642 } else {
1643 request.result = ((int[]) ar.result)[0];
1644 }
1645 notifyRequester(request);
1646 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001647 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1648 request = (MainThreadRequest) msg.obj;
1649 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1650 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001651 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1652 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001653 break;
1654 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1655 ar = (AsyncResult) msg.obj;
1656 request = (MainThreadRequest) ar.userObj;
1657 request.result = ar.exception == null;
1658 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001659 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001660 case CMD_GET_ALL_CELL_INFO:
1661 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001662 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001663 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001664 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001665 case EVENT_GET_ALL_CELL_INFO_DONE:
1666 ar = (AsyncResult) msg.obj;
1667 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001668 // If a timeout occurs, the response will be null
1669 request.result = (ar.exception == null && ar.result != null)
1670 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001671 synchronized (request) {
1672 request.notifyAll();
1673 }
1674 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001675 case CMD_REQUEST_CELL_INFO_UPDATE:
1676 request = (MainThreadRequest) msg.obj;
1677 request.phone.requestCellInfoUpdate(request.workSource,
1678 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1679 break;
1680 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1684 try {
1685 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001686 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001687 cb.onError(
1688 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1689 ar.exception.getClass().getName(),
1690 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001691 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001692 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001693 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001694 } else {
1695 // use the result as returned
1696 cb.onCellInfo((List<CellInfo>) ar.result);
1697 }
1698 } catch (RemoteException re) {
1699 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1700 }
1701 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001702 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001703 request = (MainThreadRequest) msg.obj;
1704 WorkSource ws = (WorkSource) request.argument;
1705 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001706 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001707 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001708 }
1709 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001710 ar = (AsyncResult) msg.obj;
1711 request = (MainThreadRequest) ar.userObj;
1712 if (ar.exception == null) {
1713 request.result = ar.result;
1714 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001715 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001716 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001717 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001718 }
1719
1720 synchronized (request) {
1721 request.notifyAll();
1722 }
1723 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001724 }
chen xu6dac5ab2018-10-26 17:39:23 -07001725 case CMD_MODEM_REBOOT:
1726 request = (MainThreadRequest) msg.obj;
1727 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001728 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001729 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001730 case EVENT_CMD_MODEM_REBOOT_DONE:
1731 handleNullReturnEvent(msg, "rebootModem");
1732 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001733 case CMD_REQUEST_ENABLE_MODEM:
1734 request = (MainThreadRequest) msg.obj;
1735 boolean enable = (boolean) request.argument;
1736 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001737 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001738 PhoneConfigurationManager.getInstance()
1739 .enablePhone(request.phone, enable, onCompleted);
1740 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001741 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001742 ar = (AsyncResult) msg.obj;
1743 request = (MainThreadRequest) ar.userObj;
1744 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001745 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001746 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001747 if ((boolean) request.result) {
1748 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1749 updateModemStateMetrics();
1750 } else {
1751 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1752 + ar.exception);
1753 }
1754 notifyRequester(request);
1755 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001756 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001757 case CMD_GET_MODEM_STATUS:
1758 request = (MainThreadRequest) msg.obj;
1759 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1760 PhoneConfigurationManager.getInstance()
1761 .getPhoneStatusFromModem(request.phone, onCompleted);
1762 break;
1763 case EVENT_GET_MODEM_STATUS_DONE:
1764 ar = (AsyncResult) msg.obj;
1765 request = (MainThreadRequest) ar.userObj;
1766 int id = request.phone.getPhoneId();
1767 if (ar.exception == null && ar.result != null) {
1768 request.result = ar.result;
1769 //update the cache as modem status has changed
1770 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1771 (boolean) request.result);
1772 } else {
1773 // Return true if modem status cannot be retrieved. For most cases,
1774 // modem status is on. And for older version modems, GET_MODEM_STATUS
1775 // and disable modem are not supported. Modem is always on.
1776 // TODO: this should be fixed in R to support a third
1777 // status UNKNOWN b/131631629
1778 request.result = true;
1779 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1780 + ar.exception);
1781 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001782 notifyRequester(request);
1783 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001784 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1785 request = (MainThreadRequest) msg.obj;
1786 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1787 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1788 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1789 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1790 break;
1791 }
1792 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1793 ar = (AsyncResult) msg.obj;
1794 request = (MainThreadRequest) ar.userObj;
1795 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1796 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1797 args.second.accept(ar.exception == null);
1798 notifyRequester(request);
1799 break;
1800 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001801 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1802 request = (MainThreadRequest) msg.obj;
1803 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1804 Phone phone = getPhoneFromRequest(request);
1805 if (phone != null) {
1806 phone.getSystemSelectionChannels(onCompleted);
1807 } else {
1808 loge("getSystemSelectionChannels: No phone object");
1809 request.result = new ArrayList<RadioAccessSpecifier>();
1810 notifyRequester(request);
1811 }
1812 break;
1813 }
1814 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1815 ar = (AsyncResult) msg.obj;
1816 request = (MainThreadRequest) ar.userObj;
1817 if (ar.exception == null && ar.result != null) {
1818 request.result = ar.result;
1819 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001820 request.result = new IllegalStateException(
1821 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001822 if (ar.result == null) {
1823 loge("getSystemSelectionChannels: Empty response");
1824 } else {
1825 loge("getSystemSelectionChannels: Unknown exception");
1826 }
1827 }
1828 notifyRequester(request);
1829 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001830 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1831 ar = (AsyncResult) msg.obj;
1832 request = (MainThreadRequest) ar.userObj;
1833 if (ar.exception == null && ar.result != null) {
1834 request.result = ar.result;
1835 } else {
1836 request.result = -1;
1837 loge("Failed to set Forbidden Plmns");
1838 if (ar.result == null) {
1839 loge("setForbidenPlmns: Empty response");
1840 } else if (ar.exception != null) {
1841 loge("setForbiddenPlmns: Exception: " + ar.exception);
1842 request.result = -1;
1843 } else {
1844 loge("setForbiddenPlmns: Unknown exception");
1845 }
1846 }
1847 notifyRequester(request);
1848 break;
1849 case CMD_SET_FORBIDDEN_PLMNS:
1850 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001851 uiccPort = getUiccPortFromRequest(request);
1852 if (uiccPort == null) {
1853 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001854 request.result = -1;
1855 notifyRequester(request);
1856 break;
1857 }
1858 Pair<Integer, List<String>> setFplmnsArgs =
1859 (Pair<Integer, List<String>>) request.argument;
1860 appType = setFplmnsArgs.first;
1861 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001862 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001863 if (uiccApp == null) {
1864 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1865 request.result = -1;
1866 loge("Failed to get UICC App");
1867 notifyRequester(request);
1868 } else {
1869 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1870 ((SIMRecords) uiccApp.getIccRecords())
1871 .setForbiddenPlmns(onCompleted, fplmns);
1872 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001873 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001874 case CMD_ERASE_MODEM_CONFIG:
1875 request = (MainThreadRequest) msg.obj;
1876 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1877 defaultPhone.eraseModemConfig(onCompleted);
1878 break;
1879 case EVENT_ERASE_MODEM_CONFIG_DONE:
1880 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001881 break;
zoey chene02881a2019-12-30 16:11:23 +08001882
Kai Shif70f46f2021-03-03 13:59:46 -08001883 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1884 request = (MainThreadRequest) msg.obj;
1885 request.result = defaultPhone.eraseDataInSharedPreferences();
1886 notifyRequester(request);
1887 break;
1888
zoey chene02881a2019-12-30 16:11:23 +08001889 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1890 request = (MainThreadRequest) msg.obj;
1891 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1892 Pair<String, String> changed = (Pair<String, String>) request.argument;
1893 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1894 changed.first, changed.second, onCompleted);
1895 break;
1896 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1897 ar = (AsyncResult) msg.obj;
1898 request = (MainThreadRequest) ar.userObj;
1899 if (ar.exception == null) {
1900 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001901 // If the operation is successful, update the PIN storage
1902 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1903 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001904 UiccController.getInstance().getPinStorage()
1905 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001906 } else {
1907 request.result = msg.arg1;
1908 }
1909 notifyRequester(request);
1910 break;
1911
Michele Berionne5e411512020-11-13 02:36:59 +00001912 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001913 request = (MainThreadRequest) msg.obj;
1914 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1915 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1916 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1917 enabled.first, enabled.second, onCompleted);
1918 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001919 }
zoey chene02881a2019-12-30 16:11:23 +08001920 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1921 ar = (AsyncResult) msg.obj;
1922 request = (MainThreadRequest) ar.userObj;
1923 if (ar.exception == null) {
1924 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001925 // If the operation is successful, update the PIN storage
1926 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1927 int phoneId = getPhoneFromRequest(request).getPhoneId();
1928 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001929 UiccController.getInstance().getPinStorage()
1930 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001931 } else {
1932 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1933 }
zoey chene02881a2019-12-30 16:11:23 +08001934 } else {
1935 request.result = msg.arg1;
1936 }
Michele Berionne5e411512020-11-13 02:36:59 +00001937
1938
zoey chene02881a2019-12-30 16:11:23 +08001939 notifyRequester(request);
1940 break;
1941
Peter Wangdafb9ac2020-01-15 14:13:38 -08001942 case MSG_NOTIFY_USER_ACTIVITY:
1943 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001944 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001945 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1946 getDefaultPhone().getContext().sendBroadcastAsUser(
1947 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1948 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001949
1950 case CMD_SET_DATA_THROTTLING: {
1951 request = (MainThreadRequest) msg.obj;
1952 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1953 DataThrottlingRequest dataThrottlingRequest =
1954 (DataThrottlingRequest) request.argument;
1955 Phone phone = getPhoneFromRequest(request);
1956 if (phone != null) {
1957 phone.setDataThrottling(onCompleted,
1958 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1959 dataThrottlingRequest.getCompletionDurationMillis());
1960 } else {
1961 loge("setDataThrottling: No phone object");
1962 request.result =
1963 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1964 notifyRequester(request);
1965 }
1966
1967 break;
1968 }
1969 case EVENT_SET_DATA_THROTTLING_DONE:
1970 ar = (AsyncResult) msg.obj;
1971 request = (MainThreadRequest) ar.userObj;
1972
1973 if (ar.exception == null) {
1974 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1975 } else if (ar.exception instanceof CommandException) {
1976 loge("setDataThrottling: CommandException: " + ar.exception);
1977 CommandException.Error error =
1978 ((CommandException) (ar.exception)).getCommandError();
1979
1980 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1981 request.result = TelephonyManager
1982 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1983 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1984 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001985 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1986 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001987 } else {
1988 request.result =
1989 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1990 }
1991 } else {
1992 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1993 }
1994 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1995 notifyRequester(request);
1996 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001997
1998 case CMD_SET_SIM_POWER: {
1999 request = (MainThreadRequest) msg.obj;
2000 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2001 request = (MainThreadRequest) msg.obj;
2002 int stateToSet =
2003 ((Pair<Integer, IIntegerConsumer>)
2004 request.argument).first;
2005 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2006 break;
2007 }
2008 case EVENT_SET_SIM_POWER_DONE: {
2009 ar = (AsyncResult) msg.obj;
2010 request = (MainThreadRequest) ar.userObj;
2011 IIntegerConsumer callback =
2012 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2013 if (ar.exception != null) {
2014 loge("setSimPower exception: " + ar.exception);
2015 int errorCode = TelephonyManager.CallForwardingInfoCallback
2016 .RESULT_ERROR_UNKNOWN;
2017 if (ar.exception instanceof CommandException) {
2018 CommandException.Error error =
2019 ((CommandException) (ar.exception)).getCommandError();
2020 if (error == CommandException.Error.SIM_ERR) {
2021 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2022 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2023 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2024 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2025 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2026 } else {
2027 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2028 }
2029 }
2030 try {
2031 callback.accept(errorCode);
2032 } catch (RemoteException e) {
2033 // Ignore if the remote process is no longer available to call back.
2034 Log.w(LOG_TAG, "setSimPower: callback not available.");
2035 }
2036 } else {
2037 try {
2038 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2039 } catch (RemoteException e) {
2040 // Ignore if the remote process is no longer available to call back.
2041 Log.w(LOG_TAG, "setSimPower: callback not available.");
2042 }
2043 }
2044 break;
2045 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002046 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2047 request = (MainThreadRequest) msg.obj;
2048
2049 final Phone phone = getPhoneFromRequest(request);
2050 if (phone == null || phone.getServiceStateTracker() == null) {
2051 request.result = new IllegalStateException("Phone or SST is null");
2052 notifyRequester(request);
2053 break;
2054 }
2055
2056 Pair<Integer, SignalStrengthUpdateRequest> pair =
2057 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2058 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2059 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002060 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002061 request.subId, pair.first /*callingUid*/,
2062 pair.second /*request*/, onCompleted);
2063 break;
2064 }
2065 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2066 ar = (AsyncResult) msg.obj;
2067 request = (MainThreadRequest) ar.userObj;
2068 // request.result will be the exception of ar if present, true otherwise.
2069 // Be cautious not to leave result null which will wait() forever
2070 request.result = ar.exception != null ? ar.exception : true;
2071 notifyRequester(request);
2072 break;
2073 }
2074 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2075 request = (MainThreadRequest) msg.obj;
2076
2077 Phone phone = getPhoneFromRequest(request);
2078 if (phone == null || phone.getServiceStateTracker() == null) {
2079 request.result = new IllegalStateException("Phone or SST is null");
2080 notifyRequester(request);
2081 break;
2082 }
2083
2084 Pair<Integer, SignalStrengthUpdateRequest> pair =
2085 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2086 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2087 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002088 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002089 request.subId, pair.first /*callingUid*/,
2090 pair.second /*request*/, onCompleted);
2091 break;
2092 }
2093 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2094 ar = (AsyncResult) msg.obj;
2095 request = (MainThreadRequest) ar.userObj;
2096 request.result = ar.exception != null ? ar.exception : true;
2097 notifyRequester(request);
2098 break;
2099 }
Jordan Liu109698e2020-11-24 14:50:34 -08002100
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002101 case CMD_GET_SLICING_CONFIG: {
2102 request = (MainThreadRequest) msg.obj;
2103 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2104 request.phone.getSlicingConfig(onCompleted);
2105 break;
2106 }
2107 case EVENT_GET_SLICING_CONFIG_DONE: {
2108 ar = (AsyncResult) msg.obj;
2109 request = (MainThreadRequest) ar.userObj;
2110 ResultReceiver result = (ResultReceiver) request.argument;
2111
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002112 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002113 Bundle bundle = new Bundle();
2114 int resultCode = 0;
2115 if (ar.exception != null) {
2116 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2117 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002118 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002119 } else if (ar.result == null) {
2120 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002121 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002122 } else {
2123 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002124 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2125 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002126 }
2127
2128 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002129 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002130 }
2131 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2132 result.send(resultCode, bundle);
2133 notifyRequester(request);
2134 break;
2135 }
2136
Michele Berionne5e411512020-11-13 02:36:59 +00002137 case CMD_PREPARE_UNATTENDED_REBOOT:
2138 request = (MainThreadRequest) msg.obj;
2139 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002140 UiccController.getInstance().getPinStorage()
2141 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002142 notifyRequester(request);
2143 break;
2144
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002145 default:
2146 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2147 break;
2148 }
2149 }
Jake Hambye994d462014-02-03 13:10:13 -08002150
Pengquan Menga1bb6272018-09-06 09:59:22 -07002151 private void notifyRequester(MainThreadRequest request) {
2152 synchronized (request) {
2153 request.notifyAll();
2154 }
2155 }
2156
Jake Hambye994d462014-02-03 13:10:13 -08002157 private void handleNullReturnEvent(Message msg, String command) {
2158 AsyncResult ar = (AsyncResult) msg.obj;
2159 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2160 if (ar.exception == null) {
2161 request.result = true;
2162 } else {
2163 request.result = false;
2164 if (ar.exception instanceof CommandException) {
2165 loge(command + ": CommandException: " + ar.exception);
2166 } else {
2167 loge(command + ": Unknown exception");
2168 }
2169 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002170 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 }
2173
2174 /**
2175 * Posts the specified command to be executed on the main thread,
2176 * waits for the request to complete, and returns the result.
2177 * @see #sendRequestAsync
2178 */
2179 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002180 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2181 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002182 }
2183
2184 /**
2185 * Posts the specified command to be executed on the main thread,
2186 * waits for the request to complete, and returns the result.
2187 * @see #sendRequestAsync
2188 */
2189 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2190 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002191 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002192 }
2193
2194 /**
2195 * Posts the specified command to be executed on the main thread,
2196 * waits for the request to complete, and returns the result.
2197 * @see #sendRequestAsync
2198 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002199 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002200 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2201 }
2202
2203 /**
2204 * Posts the specified command to be executed on the main thread,
2205 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2206 * if not timeout or null otherwise.
2207 * @see #sendRequestAsync
2208 */
2209 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2210 long timeoutInMs) {
2211 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002212 }
2213
2214 /**
2215 * Posts the specified command to be executed on the main thread,
2216 * waits for the request to complete, and returns the result.
2217 * @see #sendRequestAsync
2218 */
Nathan Harold92bed182018-10-12 18:16:49 -07002219 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002220 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002221 }
2222
2223 /**
2224 * Posts the specified command to be executed on the main thread,
2225 * waits for the request to complete, and returns the result.
2226 * @see #sendRequestAsync
2227 */
2228 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002229 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2230 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002231 }
2232
2233 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002234 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2235 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2236 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002237 * @see #sendRequestAsync
2238 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002239 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2240 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2242 throw new RuntimeException("This method will deadlock if called from the main thread.");
2243 }
2244
Nathan Harold92bed182018-10-12 18:16:49 -07002245 MainThreadRequest request = null;
2246 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2247 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2248 } else if (phone != null) {
2249 request = new MainThreadRequest(argument, phone, workSource);
2250 } else {
2251 request = new MainThreadRequest(argument, subId, workSource);
2252 }
2253
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 Message msg = mMainThreadHandler.obtainMessage(command, request);
2255 msg.sendToTarget();
2256
Rambo Wang0f050d82021-02-12 11:43:36 -08002257
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002259 if (timeoutInMs >= 0) {
2260 // Wait for at least timeoutInMs before returning null request result
2261 long now = SystemClock.elapsedRealtime();
2262 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002263 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002264 try {
2265 request.wait(deadline - now);
2266 } catch (InterruptedException e) {
2267 // Do nothing, go back and check if request is completed or timeout
2268 } finally {
2269 now = SystemClock.elapsedRealtime();
2270 }
2271 }
2272 } else {
2273 // Wait for the request to complete
2274 while (request.result == null) {
2275 try {
2276 request.wait();
2277 } catch (InterruptedException e) {
2278 // Do nothing, go back and wait until the request is complete
2279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 }
2281 }
2282 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002283 if (request.result == null) {
2284 Log.wtf(LOG_TAG,
2285 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 return request.result;
2288 }
2289
2290 /**
2291 * Asynchronous ("fire and forget") version of sendRequest():
2292 * Posts the specified command to be executed on the main thread, and
2293 * returns immediately.
2294 * @see #sendRequest
2295 */
2296 private void sendRequestAsync(int command) {
2297 mMainThreadHandler.sendEmptyMessage(command);
2298 }
2299
2300 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002301 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002302 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002303 */
2304 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002305 sendRequestAsync(command, argument, null, null);
2306 }
2307
2308 /**
2309 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2310 * @see {@link #sendRequest(int,Object)}
2311 */
2312 private void sendRequestAsync(
2313 int command, Object argument, Phone phone, WorkSource workSource) {
2314 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002315 Message msg = mMainThreadHandler.obtainMessage(command, request);
2316 msg.sendToTarget();
2317 }
2318
2319 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 * Initialize the singleton PhoneInterfaceManager instance.
2321 * This is only done once, at startup, from PhoneApp.onCreate().
2322 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002323 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 synchronized (PhoneInterfaceManager.class) {
2325 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002326 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 } else {
2328 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2329 }
2330 return sInstance;
2331 }
2332 }
2333
2334 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002335 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002338 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002339 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002341 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002343 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002344 mTelephonySharedPreferences =
2345 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002346 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002347 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002348 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002349 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002350 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002351 mTelephony2gUpdater = new Telephony2gUpdater(
2352 Executors.newSingleThreadExecutor(), mApp);
2353 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 publish();
2355 }
2356
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002357 private Phone getDefaultPhone() {
2358 Phone thePhone = getPhone(getDefaultSubscription());
2359 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2360 }
2361
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 private void publish() {
2363 if (DBG) log("publish: " + this);
2364
Peter Wangc035ce42020-01-08 21:00:22 -08002365 TelephonyFrameworkInitializer
2366 .getTelephonyServiceManager()
2367 .getTelephonyServiceRegisterer()
2368 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369 }
2370
Stuart Scott584921c2015-01-15 17:10:34 -08002371 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002372 if (request.phone != null) {
2373 return request.phone;
2374 } else {
2375 return getPhoneFromSubId(request.subId);
2376 }
2377 }
2378
2379 private Phone getPhoneFromSubId(int subId) {
2380 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2381 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002382 }
2383
Rambo Wange53e07d2022-05-10 13:01:13 -07002384 @Nullable
2385 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002386 Phone phone = getPhoneFromRequest(request);
2387 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002388 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002389 }
2390
Wink Saville36469e72014-06-11 15:17:00 -07002391 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002392 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002393 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395
Kai Shif70f46f2021-03-03 13:59:46 -08002396 private void sendEraseModemConfig(@NonNull Phone phone) {
2397 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2398 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2399 }
2400
2401 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2402 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2403 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002404 }
2405
Peter Wang44b186e2020-01-13 23:33:09 -08002406 private boolean isImsAvailableOnDevice() {
2407 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2408 if (pm == null) {
2409 // For some reason package manger is not available.. This will fail internally anyway,
2410 // so do not throw error and allow.
2411 return true;
2412 }
2413 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2414 }
2415
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002417 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002418 }
2419
Wink Savilleb564aae2014-10-23 10:18:09 -07002420 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 if (DBG) log("dial: " + number);
2422 // No permission check needed here: This is just a wrapper around the
2423 // ACTION_DIAL intent, which is available to any app since it puts up
2424 // the UI before it does anything.
2425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426 final long identity = Binder.clearCallingIdentity();
2427 try {
2428 String url = createTelUrl(number);
2429 if (url == null) {
2430 return;
2431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002433 // PENDING: should we just silently fail if phone is offhook or ringing?
2434 PhoneConstants.State state = mCM.getState(subId);
2435 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2436 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2437 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2438 mApp.startActivity(intent);
2439 }
2440 } finally {
2441 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 }
2443 }
2444
2445 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002446 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002447 }
2448
Wink Savilleb564aae2014-10-23 10:18:09 -07002449 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 if (DBG) log("call: " + number);
2451
2452 // This is just a wrapper around the ACTION_CALL intent, but we still
2453 // need to do a permission check since we're calling startActivity()
2454 // from the context of the phone app.
2455 enforceCallPermission();
2456
Jordan Liu1617b712019-07-10 15:06:26 -07002457 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 != AppOpsManager.MODE_ALLOWED) {
2459 return;
2460 }
2461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002462 final long identity = Binder.clearCallingIdentity();
2463 try {
2464 String url = createTelUrl(number);
2465 if (url == null) {
2466 return;
2467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469 boolean isValid = false;
2470 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2471 if (slist != null) {
2472 for (SubscriptionInfo subInfoRecord : slist) {
2473 if (subInfoRecord.getSubscriptionId() == subId) {
2474 isValid = true;
2475 break;
2476 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002477 }
Wink Saville08874612014-08-31 19:19:58 -07002478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002479 if (!isValid) {
2480 return;
2481 }
Wink Saville08874612014-08-31 19:19:58 -07002482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2484 intent.putExtra(SUBSCRIPTION_KEY, subId);
2485 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2486 mApp.startActivity(intent);
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
2489 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 }
2491
Wink Savilleb564aae2014-10-23 10:18:09 -07002492 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002493 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002494 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2495 }
2496
Wink Savilleb564aae2014-10-23 10:18:09 -07002497 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002498 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002499 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2500 }
2501
Wink Savilleb564aae2014-10-23 10:18:09 -07002502 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002503 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504
2505 final long identity = Binder.clearCallingIdentity();
2506 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002507 Phone phone = getPhone(subId);
2508 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509 checkSimPin.start();
2510 return checkSimPin.unlockSim(null, pin);
2511 } finally {
2512 Binder.restoreCallingIdentity(identity);
2513 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002514 }
2515
Wink Savilleb564aae2014-10-23 10:18:09 -07002516 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002518
2519 final long identity = Binder.clearCallingIdentity();
2520 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002521 Phone phone = getPhone(subId);
2522 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523 checkSimPuk.start();
2524 return checkSimPuk.unlockSim(puk, pin);
2525 } finally {
2526 Binder.restoreCallingIdentity(identity);
2527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 }
2529
2530 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002531 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532 * a synchronous one.
2533 */
2534 private static class UnlockSim extends Thread {
2535
2536 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002537 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538
2539 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002540 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2541 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542
2543 // For replies from SimCard interface
2544 private Handler mHandler;
2545
2546 // For async handler to identify request type
2547 private static final int SUPPLY_PIN_COMPLETE = 100;
2548
Michele Berionne5e411512020-11-13 02:36:59 +00002549 UnlockSim(int phoneId, IccCard simCard) {
2550 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 mSimCard = simCard;
2552 }
2553
2554 @Override
2555 public void run() {
2556 Looper.prepare();
2557 synchronized (UnlockSim.this) {
2558 mHandler = new Handler() {
2559 @Override
2560 public void handleMessage(Message msg) {
2561 AsyncResult ar = (AsyncResult) msg.obj;
2562 switch (msg.what) {
2563 case SUPPLY_PIN_COMPLETE:
2564 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2565 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002566 mRetryCount = msg.arg1;
2567 if (ar.exception != null) {
2568 if (ar.exception instanceof CommandException &&
2569 ((CommandException)(ar.exception)).getCommandError()
2570 == CommandException.Error.PASSWORD_INCORRECT) {
2571 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002572 } //When UiccCardApp dispose,handle message and return exception
2573 else if (ar.exception instanceof CommandException &&
2574 ((CommandException) (ar.exception)).getCommandError()
2575 == CommandException.Error.ABORTED) {
2576 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002577 } else {
2578 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2579 }
2580 } else {
2581 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 mDone = true;
2584 UnlockSim.this.notifyAll();
2585 }
2586 break;
2587 }
2588 }
2589 };
2590 UnlockSim.this.notifyAll();
2591 }
2592 Looper.loop();
2593 }
2594
2595 /*
2596 * Use PIN or PUK to unlock SIM card
2597 *
2598 * If PUK is null, unlock SIM card with PIN
2599 *
2600 * If PUK is not null, unlock SIM card with PUK and set PIN code
2601 */
Wink Saville9de0f752013-10-22 19:04:03 -07002602 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603
2604 while (mHandler == null) {
2605 try {
2606 wait();
2607 } catch (InterruptedException e) {
2608 Thread.currentThread().interrupt();
2609 }
2610 }
2611 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2612
2613 if (puk == null) {
2614 mSimCard.supplyPin(pin, callback);
2615 } else {
2616 mSimCard.supplyPuk(puk, pin, callback);
2617 }
2618
2619 while (!mDone) {
2620 try {
2621 Log.d(LOG_TAG, "wait for done");
2622 wait();
2623 } catch (InterruptedException e) {
2624 // Restore the interrupted status
2625 Thread.currentThread().interrupt();
2626 }
2627 }
2628 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002629 int[] resultArray = new int[2];
2630 resultArray[0] = mResult;
2631 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002632
2633 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002634 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002635 }
2636
Wink Saville9de0f752013-10-22 19:04:03 -07002637 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002638 }
2639 }
2640
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002641 /**
2642 * This method has been removed due to privacy and stability concerns.
2643 */
2644 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002646 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2647 return;
Wink Saville36469e72014-06-11 15:17:00 -07002648 }
2649
Nathan Harold1f889d82020-06-04 17:05:26 -07002650 @Override
2651 public void updateServiceLocationWithPackageName(String callingPackage) {
2652 mApp.getSystemService(AppOpsManager.class)
2653 .checkPackage(Binder.getCallingUid(), callingPackage);
2654
Nathan Haroldf096d982020-11-18 17:18:06 -08002655 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002656 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2657 // Callers targeting S have no business invoking this method.
2658 return;
2659 }
2660
2661 LocationAccessPolicy.LocationPermissionResult locationResult =
2662 LocationAccessPolicy.checkLocationPermission(mApp,
2663 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2664 .setCallingPackage(callingPackage)
2665 .setCallingFeatureId(null)
2666 .setCallingPid(Binder.getCallingPid())
2667 .setCallingUid(Binder.getCallingUid())
2668 .setMethod("updateServiceLocation")
2669 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2670 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2671 .build());
2672 // Apps that lack location permission have no business calling this method;
2673 // however, because no permission was declared in the public API, denials must
2674 // all be "soft".
2675 switch (locationResult) {
2676 case DENIED_HARD: /* fall through */
2677 case DENIED_SOFT:
2678 return;
2679 }
2680
2681 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682 final long identity = Binder.clearCallingIdentity();
2683 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002684 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002686 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 }
2688 } finally {
2689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 }
2692
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002693 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002694 @Override
2695 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002696 return isRadioOnWithFeature(callingPackage, null);
2697 }
2698
2699
2700 @Override
2701 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2702 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2703 callingFeatureId);
2704 }
2705
2706 @Deprecated
2707 @Override
2708 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2709 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002710 }
2711
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002712 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002713 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2714 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002716 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002717 return false;
2718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719
2720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 return isRadioOnForSubscriber(subId);
2723 } finally {
2724 Binder.restoreCallingIdentity(identity);
2725 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002726 }
2727
2728 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729 final long identity = Binder.clearCallingIdentity();
2730 try {
2731 final Phone phone = getPhone(subId);
2732 if (phone != null) {
2733 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2734 } else {
2735 return false;
2736 }
2737 } finally {
2738 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740 }
2741
2742 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002743 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 }
Wink Saville36469e72014-06-11 15:17:00 -07002745
Wink Savilleb564aae2014-10-23 10:18:09 -07002746 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002748
2749 final long identity = Binder.clearCallingIdentity();
2750 try {
2751 final Phone phone = getPhone(subId);
2752 if (phone != null) {
2753 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2754 }
2755 } finally {
2756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002757 }
Wink Saville36469e72014-06-11 15:17:00 -07002758 }
2759
2760 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002761 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002762 }
2763
Wink Savilleb564aae2014-10-23 10:18:09 -07002764 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002765 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766
2767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 final Phone phone = getPhone(subId);
2770 if (phone == null) {
2771 return false;
2772 }
2773 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2774 toggleRadioOnOffForSubscriber(subId);
2775 }
2776 return true;
2777 } finally {
2778 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 }
Wink Saville36469e72014-06-11 15:17:00 -07002781
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002782 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002783 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002784 /*
2785 * If any of the Radios are available, it will need to be
2786 * shutdown. So return true if any Radio is available.
2787 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2791 Phone phone = PhoneFactory.getPhone(i);
2792 if (phone != null && phone.isRadioAvailable()) return true;
2793 }
2794 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2795 return false;
2796 } finally {
2797 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002798 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002799 }
2800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002802 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803 enforceModifyPermission();
2804
2805 final long identity = Binder.clearCallingIdentity();
2806 try {
2807 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2808 logv("Shutting down Phone " + i);
2809 shutdownRadioUsingPhoneId(i);
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002813 }
2814 }
2815
2816 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002817 Phone phone = PhoneFactory.getPhone(phoneId);
2818 if (phone != null && phone.isRadioAvailable()) {
2819 phone.shutdownRadio();
2820 }
2821 }
2822
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002823 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002824 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825
2826 final long identity = Binder.clearCallingIdentity();
2827 try {
2828 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2829 if (defaultPhone != null) {
2830 defaultPhone.setRadioPower(turnOn);
2831 return true;
2832 } else {
2833 loge("There's no default phone.");
2834 return false;
2835 }
2836 } finally {
2837 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002838 }
Wink Saville36469e72014-06-11 15:17:00 -07002839 }
2840
Wink Savilleb564aae2014-10-23 10:18:09 -07002841 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002842 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002843
2844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 final Phone phone = getPhone(subId);
2847 if (phone != null) {
2848 phone.setRadioPower(turnOn);
2849 return true;
2850 } else {
2851 return false;
2852 }
2853 } finally {
2854 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002855 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002856 }
2857
Wink Saville36469e72014-06-11 15:17:00 -07002858 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002860 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862
2863 final long identity = Binder.clearCallingIdentity();
2864 try {
2865 int subId = mSubscriptionController.getDefaultDataSubId();
2866 final Phone phone = getPhone(subId);
2867 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002868 if (phone.isUsingNewDataStack()) {
2869 phone.getDataSettingsManager().setDataEnabled(
Sarah Chinecc78c42022-03-31 21:16:48 -07002870 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08002871 } else {
2872 phone.getDataEnabledSettings().setDataEnabled(
2873 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2874 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875 return true;
2876 } else {
2877 return false;
2878 }
2879 } finally {
2880 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882 }
2883
Wink Saville36469e72014-06-11 15:17:00 -07002884 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002885 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002886 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002888
2889 final long identity = Binder.clearCallingIdentity();
2890 try {
2891 int subId = mSubscriptionController.getDefaultDataSubId();
2892 final Phone phone = getPhone(subId);
2893 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002894 if (phone.isUsingNewDataStack()) {
2895 phone.getDataSettingsManager().setDataEnabled(
Sarah Chinecc78c42022-03-31 21:16:48 -07002896 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08002897 } else {
2898 phone.getDataEnabledSettings().setDataEnabled(
2899 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 return true;
2902 } else {
2903 return false;
2904 }
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002908 }
2909
Sanket Padawe356d7632015-06-22 14:03:32 -07002910 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002911 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002912 final long identity = Binder.clearCallingIdentity();
2913 try {
2914 final Phone phone = getPhone(subId);
2915 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002916 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 } else {
2918 return false;
2919 }
2920 } finally {
2921 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002923 }
2924
2925 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002926 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002927 }
2928
pkanwarae03a6b2016-11-06 20:37:09 -08002929 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930 enforceCallPermission();
2931
2932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2935 return;
2936 }
2937 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2938 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
2941 }
pkanwar32d516d2016-10-14 19:37:38 -07002942 };
2943
Wink Savilleb564aae2014-10-23 10:18:09 -07002944 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946
2947 final long identity = Binder.clearCallingIdentity();
2948 try {
2949 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2950 return false;
2951 }
2952 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002956 }
2957
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002958 /**
2959 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2960 * tag on getCallState Binder call.
2961 */
2962 @Deprecated
2963 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002964 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002965 if (CompatChanges.isChangeEnabled(
2966 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2967 Binder.getCallingUid())) {
2968 // Do not allow this API to be called on API version 31+, it should only be
2969 // called on old apps using this Binder call directly.
2970 throw new SecurityException("This method can only be used for applications "
2971 + "targeting API version 30 or less.");
2972 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002973 final long identity = Binder.clearCallingIdentity();
2974 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002975 Phone phone = getPhone(getDefaultSubscription());
2976 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2977 PhoneConstantConversions.convertCallState(phone.getState());
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 }
2982
2983 @Override
2984 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2985 if (CompatChanges.isChangeEnabled(
2986 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2987 Binder.getCallingUid())) {
2988 // Check READ_PHONE_STATE for API version 31+
2989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2990 featureId, "getCallStateForSubscription")) {
2991 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2992 + "targeting API level 31+.");
2993 }
2994 }
2995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2999 PhoneConstantConversions.convertCallState(phone.getState());
3000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003003 }
3004
Sanket Padawe356d7632015-06-22 14:03:32 -07003005 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003006 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003007 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3008 }
3009
3010 @Override
3011 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003012 final long identity = Binder.clearCallingIdentity();
3013 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003014 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08003016 if (phone.isUsingNewDataStack()) {
3017 return phone.getDataNetworkController().getInternetDataNetworkState();
3018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3020 } else {
3021 return PhoneConstantConversions.convertDataState(
3022 PhoneConstants.DataState.DISCONNECTED);
3023 }
3024 } finally {
3025 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003026 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003027 }
3028
Sanket Padawe356d7632015-06-22 14:03:32 -07003029 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003030 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003031 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3032 }
3033
3034 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003035 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003036 final long identity = Binder.clearCallingIdentity();
3037 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003038 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003039 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003040 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 } else {
3042 return TelephonyManager.DATA_ACTIVITY_NONE;
3043 }
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003046 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003047 }
3048
3049 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003050 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003051 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003052 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003053
3054 LocationAccessPolicy.LocationPermissionResult locationResult =
3055 LocationAccessPolicy.checkLocationPermission(mApp,
3056 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3057 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003058 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003059 .setCallingPid(Binder.getCallingPid())
3060 .setCallingUid(Binder.getCallingUid())
3061 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003062 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003063 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3064 .build());
3065 switch (locationResult) {
3066 case DENIED_HARD:
3067 throw new SecurityException("Not allowed to access cell location");
3068 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003069 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3070 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003071 }
3072
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003073 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003077 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003078 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003079 } finally {
3080 Binder.restoreCallingIdentity(identity);
3081 }
Svetoslav64fad262015-04-14 14:35:21 -07003082 }
3083
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003084 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003085 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003086 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3087 // registered cell info, so return a NULL country instead.
3088 final long identity = Binder.clearCallingIdentity();
3089 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003090 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3091 // Get default phone in this case.
3092 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3093 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003094 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003095 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003096 if (phone == null) return "";
3097 ServiceStateTracker sst = phone.getServiceStateTracker();
3098 if (sst == null) return "";
3099 LocaleTracker lt = sst.getLocaleTracker();
3100 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003101 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003105 }
3106
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003107 /**
3108 * This method was removed due to potential issues caused by performing partial
3109 * updates of service state, and lack of a credible use case.
3110 *
3111 * This has the ability to break the telephony implementation by disabling notification of
3112 * changes in device connectivity. DO NOT USE THIS!
3113 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003114 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003115 public void enableLocationUpdates() {
3116 mApp.enforceCallingOrSelfPermission(
3117 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003118 }
3119
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003120 /**
3121 * This method was removed due to potential issues caused by performing partial
3122 * updates of service state, and lack of a credible use case.
3123 *
3124 * This has the ability to break the telephony implementation by disabling notification of
3125 * changes in device connectivity. DO NOT USE THIS!
3126 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003127 @Override
3128 public void disableLocationUpdates() {
3129 mApp.enforceCallingOrSelfPermission(
3130 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003131 }
3132
3133 @Override
3134 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003135 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3136 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003137 try {
3138 mApp.getSystemService(AppOpsManager.class)
3139 .checkPackage(Binder.getCallingUid(), callingPackage);
3140 } catch (SecurityException e) {
3141 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3142 throw e;
3143 }
3144
Nathan Haroldf096d982020-11-18 17:18:06 -08003145 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003146 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3147 throw new SecurityException(
3148 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3149 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003150
Jordan Liu1617b712019-07-10 15:06:26 -07003151 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003152 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3153 return null;
3154 }
Svetoslav64fad262015-04-14 14:35:21 -07003155
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003156 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003158 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003159 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003160
Nathan Haroldf180aac2018-06-01 18:43:55 -07003161 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3162 for (CellInfo ci : info) {
3163 if (ci instanceof CellInfoGsm) {
3164 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3165 } else if (ci instanceof CellInfoWcdma) {
3166 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003168 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003169 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170 }
3171
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003172 private List<CellInfo> getCachedCellInfo() {
3173 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3174 for (Phone phone : PhoneFactory.getPhones()) {
3175 List<CellInfo> info = phone.getAllCellInfo();
3176 if (info != null) cellInfos.addAll(info);
3177 }
3178 return cellInfos;
3179 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003180
3181 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003182 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003183 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003184 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003185
3186 LocationAccessPolicy.LocationPermissionResult locationResult =
3187 LocationAccessPolicy.checkLocationPermission(mApp,
3188 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3189 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003190 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003191 .setCallingPid(Binder.getCallingPid())
3192 .setCallingUid(Binder.getCallingUid())
3193 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003194 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003195 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3196 .build());
3197 switch (locationResult) {
3198 case DENIED_HARD:
3199 throw new SecurityException("Not allowed to access cell info");
3200 case DENIED_SOFT:
3201 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003202 }
3203
Nathan Haroldf096d982020-11-18 17:18:06 -08003204 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003205 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3206 return getCachedCellInfo();
3207 }
3208
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003209 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003210 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3214 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003215 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003216 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217 if (info != null) cellInfos.addAll(info);
3218 }
3219 return cellInfos;
3220 } finally {
3221 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003222 }
3223 }
3224
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003225 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003226 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3227 String callingFeatureId) {
3228 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3229 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003230 }
3231
3232 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003233 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3234 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003235 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003236 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003237 }
3238
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003239 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3240 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003241 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003242 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003243
3244 LocationAccessPolicy.LocationPermissionResult locationResult =
3245 LocationAccessPolicy.checkLocationPermission(mApp,
3246 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3247 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003248 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003249 .setCallingPid(Binder.getCallingPid())
3250 .setCallingUid(Binder.getCallingUid())
3251 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003252 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3253 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003254 .build());
3255 switch (locationResult) {
3256 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003257 if (TelephonyPermissions
3258 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003259 // Safetynet logging for b/154934934
3260 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3261 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003262 throw new SecurityException("Not allowed to access cell info");
3263 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003264 if (TelephonyPermissions
3265 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003266 // Safetynet logging for b/154934934
3267 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3268 }
Nathan Harold5320c422019-05-09 10:26:08 -07003269 try {
3270 cb.onCellInfo(new ArrayList<CellInfo>());
3271 } catch (RemoteException re) {
3272 // Drop without consequences
3273 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003274 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003275 }
3276
Nathan Harolda939a962019-05-09 10:13:47 -07003277
3278 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003279 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3280
3281 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3282 }
3283
3284 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003285 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003286 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003287 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003288
3289 final long identity = Binder.clearCallingIdentity();
3290 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003291 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292 } finally {
3293 Binder.restoreCallingIdentity(identity);
3294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003295 }
3296
Shishir Agrawala9f32182016-04-12 12:00:16 -07003297 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003298 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003299 Phone phone = PhoneFactory.getPhone(slotIndex);
3300 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003301 return null;
3302 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003303 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003304 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003305 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003306 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003307 return null;
3308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309
3310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 return phone.getImei();
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003316 }
3317
3318 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003319 public String getTypeAllocationCodeForSlot(int slotIndex) {
3320 Phone phone = PhoneFactory.getPhone(slotIndex);
3321 String tac = null;
3322 if (phone != null) {
3323 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003324 try {
3325 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3326 } catch (IndexOutOfBoundsException e) {
3327 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3328 return null;
3329 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003330 }
3331 return tac;
3332 }
3333
3334 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003335 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003336 try {
3337 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3338 } catch (SecurityException se) {
3339 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3340 throw new SecurityException("Package " + callingPackage + " does not belong to "
3341 + Binder.getCallingUid());
3342 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003343 Phone phone = PhoneFactory.getPhone(slotIndex);
3344 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003345 return null;
3346 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003347
Jeff Davidson913390f2018-02-23 17:11:49 -08003348 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003349 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003350 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003351 return null;
3352 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353
3354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 return phone.getMeid();
3357 } finally {
3358 Binder.restoreCallingIdentity(identity);
3359 }
Jack Yu2af8d712017-03-15 17:14:14 -07003360 }
3361
3362 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003363 public String getManufacturerCodeForSlot(int slotIndex) {
3364 Phone phone = PhoneFactory.getPhone(slotIndex);
3365 String manufacturerCode = null;
3366 if (phone != null) {
3367 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003368 try {
3369 manufacturerCode =
3370 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3371 } catch (IndexOutOfBoundsException e) {
3372 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3373 return null;
3374 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003375 }
3376 return manufacturerCode;
3377 }
3378
3379 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003380 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3381 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003382 Phone phone = PhoneFactory.getPhone(slotIndex);
3383 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003384 return null;
3385 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003386 int subId = phone.getSubId();
3387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003388 mApp, subId, callingPackage, callingFeatureId,
3389 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003390 return null;
3391 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003392
3393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 return phone.getDeviceSvn();
3396 } finally {
3397 Binder.restoreCallingIdentity(identity);
3398 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003399 }
3400
fionaxu43304da2017-11-27 22:51:16 -08003401 @Override
3402 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 final Phone phone = getPhone(subId);
3406 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3407 } finally {
3408 Binder.restoreCallingIdentity(identity);
3409 }
fionaxu43304da2017-11-27 22:51:16 -08003410 }
3411
3412 @Override
3413 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003414 final long identity = Binder.clearCallingIdentity();
3415 try {
3416 final Phone phone = getPhone(subId);
3417 return phone == null ? null : phone.getCarrierName();
3418 } finally {
3419 Binder.restoreCallingIdentity(identity);
3420 }
fionaxu43304da2017-11-27 22:51:16 -08003421 }
3422
calvinpanffe225e2018-11-01 19:43:06 +08003423 @Override
chen xu0026ca62019-03-06 15:28:50 -08003424 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003425 final long identity = Binder.clearCallingIdentity();
3426 try {
3427 final Phone phone = getPhone(subId);
3428 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003429 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
3433 }
3434
3435 @Override
chen xu0026ca62019-03-06 15:28:50 -08003436 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003440 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003441 } finally {
3442 Binder.restoreCallingIdentity(identity);
3443 }
3444 }
3445
chen xu651eec72018-11-11 19:03:44 -08003446 @Override
chen xu864e11c2018-12-06 22:10:03 -08003447 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3448 if (!isSubscriptionMccMnc) {
3449 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3450 }
chen xu651eec72018-11-11 19:03:44 -08003451 final Phone phone = PhoneFactory.getPhone(slotIndex);
3452 if (phone == null) {
3453 return TelephonyManager.UNKNOWN_CARRIER_ID;
3454 }
3455 final long identity = Binder.clearCallingIdentity();
3456 try {
3457 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3458 } finally {
3459 Binder.restoreCallingIdentity(identity);
3460 }
3461 }
3462
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 //
3464 // Internal helper methods.
3465 //
3466
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003467 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003468 * Make sure the caller is the calling package itself
3469 *
3470 * @throws SecurityException if the caller is not the calling package
3471 */
3472 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3473 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003474 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3475 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003476 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003477 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003478 } catch (PackageManager.NameNotFoundException e) {
3479 // packageUid is -1
3480 }
3481 if (packageUid != callingUid) {
3482 throw new SecurityException(message + ": Package " + callingPackage
3483 + " does not belong to " + callingUid);
3484 }
3485 }
3486
3487 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003488 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3489 *
3490 * @throws SecurityException if the caller does not have the required permission
3491 */
3492 private void enforceModifyPermission() {
3493 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3494 }
3495
Shuo Qian3b6ee772019-11-13 17:43:31 -08003496 private void enforceActiveEmergencySessionPermission() {
3497 mApp.enforceCallingOrSelfPermission(
3498 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3499 }
3500
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003501 /**
3502 * Make sure the caller has the CALL_PHONE permission.
3503 *
3504 * @throws SecurityException if the caller does not have the required permission
3505 */
3506 private void enforceCallPermission() {
3507 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3508 }
3509
paulhu5a773602019-08-23 19:17:33 +08003510 private void enforceSettingsPermission() {
3511 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003512 }
3513
Michele Berionne5e411512020-11-13 02:36:59 +00003514 private void enforceRebootPermission() {
3515 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3516 }
3517
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003518 private String createTelUrl(String number) {
3519 if (TextUtils.isEmpty(number)) {
3520 return null;
3521 }
3522
Jake Hambye994d462014-02-03 13:10:13 -08003523 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524 }
3525
Ihab Awadf9e92732013-12-05 18:02:52 -08003526 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003527 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3528 }
3529
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003530 private static void logv(String msg) {
3531 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3532 }
3533
Ihab Awadf9e92732013-12-05 18:02:52 -08003534 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003535 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3536 }
3537
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003538 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003539 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003540 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003541 }
3542
Sanket Padawe356d7632015-06-22 14:03:32 -07003543 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003544 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 final Phone phone = PhoneFactory.getPhone(slotIndex);
3548 if (phone == null) {
3549 return PhoneConstants.PHONE_TYPE_NONE;
3550 } else {
3551 return phone.getPhoneType();
3552 }
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003556 }
3557
3558 /**
3559 * Returns the CDMA ERI icon index to display
3560 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003562 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3563 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3564 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003565 }
3566
Sanket Padawe356d7632015-06-22 14:03:32 -07003567 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003568 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3569 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003570 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003571 mApp, subId, callingPackage, callingFeatureId,
3572 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003573 return -1;
3574 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575
3576 final long identity = Binder.clearCallingIdentity();
3577 try {
3578 final Phone phone = getPhone(subId);
3579 if (phone != null) {
3580 return phone.getCdmaEriIconIndex();
3581 } else {
3582 return -1;
3583 }
3584 } finally {
3585 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003587 }
3588
3589 /**
3590 * Returns the CDMA ERI icon mode,
3591 * 0 - ON
3592 * 1 - FLASHING
3593 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003594 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003595 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3596 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3597 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003598 }
3599
Sanket Padawe356d7632015-06-22 14:03:32 -07003600 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003601 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3602 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003604 mApp, subId, callingPackage, callingFeatureId,
3605 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003606 return -1;
3607 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003608
3609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 final Phone phone = getPhone(subId);
3612 if (phone != null) {
3613 return phone.getCdmaEriIconMode();
3614 } else {
3615 return -1;
3616 }
3617 } finally {
3618 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003620 }
3621
3622 /**
3623 * Returns the CDMA ERI text,
3624 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003625 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003626 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3627 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3628 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003629 }
3630
Sanket Padawe356d7632015-06-22 14:03:32 -07003631 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003632 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3633 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003635 mApp, subId, callingPackage, callingFeatureId,
3636 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003637 return null;
3638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003639
3640 final long identity = Binder.clearCallingIdentity();
3641 try {
3642 final Phone phone = getPhone(subId);
3643 if (phone != null) {
3644 return phone.getCdmaEriText();
3645 } else {
3646 return null;
3647 }
3648 } finally {
3649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003651 }
3652
3653 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003654 * Returns the CDMA MDN.
3655 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003656 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003657 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3659 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660
3661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003664 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665 return phone.getLine1Number();
3666 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003667 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668 return null;
3669 }
3670 } finally {
3671 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003672 }
3673 }
3674
3675 /**
3676 * Returns the CDMA MIN.
3677 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003678 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003679 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3681 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003682
3683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 final Phone phone = getPhone(subId);
3686 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3687 return phone.getCdmaMin();
3688 } else {
3689 return null;
3690 }
3691 } finally {
3692 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003693 }
3694 }
3695
Hall Liud892bec2018-11-30 14:51:45 -08003696 @Override
3697 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3698 INumberVerificationCallback callback, String callingPackage) {
3699 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3700 != PERMISSION_GRANTED) {
3701 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3702 }
3703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3704
3705 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3706 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003707 throw new SecurityException("Calling package must be configured in the device config: "
3708 + "calling package: " + callingPackage
3709 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003710 }
3711
3712 if (range == null) {
3713 throw new NullPointerException("Range must be non-null");
3714 }
3715
3716 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003717 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003718
3719 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3720 }
3721
Junda Liuca05d5d2014-08-14 22:36:34 -07003722 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003723 * Returns true if CDMA provisioning needs to run.
3724 */
3725 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003726 final long identity = Binder.clearCallingIdentity();
3727 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003728 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003732 }
3733
3734 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003735 * Sets the voice mail number of a given subId.
3736 */
3737 @Override
3738 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003739 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3740 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741
3742 final long identity = Binder.clearCallingIdentity();
3743 try {
3744 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3745 new Pair<String, String>(alphaTag, number), new Integer(subId));
3746 return success;
3747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003750 }
3751
Ta-wei Yen87c49842016-05-13 21:19:52 -07003752 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003753 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3754 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003755 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3756 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003757 if (!TextUtils.equals(callingPackage, systemDialer)) {
3758 throw new SecurityException("caller must be system dialer");
3759 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003760
3761 final long identity = Binder.clearCallingIdentity();
3762 try {
3763 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3764 if (phoneAccountHandle == null) {
3765 return null;
3766 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003767 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768 } finally {
3769 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003770 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003771 }
3772
3773 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003774 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3775 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003776 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003777 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003778 mApp, subId, callingPackage, callingFeatureId,
3779 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003780 return null;
3781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003783 final long identity = Binder.clearCallingIdentity();
3784 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003785 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003786 } finally {
3787 Binder.restoreCallingIdentity(identity);
3788 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003789 }
3790
3791 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003792 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3793 VisualVoicemailSmsFilterSettings settings) {
3794 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795
3796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003799 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 } finally {
3801 Binder.restoreCallingIdentity(identity);
3802 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003803 }
3804
3805 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003806 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3807 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808
3809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003812 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 } finally {
3814 Binder.restoreCallingIdentity(identity);
3815 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003816 }
3817
3818 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003819 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3820 String callingPackage, int subId) {
3821 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003822
3823 final long identity = Binder.clearCallingIdentity();
3824 try {
3825 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003826 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 } finally {
3828 Binder.restoreCallingIdentity(identity);
3829 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003830 }
3831
3832 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003833 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003834 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003835
3836 final long identity = Binder.clearCallingIdentity();
3837 try {
3838 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003839 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003840 } finally {
3841 Binder.restoreCallingIdentity(identity);
3842 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003843 }
3844
3845 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003846 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3847 String callingAttributionTag, int subId, String number, int port, String text,
3848 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003849 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003850 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003851 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003852 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003853 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3854 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003855 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003856
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003857 /**
fionaxu0152e512016-11-14 13:36:14 -08003858 * Sets the voice activation state of a given subId.
3859 */
3860 @Override
3861 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3863 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003864
3865 final long identity = Binder.clearCallingIdentity();
3866 try {
3867 final Phone phone = getPhone(subId);
3868 if (phone != null) {
3869 phone.setVoiceActivationState(activationState);
3870 } else {
3871 loge("setVoiceActivationState fails with invalid subId: " + subId);
3872 }
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003875 }
3876 }
3877
3878 /**
3879 * Sets the data activation state of a given subId.
3880 */
3881 @Override
3882 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3884 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003885
3886 final long identity = Binder.clearCallingIdentity();
3887 try {
3888 final Phone phone = getPhone(subId);
3889 if (phone != null) {
3890 phone.setDataActivationState(activationState);
3891 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003892 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003893 }
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003896 }
3897 }
3898
3899 /**
3900 * Returns the voice activation state of a given subId.
3901 */
3902 @Override
3903 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003904 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003905
fionaxu0152e512016-11-14 13:36:14 -08003906 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003907 final long identity = Binder.clearCallingIdentity();
3908 try {
3909 if (phone != null) {
3910 return phone.getVoiceActivationState();
3911 } else {
3912 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3913 }
3914 } finally {
3915 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003916 }
3917 }
3918
3919 /**
3920 * Returns the data activation state of a given subId.
3921 */
3922 @Override
3923 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003924 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003925
fionaxu0152e512016-11-14 13:36:14 -08003926 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003927 final long identity = Binder.clearCallingIdentity();
3928 try {
3929 if (phone != null) {
3930 return phone.getDataActivationState();
3931 } else {
3932 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3933 }
3934 } finally {
3935 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003936 }
3937 }
3938
3939 /**
Wink Saville36469e72014-06-11 15:17:00 -07003940 * Returns the unread count of voicemails for a subId
3941 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003942 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003943 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3944 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003946 mApp, subId, callingPackage, callingFeatureId,
3947 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003948 return 0;
3949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950 final long identity = Binder.clearCallingIdentity();
3951 try {
3952 final Phone phone = getPhone(subId);
3953 if (phone != null) {
3954 return phone.getVoiceMessageCount();
3955 } else {
3956 return 0;
3957 }
3958 } finally {
3959 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003960 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003961 }
3962
3963 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003964 * returns true, if the device is in a state where both voice and data
3965 * are supported simultaneously. This can change based on location or network condition.
3966 */
3967 @Override
3968 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003969 final long identity = Binder.clearCallingIdentity();
3970 try {
3971 final Phone phone = getPhone(subId);
3972 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3973 } finally {
3974 Binder.restoreCallingIdentity(identity);
3975 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003976 }
3977
3978 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003979 * Send the dialer code if called from the current default dialer or the caller has
3980 * carrier privilege.
3981 * @param inputCode The dialer code to send
3982 */
3983 @Override
3984 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003985 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003986 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003987 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3988 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003989 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003990 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003991 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003993
3994 final long identity = Binder.clearCallingIdentity();
3995 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003996 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003997 } finally {
3998 Binder.restoreCallingIdentity(identity);
3999 }
fionaxu235cc5e2017-03-06 22:25:57 -08004000 }
4001
Pengquan Menga1bb6272018-09-06 09:59:22 -07004002 @Override
4003 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004004 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004005 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004006 mApp, subId, "getNetworkSelectionMode");
4007 final long identity = Binder.clearCallingIdentity();
4008 try {
4009 if (!isActiveSubscription(subId)) {
4010 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4011 }
4012 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4013 } finally {
4014 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004015 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004016 }
4017
Brad Ebinger35c841c2018-10-01 10:40:55 -07004018 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004019 public boolean isInEmergencySmsMode() {
4020 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4021 final long identity = Binder.clearCallingIdentity();
4022 try {
4023 for (Phone phone : PhoneFactory.getPhones()) {
4024 if (phone.isInEmergencySmsMode()) {
4025 return true;
4026 }
4027 }
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
4031 return false;
4032 }
4033
shilu366312e2019-12-17 09:28:10 -08004034 /**
4035 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4036 * @param subId The subscription to use to check the configuration.
4037 * @param c The callback that will be used to send the result.
4038 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004039 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004040 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4041 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004042 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004043 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004044
4045 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4046 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4047 "IMS not available on device.");
4048 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 final long token = Binder.clearCallingIdentity();
4050 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004051 int slotId = getSlotIndexOrException(subId);
4052 verifyImsMmTelConfiguredOrThrow(slotId);
4053 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004054 } catch (ImsException e) {
4055 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 } finally {
4057 Binder.restoreCallingIdentity(token);
4058 }
4059 }
4060
shilu366312e2019-12-17 09:28:10 -08004061 /**
4062 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4063 * @param subId The subscription to use to check the configuration.
4064 * @param c The callback that will be used to send the result.
4065 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004067 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004068 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004069 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004070 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4071 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4072 }
Meng Wangafbc5852019-09-19 17:37:13 -07004073 final long token = Binder.clearCallingIdentity();
4074 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004075 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4076 .removeRegistrationCallbackForSubscription(c, subId);
4077 } catch (ImsException e) {
4078 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4079 + "is inactive, ignoring unregister.");
4080 // If the subscription is no longer active, just return, since the callback
4081 // will already have been removed internally.
4082 } finally {
4083 Binder.restoreCallingIdentity(token);
4084 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004085 }
4086
Brad Ebingera34a6c22019-10-22 17:36:18 -07004087 /**
4088 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4089 */
4090 @Override
4091 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4092 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4093 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4094 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4095 "IMS not available on device.");
4096 }
4097 final long token = Binder.clearCallingIdentity();
4098 try {
4099 Phone phone = getPhone(subId);
4100 if (phone == null) {
4101 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4102 + subId + "'");
4103 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4104 }
4105 phone.getImsRegistrationState(regState -> {
4106 try {
4107 consumer.accept((regState == null)
4108 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4109 } catch (RemoteException e) {
4110 // Ignore if the remote process is no longer available to call back.
4111 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4112 }
4113 });
4114 } finally {
4115 Binder.restoreCallingIdentity(token);
4116 }
4117 }
4118
4119 /**
4120 * Get the transport type for the IMS service registration state.
4121 */
4122 @Override
4123 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004124 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004125 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004126 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4127 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4128 "IMS not available on device.");
4129 }
4130 final long token = Binder.clearCallingIdentity();
4131 try {
4132 Phone phone = getPhone(subId);
4133 if (phone == null) {
4134 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4135 + subId + "'");
4136 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4137 }
4138 phone.getImsRegistrationTech(regTech -> {
4139 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4140 int regTechConverted = (regTech == null)
4141 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4142 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4143 regTechConverted);
4144 try {
4145 consumer.accept(regTechConverted);
4146 } catch (RemoteException e) {
4147 // Ignore if the remote process is no longer available to call back.
4148 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4149 }
4150 });
4151 } finally {
4152 Binder.restoreCallingIdentity(token);
4153 }
4154 }
4155
shilu366312e2019-12-17 09:28:10 -08004156 /**
4157 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4158 * @param subId The subscription to use to check the configuration.
4159 * @param c The callback that will be used to send the result.
4160 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004161 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004162 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4163 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004164 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004165 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004166 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4167 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4168 "IMS not available on device.");
4169 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004170 final long token = Binder.clearCallingIdentity();
4171 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004172 int slotId = getSlotIndexOrException(subId);
4173 verifyImsMmTelConfiguredOrThrow(slotId);
4174 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004175 } catch (ImsException e) {
4176 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 } finally {
4178 Binder.restoreCallingIdentity(token);
4179 }
4180 }
4181
shilu366312e2019-12-17 09:28:10 -08004182 /**
4183 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4184 * @param subId The subscription to use to check the configuration.
4185 * @param c The callback that will be used to send the result.
4186 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004187 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004188 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004189 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004190 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004191 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4192 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4193 }
Meng Wangafbc5852019-09-19 17:37:13 -07004194
4195 final long token = Binder.clearCallingIdentity();
4196 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004197 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004198 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004199 } catch (ImsException e) {
4200 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4201 + "is inactive, ignoring unregister.");
4202 // If the subscription is no longer active, just return, since the callback
4203 // will already have been removed internally.
4204 } finally {
4205 Binder.restoreCallingIdentity(token);
4206 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 }
4208
4209 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004210 public boolean isCapable(int subId, int capability, int regTech) {
4211 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 final long token = Binder.clearCallingIdentity();
4213 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004214 int slotId = getSlotIndexOrException(subId);
4215 verifyImsMmTelConfiguredOrThrow(slotId);
4216 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4217 } catch (com.android.ims.ImsException e) {
4218 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4219 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004220 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004221 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4222 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004223 } finally {
4224 Binder.restoreCallingIdentity(token);
4225 }
4226 }
4227
4228 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004229 public boolean isAvailable(int subId, int capability, int regTech) {
4230 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004231 final long token = Binder.clearCallingIdentity();
4232 try {
4233 Phone phone = getPhone(subId);
4234 if (phone == null) return false;
4235 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004236 } catch (com.android.ims.ImsException e) {
4237 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4238 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004239 } finally {
4240 Binder.restoreCallingIdentity(token);
4241 }
4242 }
4243
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004244 /**
4245 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4246 * subscription.
4247 * @param subId The subscription to use to check the configuration.
4248 * @param callback The callback that will be used to send the result.
4249 * @param capability The MmTelFeature capability that will be used to send the result.
4250 * @param transportType The transport type of the MmTelFeature capability.
4251 */
4252 @Override
4253 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4254 int transportType) {
4255 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004256 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4257 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4258 "IMS not available on device.");
4259 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004260 final long token = Binder.clearCallingIdentity();
4261 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004262 int slotId = getSlotIndex(subId);
4263 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4264 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4265 + subId + "'");
4266 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4267 }
4268 verifyImsMmTelConfiguredOrThrow(slotId);
4269 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4270 transportType, aBoolean -> {
4271 try {
4272 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4273 } catch (RemoteException e) {
4274 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4275 + "running. Ignore");
4276 }
4277 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004278 } catch (ImsException e) {
4279 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004280 } finally {
4281 Binder.restoreCallingIdentity(token);
4282 }
4283 }
4284
shilu366312e2019-12-17 09:28:10 -08004285 /**
4286 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4287 * @param subId The subscription to use to check the configuration.
4288 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 @Override
4290 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004291 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004292 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004293
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 final long token = Binder.clearCallingIdentity();
4295 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004296 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004297 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004299 } catch (ImsException e) {
4300 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004301 } finally {
4302 Binder.restoreCallingIdentity(token);
4303 }
4304 }
4305
4306 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004307 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004309 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004310 final long identity = Binder.clearCallingIdentity();
4311 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004312 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004313 // This setting doesn't require an active ImsService connection, so do not verify. The
4314 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004315 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004316 } catch (ImsException e) {
4317 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
4321 }
4322
shilu366312e2019-12-17 09:28:10 -08004323 /**
4324 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4325 * @param subId The subscription to use to check the configuration.
4326 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004327 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004328 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004329 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004330 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004331 final long identity = Binder.clearCallingIdentity();
4332 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004333 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004334 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004335 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004336 } catch (ImsException e) {
4337 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
4341 }
4342
4343 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004344 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004346 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004347 final long identity = Binder.clearCallingIdentity();
4348 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004349 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004350 // This setting doesn't require an active ImsService connection, so do not verify. The
4351 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004352 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004353 } catch (ImsException e) {
4354 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004355 } finally {
4356 Binder.restoreCallingIdentity(identity);
4357 }
4358 }
4359
shilu366312e2019-12-17 09:28:10 -08004360 /**
4361 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4362 * @param subId The subscription to use to check the configuration.
4363 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 @Override
4365 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004366 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004367 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004368 final long identity = Binder.clearCallingIdentity();
4369 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004370 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004371 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004372 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004373 } catch (ImsException e) {
4374 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 } finally {
4376 Binder.restoreCallingIdentity(identity);
4377 }
4378 }
4379
4380 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004381 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004383 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004384 final long identity = Binder.clearCallingIdentity();
4385 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004386 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004387 // This setting doesn't require an active ImsService connection, so do not verify. The
4388 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004389 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004390 } catch (ImsException e) {
4391 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004392 } finally {
4393 Binder.restoreCallingIdentity(identity);
4394 }
4395 }
4396
shilu366312e2019-12-17 09:28:10 -08004397 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004398 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4399 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4400 * @param subId The subscription to use to check the configuration.
4401 */
4402 @Override
4403 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004404 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004405 mApp, subId, "isCrossSimCallingEnabledByUser");
4406 final long identity = Binder.clearCallingIdentity();
4407 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004408 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004409 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004410 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004411 } catch (ImsException e) {
4412 throw new ServiceSpecificException(e.getCode());
4413 } finally {
4414 Binder.restoreCallingIdentity(identity);
4415 }
4416 }
4417
4418 /**
4419 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4420 * Requires MODIFY_PHONE_STATE permission.
4421 * @param subId The subscription to use to check the configuration.
4422 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4423 * false otherwise
4424 */
4425 @Override
4426 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4428 "setCrossSimCallingEnabled");
4429 final long identity = Binder.clearCallingIdentity();
4430 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004431 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004432 // This setting doesn't require an active ImsService connection, so do not verify. The
4433 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004434 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004435 } catch (ImsException e) {
4436 throw new ServiceSpecificException(e.getCode());
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
4440 }
4441
4442 /**
shilu366312e2019-12-17 09:28:10 -08004443 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4444 * @param subId The subscription to use to check the configuration.
4445 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004446 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004447
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004449 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004450 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004451 final long identity = Binder.clearCallingIdentity();
4452 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004453 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004454 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004455 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004456 } catch (ImsException e) {
4457 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004458 } finally {
4459 Binder.restoreCallingIdentity(identity);
4460 }
4461 }
4462
4463 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004464 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004466 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004467 final long identity = Binder.clearCallingIdentity();
4468 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004469 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004470 // This setting doesn't require an active ImsService connection, so do not verify. The
4471 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004472 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004473 } catch (ImsException e) {
4474 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004475 } finally {
4476 Binder.restoreCallingIdentity(identity);
4477 }
4478 }
4479
4480 @Override
4481 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4482 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4483 "setVoWiFiNonPersistent");
4484 final long identity = Binder.clearCallingIdentity();
4485 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004486 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004487 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004488 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004489 } catch (ImsException e) {
4490 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004491 } finally {
4492 Binder.restoreCallingIdentity(identity);
4493 }
4494 }
4495
shilu366312e2019-12-17 09:28:10 -08004496 /**
4497 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4498 * @param subId The subscription to use to check the configuration.
4499 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004500 @Override
4501 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004502 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004503 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004504 final long identity = Binder.clearCallingIdentity();
4505 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004506 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004507 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004508 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004509 } catch (ImsException e) {
4510 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
4514 }
4515
4516 @Override
4517 public void setVoWiFiModeSetting(int subId, int mode) {
4518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4519 "setVoWiFiModeSetting");
4520 final long identity = Binder.clearCallingIdentity();
4521 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004522 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004523 // This setting doesn't require an active ImsService connection, so do not verify. The
4524 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004525 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*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 int getVoWiFiRoamingModeSetting(int subId) {
4535 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4536 final long identity = Binder.clearCallingIdentity();
4537 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004538 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004539 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004540 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004541 } catch (ImsException e) {
4542 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
4546 }
4547
4548 @Override
4549 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4551 "setVoWiFiRoamingModeSetting");
4552 final long identity = Binder.clearCallingIdentity();
4553 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004554 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004555 // This setting doesn't require an active ImsService connection, so do not verify. The
4556 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004557 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004558 } catch (ImsException e) {
4559 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004560 } finally {
4561 Binder.restoreCallingIdentity(identity);
4562 }
4563 }
4564
4565 @Override
4566 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4568 "setRttCapabilityEnabled");
4569 final long identity = Binder.clearCallingIdentity();
4570 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004571 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004572 // This setting doesn't require an active ImsService connection, so do not verify. The
4573 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004574 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004575 } catch (ImsException e) {
4576 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004577 } finally {
4578 Binder.restoreCallingIdentity(identity);
4579 }
4580 }
4581
shilu366312e2019-12-17 09:28:10 -08004582 /**
4583 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4584 * @param subId The subscription to use to check the configuration.
4585 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004586 @Override
4587 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004588 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004589 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004590 final long identity = Binder.clearCallingIdentity();
4591 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004592 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004593 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004594 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004595 } catch (ImsException e) {
4596 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
4600 }
4601
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004602 @Override
4603 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4604 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004605
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004606 final long identity = Binder.clearCallingIdentity();
4607 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004608 if (!isImsAvailableOnDevice()) {
4609 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4610 "IMS not available on device.");
4611 }
4612 int slotId = getSlotIndexOrException(subId);
4613 verifyImsMmTelConfiguredOrThrow(slotId);
4614 ImsManager.getInstance(mApp, slotId)
4615 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004616 } catch (ImsException e) {
4617 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004618 } finally {
4619 Binder.restoreCallingIdentity(identity);
4620 }
4621 }
4622
4623 @Override
4624 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4625 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004626
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004627 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004628 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4629 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4630 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004631 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004632 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004633 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004634 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004635 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4636 + "is inactive, ignoring unregister.");
4637 // If the subscription is no longer active, just return, since the callback will already
4638 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004639 } finally {
4640 Binder.restoreCallingIdentity(identity);
4641 }
4642 }
4643
joonhunshincffb7fc2021-11-28 07:32:01 +00004644 @Override
4645 public void registerFeatureProvisioningChangedCallback(int subId,
4646 IFeatureProvisioningCallback callback) {
4647 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4648 mApp, subId, "registerFeatureProvisioningChangedCallback");
4649
4650 final long identity = Binder.clearCallingIdentity();
4651 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4652 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4653 }
4654
joonhunshin91bc1952022-04-29 08:47:15 +00004655 try {
4656 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4657 if (controller == null) {
4658 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4659 "Device does not support IMS");
4660 }
4661 controller.addFeatureProvisioningChangedCallback(subId, callback);
4662 } finally {
4663 Binder.restoreCallingIdentity(identity);
4664 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004665 }
4666
4667 @Override
4668 public void unregisterFeatureProvisioningChangedCallback(int subId,
4669 IFeatureProvisioningCallback callback) {
4670 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4671 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4672
4673 final long identity = Binder.clearCallingIdentity();
4674 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4675 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4676 }
4677
joonhunshin91bc1952022-04-29 08:47:15 +00004678 try {
4679 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4680 if (controller == null) {
4681 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4682 return;
4683 }
4684 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4685 } finally {
4686 Binder.restoreCallingIdentity(identity);
4687 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004688 }
allenwtsu99c623b2020-01-03 18:24:23 +08004689
4690 private void checkModifyPhoneStatePermission(int subId, String message) {
4691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4692 message);
4693 }
4694
allenwtsu99c623b2020-01-03 18:24:23 +08004695 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004696 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004697 boolean isProvisioned) {
4698 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4699
4700 final long identity = Binder.clearCallingIdentity();
4701 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004702 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4703 if (controller == null) {
4704 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4705 return;
4706 }
4707 controller.setRcsProvisioningStatusForCapability(
4708 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004709 } finally {
4710 Binder.restoreCallingIdentity(identity);
4711 }
allenwtsu99c623b2020-01-03 18:24:23 +08004712 }
4713
4714
4715 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004716 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4717 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4718 mApp, subId, "getRcsProvisioningStatusForCapability");
4719
allenwtsu99c623b2020-01-03 18:24:23 +08004720 final long identity = Binder.clearCallingIdentity();
4721 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004722 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4723 if (controller == null) {
4724 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4725
4726 // device does not support IMS, this method will return true always.
4727 return true;
4728 }
4729 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004730 } finally {
4731 Binder.restoreCallingIdentity(identity);
4732 }
4733 }
4734
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004735 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004736 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4737 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004738 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004739
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004740 final long identity = Binder.clearCallingIdentity();
4741 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004742 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4743 if (controller == null) {
4744 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4745 return;
4746 }
4747 controller.setImsProvisioningStatusForCapability(
4748 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004749 } finally {
4750 Binder.restoreCallingIdentity(identity);
4751 }
4752 }
4753
4754 @Override
4755 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004756 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4757 mApp, subId, "getProvisioningStatusForCapability");
4758
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004759 final long identity = Binder.clearCallingIdentity();
4760 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004761 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4762 if (controller == null) {
4763 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004764
joonhunshin91bc1952022-04-29 08:47:15 +00004765 // device does not support IMS, this method will return true always.
4766 return true;
4767 }
4768 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004769 } finally {
4770 Binder.restoreCallingIdentity(identity);
4771 }
4772 }
4773
4774 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004775 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4776 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4777 mApp, subId, "isProvisioningRequiredForCapability");
4778
4779 final long identity = Binder.clearCallingIdentity();
4780 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004781 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4782 if (controller == null) {
4783 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4784
4785 // device does not support IMS, this method will return false
4786 return false;
4787 }
4788 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004789 } finally {
4790 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004791 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004792 }
4793
4794 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004795 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4796 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4797 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004798
joonhunshincffb7fc2021-11-28 07:32:01 +00004799 final long identity = Binder.clearCallingIdentity();
4800 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004801 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4802 if (controller == null) {
4803 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4804
4805 // device does not support IMS, this method will return false
4806 return false;
4807 }
4808 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004809 } finally {
4810 Binder.restoreCallingIdentity(identity);
4811 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004812 }
4813
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004814 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004815 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004816 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4817 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4818 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004819 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4820 mApp, subId, "getImsProvisioningInt");
4821
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004822 final long identity = Binder.clearCallingIdentity();
4823 try {
4824 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004825 int slotId = getSlotIndex(subId);
4826 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4827 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4828 + subId + "' for key:" + key);
4829 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4830 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004831
joonhunshin91bc1952022-04-29 08:47:15 +00004832 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4833 if (controller == null) {
4834 loge("getImsProvisioningInt: Device does not support IMS");
4835
4836 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4837 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4838 }
4839 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004840 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4841 return retVal;
4842 }
4843
calvinpanb5a34062021-02-08 19:59:36 +08004844 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004845 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004846 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4847 + subId + "' for key:" + key);
4848 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004849 } finally {
4850 Binder.restoreCallingIdentity(identity);
4851 }
4852 }
4853
4854 @Override
4855 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004856 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4857 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4858 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004859 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4860 mApp, subId, "getImsProvisioningString");
4861
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004862 final long identity = Binder.clearCallingIdentity();
4863 try {
4864 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004865 int slotId = getSlotIndex(subId);
4866 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4867 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4868 + subId + "' for key:" + key);
4869 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4870 }
calvinpanb5a34062021-02-08 19:59:36 +08004871 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004872 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004873 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4874 + subId + "' for key:" + key);
4875 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004876 } finally {
4877 Binder.restoreCallingIdentity(identity);
4878 }
4879 }
4880
4881 @Override
4882 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004883 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4884 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4885 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4887 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004888
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004889 final long identity = Binder.clearCallingIdentity();
4890 try {
4891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004892 int slotId = getSlotIndex(subId);
4893 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4894 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4895 + subId + "' for key:" + key);
4896 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4897 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004898
joonhunshin91bc1952022-04-29 08:47:15 +00004899 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4900 if (controller == null) {
4901 loge("setImsProvisioningInt: Device does not support IMS");
4902
4903 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
4904 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4905 }
4906 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00004907 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4908 return retVal;
4909 }
4910
calvinpanb5a34062021-02-08 19:59:36 +08004911 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4912 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004913 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004914 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004915 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004916 } finally {
4917 Binder.restoreCallingIdentity(identity);
4918 }
4919 }
4920
4921 @Override
4922 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004923 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4924 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4925 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4927 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004928 final long identity = Binder.clearCallingIdentity();
4929 try {
4930 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004931 int slotId = getSlotIndex(subId);
4932 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4933 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4934 + subId + "' for key:" + key);
4935 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4936 }
calvinpanb5a34062021-02-08 19:59:36 +08004937 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4938 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004939 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004940 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004941 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004942 } finally {
4943 Binder.restoreCallingIdentity(identity);
4944 }
4945 }
4946
Brad Ebinger919631e2021-06-02 17:46:35 -07004947 /**
4948 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4949 * for the given slot ID or no ImsResolver instance has been created.
4950 * @param slotId The slot ID that the IMS service is created for.
4951 * @throws ImsException If there is no ImsService configured for this slot.
4952 */
4953 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4954 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4955 ImsFeature.FEATURE_MMTEL)) {
4956 throw new ImsException("This subscription does not support MMTEL over IMS",
4957 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4958 }
4959 }
4960
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004961 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004962 int slotId = SubscriptionManager.getSlotIndex(subId);
4963 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004964 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4965 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004966 }
4967 return slotId;
4968 }
4969
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004970 private int getSlotIndex(int subId) {
4971 int slotId = SubscriptionManager.getSlotIndex(subId);
4972 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4973 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4974 }
4975 return slotId;
4976 }
4977
Wink Saville36469e72014-06-11 15:17:00 -07004978 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004979 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004980 */
4981 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004982 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4983 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004984 try {
4985 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4986 } catch (SecurityException se) {
4987 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4988 throw new SecurityException("Package " + callingPackage + " does not belong to "
4989 + Binder.getCallingUid());
4990 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004991 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004992 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004993 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004994 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004995 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004996 mApp, subId, callingPackage, callingFeatureId,
4997 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004998 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4999 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 final long identity = Binder.clearCallingIdentity();
5002 try {
5003 final Phone phone = getPhone(subId);
5004 if (phone != null) {
5005 return phone.getServiceState().getDataNetworkType();
5006 } else {
5007 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5008 }
5009 } finally {
5010 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005011 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005012 }
5013
5014 /**
5015 * Returns the data network type
5016 */
5017 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005018 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005019 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5020 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005021 }
5022
5023 /**
5024 * Returns the data network type for a subId
5025 */
5026 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005027 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5028 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005029 String functionName = "getDataNetworkTypeForSubscriber";
5030 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5031 mApp, functionName)) {
5032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5033 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5034 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5035 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005036 }
5037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 final long identity = Binder.clearCallingIdentity();
5039 try {
5040 final Phone phone = getPhone(subId);
5041 if (phone != null) {
5042 return phone.getServiceState().getDataNetworkType();
5043 } else {
5044 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5045 }
5046 } finally {
5047 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005049 }
5050
5051 /**
Wink Saville36469e72014-06-11 15:17:00 -07005052 * Returns the Voice network type for a subId
5053 */
5054 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005055 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5056 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005057 String functionName = "getVoiceNetworkTypeForSubscriber";
5058 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5059 mApp, functionName)) {
5060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5061 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5062 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5063 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005064 }
5065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 final long identity = Binder.clearCallingIdentity();
5067 try {
5068 final Phone phone = getPhone(subId);
5069 if (phone != null) {
5070 return phone.getServiceState().getVoiceNetworkType();
5071 } else {
5072 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5073 }
5074 } finally {
5075 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005076 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005077 }
5078
5079 /**
5080 * @return true if a ICC card is present
5081 */
5082 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005083 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005084 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5085 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005086 }
5087
5088 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005089 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005090 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005091 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005092 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005093 final long identity = Binder.clearCallingIdentity();
5094 try {
5095 final Phone phone = PhoneFactory.getPhone(slotIndex);
5096 if (phone != null) {
5097 return phone.getIccCard().hasIccCard();
5098 } else {
5099 return false;
5100 }
5101 } finally {
5102 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005104 }
5105
5106 /**
5107 * Return if the current radio is LTE on CDMA. This
5108 * is a tri-state return value as for a period of time
5109 * the mode may be unknown.
5110 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005111 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005112 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005113 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005114 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005115 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005116 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5117 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5118 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005119 }
5120
Sanket Padawe356d7632015-06-22 14:03:32 -07005121 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005122 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5123 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005124 try {
5125 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5126 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005127 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5128 }
5129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005130 final long identity = Binder.clearCallingIdentity();
5131 try {
5132 final Phone phone = getPhone(subId);
5133 if (phone == null) {
5134 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5135 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005136 return TelephonyProperties.lte_on_cdma_device()
5137 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 }
5139 } finally {
5140 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005141 }
Wink Saville36469e72014-06-11 15:17:00 -07005142 }
5143
Wink Saville36469e72014-06-11 15:17:00 -07005144 /**
5145 * {@hide}
5146 * Returns Default subId, 0 in the case of single standby.
5147 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005148 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005149 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005150 }
5151
Shishir Agrawala9f32182016-04-12 12:00:16 -07005152 private int getSlotForDefaultSubscription() {
5153 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5154 }
5155
Wink Savilleb564aae2014-10-23 10:18:09 -07005156 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005157 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005158 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005159
Pengquan Menge92a50d2018-09-21 15:54:48 -07005160 private boolean isActiveSubscription(int subId) {
5161 return mSubscriptionController.isActiveSubId(subId);
5162 }
5163
Ihab Awadf2177b72013-11-25 13:33:23 -08005164 /**
5165 * @see android.telephony.TelephonyManager.WifiCallingChoices
5166 */
5167 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 final long identity = Binder.clearCallingIdentity();
5169 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005170 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5172 getWhenToMakeWifiCallsDefaultPreference());
5173 } finally {
5174 Binder.restoreCallingIdentity(identity);
5175 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005176 }
5177
5178 /**
5179 * @see android.telephony.TelephonyManager.WifiCallingChoices
5180 */
5181 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182 final long identity = Binder.clearCallingIdentity();
5183 try {
5184 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005185 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5187 } finally {
5188 Binder.restoreCallingIdentity(identity);
5189 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005190 }
5191
Sailesh Nepald1e68152013-12-12 19:08:02 -08005192 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005193 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005194 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005195 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005196
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005197 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5198 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5199 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005200 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005201 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5202 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005203 }
5204 return PhoneFactory.getPhone(phoneId);
5205 }
5206
Shishir Agrawal566b7612013-10-28 14:41:00 -07005207 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005208 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005209 @NonNull IccLogicalChannelRequest request) {
5210 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5211 /*message=*/ "iccOpenLogicalChannel");
5212
5213 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5214 // Verify that the callingPackage in the request belongs to the calling UID
5215 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5216
5217 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005218 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005219
Rambo Wanga1782702021-11-10 20:15:19 -08005220 private Phone getPhoneFromValidIccLogicalChannelRequest(
5221 @NonNull IccLogicalChannelRequest request, String message) {
5222 Phone phone;
5223 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5224 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5225 mApp, request.subId, message);
5226 phone = getPhoneFromSubId(request.subId);
5227 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5228 enforceModifyPermission();
5229 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5230 } else {
5231 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005232 }
Rambo Wanga1782702021-11-10 20:15:19 -08005233 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005234 }
5235
5236 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005237 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 final long identity = Binder.clearCallingIdentity();
5239 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005240 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005242 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5243 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005244 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5245 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 loge("The calling package is not allowed to access ISD-R.");
5247 throw new SecurityException(
5248 "The calling package is not allowed to access ISD-R.");
5249 }
Derek Tan740e1672017-06-27 14:56:27 -07005250 }
Derek Tan740e1672017-06-27 14:56:27 -07005251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005253 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5254 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 return response;
5256 } finally {
5257 Binder.restoreCallingIdentity(identity);
5258 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005259 }
5260
5261 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005262 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5263 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5264 /*message=*/"iccCloseLogicalChannel");
5265
5266 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5267
5268 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005269 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005270
Rambo Wanga1782702021-11-10 20:15:19 -08005271 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5272 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005273 // before this feature is enabled, this API should only return false if
5274 // the operation fails instead of throwing runtime exception for
5275 // backward-compatibility.
5276 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5277 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 final long identity = Binder.clearCallingIdentity();
5279 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005280 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005281 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 }
Chen Xue9d737e2022-01-01 23:41:31 -08005283 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005284 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005285 Boolean success = false;
5286 if (result instanceof RuntimeException) {
5287 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005288 if (shouldThrowExceptionOnFailure) {
5289 throw (RuntimeException) result;
5290 } else {
5291 return false;
5292 }
Chen Xue9d737e2022-01-01 23:41:31 -08005293 } else if (result instanceof Boolean) {
5294 success = (Boolean) result;
5295 } else {
5296 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5297 }
Rambo Wanga1782702021-11-10 20:15:19 -08005298 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299 return success;
5300 } finally {
5301 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005302 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005303 }
5304
5305 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005306 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005307 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5309 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005310 if (DBG) {
5311 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5312 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5313 + p3 + " data=" + data);
5314 }
5315 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5316 command, p1, p2, p3, data);
5317 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005318
Jordan Liu4c733742019-02-28 12:03:40 -08005319 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005320 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5321 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005322 enforceModifyPermission();
5323 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005324 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5325 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5326 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005327 }
5328 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005329 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5330 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005331 }
5332
5333 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5334 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 final long identity = Binder.clearCallingIdentity();
5336 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005337 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 return "";
5339 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005342 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5343 null /* workSource */);
5344 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005346 // Append the returned status code to the end of the response payload.
5347 String s = Integer.toHexString(
5348 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5349 if (response.payload != null) {
5350 s = IccUtils.bytesToHexString(response.payload) + s;
5351 }
5352 return s;
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005355 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005356 }
Jake Hambye994d462014-02-03 13:10:13 -08005357
Evan Charltonc66da362014-05-16 14:06:40 -07005358 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005359 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5360 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5362 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005364 if (DBG) {
5365 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5366 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5367 }
5368 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5369 cla, command, p1, p2, p3, data);
5370 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005371
Jordan Liu4c733742019-02-28 12:03:40 -08005372 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005373 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5374 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005375 enforceModifyPermission();
5376 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5377 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005378 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5379 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5380 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005381 }
5382
5383 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005384 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5385 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005386 }
5387
5388 // open APDU basic channel assuming the caller has sufficient permissions
5389 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5390 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 final long identity = Binder.clearCallingIdentity();
5392 try {
5393 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5394 && TextUtils.equals(ISDR_AID, data)) {
5395 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005396 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5397 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 if (bestComponent == null
5399 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5400 loge("The calling package is not allowed to select ISD-R.");
5401 throw new SecurityException(
5402 "The calling package is not allowed to select ISD-R.");
5403 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005404 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005405
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005407 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5408 null /* workSource */);
5409 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005410
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 // Append the returned status code to the end of the response payload.
5412 String s = Integer.toHexString(
5413 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5414 if (response.payload != null) {
5415 s = IccUtils.bytesToHexString(response.payload) + s;
5416 }
5417 return s;
5418 } finally {
5419 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005420 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005421 }
5422
5423 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005424 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005425 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5427 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 final long identity = Binder.clearCallingIdentity();
5430 try {
5431 if (DBG) {
5432 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5433 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5434 }
5435
5436 IccIoResult response =
5437 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5438 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5439 subId);
5440
5441 if (DBG) {
5442 log("Exchange SIM_IO [R]" + response);
5443 }
5444
5445 byte[] result = null;
5446 int length = 2;
5447 if (response.payload != null) {
5448 length = 2 + response.payload.length;
5449 result = new byte[length];
5450 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5451 } else {
5452 result = new byte[length];
5453 }
5454
5455 result[length - 1] = (byte) response.sw2;
5456 result[length - 2] = (byte) response.sw1;
5457 return result;
5458 } finally {
5459 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005460 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005461 }
5462
Nathan Haroldb3014052017-01-25 15:57:32 -08005463 /**
5464 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5465 * on a particular subscription
5466 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005467 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5468 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005470 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005471 return null;
5472 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473
5474 final long identity = Binder.clearCallingIdentity();
5475 try {
5476 if (appType != TelephonyManager.APPTYPE_USIM
5477 && appType != TelephonyManager.APPTYPE_SIM) {
5478 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5479 return null;
5480 }
5481 Object response = sendRequest(
5482 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5483 if (response instanceof String[]) {
5484 return (String[]) response;
5485 }
yincheng zhao2737e882019-09-06 17:06:54 -07005486 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005488 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 } finally {
5490 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005491 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005492 }
5493
yincheng zhao2737e882019-09-06 17:06:54 -07005494 /**
5495 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5496 * subscription.
5497 *
5498 * @param subId the id of the subscription.
5499 * @param appType the uicc app type, must be USIM or SIM.
5500 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5501 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005502 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005503 * @return number of fplmns that is successfully written to the SIM.
5504 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005505 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5506 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5508 mApp, subId, "setForbiddenPlmns");
5509
yincheng zhao2737e882019-09-06 17:06:54 -07005510 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5511 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5512 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5513 }
5514 if (fplmns == null) {
5515 throw new IllegalArgumentException("Fplmn List provided is null");
5516 }
5517 for (String fplmn : fplmns) {
5518 if (!CellIdentity.isValidPlmn(fplmn)) {
5519 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5520 }
5521 }
5522 final long identity = Binder.clearCallingIdentity();
5523 try {
5524 Object response = sendRequest(
5525 CMD_SET_FORBIDDEN_PLMNS,
5526 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5527 subId);
5528 return (int) response;
5529 } finally {
5530 Binder.restoreCallingIdentity(identity);
5531 }
5532 }
5533
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005534 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005535 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5537 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 final long identity = Binder.clearCallingIdentity();
5540 try {
5541 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5542 if (response.payload == null) {
5543 return "";
5544 }
Evan Charltonc66da362014-05-16 14:06:40 -07005545
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 // Append the returned status code to the end of the response payload.
5547 String s = Integer.toHexString(
5548 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5549 s = IccUtils.bytesToHexString(response.payload) + s;
5550 return s;
5551 } finally {
5552 Binder.restoreCallingIdentity(identity);
5553 }
Evan Charltonc66da362014-05-16 14:06:40 -07005554 }
5555
Jake Hambye994d462014-02-03 13:10:13 -08005556 /**
5557 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5558 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5559 *
5560 * @param itemID the ID of the item to read
5561 * @return the NV item as a String, or null on error.
5562 */
5563 @Override
5564 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005565 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5567 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005568
5569 final long identity = Binder.clearCallingIdentity();
5570 try {
5571 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005572 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5574 return value;
5575 } finally {
5576 Binder.restoreCallingIdentity(identity);
5577 }
Jake Hambye994d462014-02-03 13:10:13 -08005578 }
5579
5580 /**
5581 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5582 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5583 *
5584 * @param itemID the ID of the item to read
5585 * @param itemValue the value to write, as a String
5586 * @return true on success; false on any failure
5587 */
5588 @Override
5589 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005590 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5592 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593
5594 final long identity = Binder.clearCallingIdentity();
5595 try {
5596 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5597 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005598 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5600 return success;
5601 } finally {
5602 Binder.restoreCallingIdentity(identity);
5603 }
Jake Hambye994d462014-02-03 13:10:13 -08005604 }
5605
5606 /**
5607 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5608 * Used for device configuration by some CDMA operators.
5609 *
5610 * @param preferredRoamingList byte array containing the new PRL
5611 * @return true on success; false on any failure
5612 */
5613 @Override
5614 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5616 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617
5618 final long identity = Binder.clearCallingIdentity();
5619 try {
5620 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5621 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5622 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5623 return success;
5624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
Jake Hambye994d462014-02-03 13:10:13 -08005627 }
5628
5629 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005630 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005631 * Used for device configuration by some CDMA operators.
5632 *
chen xu6dac5ab2018-10-26 17:39:23 -07005633 * @param slotIndex - device slot.
5634 *
Jake Hambye994d462014-02-03 13:10:13 -08005635 * @return true on success; false on any failure
5636 */
5637 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005638 public boolean resetModemConfig(int slotIndex) {
5639 Phone phone = PhoneFactory.getPhone(slotIndex);
5640 if (phone != null) {
5641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5642 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643
chen xu6dac5ab2018-10-26 17:39:23 -07005644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5647 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5648 return success;
5649 } finally {
5650 Binder.restoreCallingIdentity(identity);
5651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652 }
chen xu6dac5ab2018-10-26 17:39:23 -07005653 return false;
5654 }
5655
5656 /**
5657 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5658 *
5659 * @param slotIndex - device slot.
5660 *
5661 * @return true on success; false on any failure
5662 */
5663 @Override
5664 public boolean rebootModem(int slotIndex) {
5665 Phone phone = PhoneFactory.getPhone(slotIndex);
5666 if (phone != null) {
5667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5668 mApp, phone.getSubId(), "rebootModem");
5669
5670 final long identity = Binder.clearCallingIdentity();
5671 try {
5672 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5673 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5674 return success;
5675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
5678 }
5679 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005680 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005681
Brad Ebinger51f743a2017-01-23 13:50:20 -08005682 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005683 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5684 * {@link #disableIms(int)}.
5685 * @param slotIndex device slot.
5686 */
5687 public void resetIms(int slotIndex) {
5688 enforceModifyPermission();
5689
5690 final long identity = Binder.clearCallingIdentity();
5691 try {
5692 if (mImsResolver == null) {
5693 // may happen if the does not support IMS.
5694 return;
5695 }
5696 mImsResolver.disableIms(slotIndex);
5697 mImsResolver.enableIms(slotIndex);
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
5701 }
5702
5703 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005704 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5705 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005706 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005707 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005708 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709
5710 final long identity = Binder.clearCallingIdentity();
5711 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005712 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005713 // may happen if the device does not support IMS.
5714 return;
5715 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005716 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005720 }
5721
5722 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005723 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5724 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005725 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005726 public void disableIms(int slotId) {
5727 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728
5729 final long identity = Binder.clearCallingIdentity();
5730 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005731 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005732 // may happen if the device does not support IMS.
5733 return;
5734 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005735 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005739 }
5740
5741 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005742 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5743 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005744 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005745 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005746 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005747 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748
5749 final long identity = Binder.clearCallingIdentity();
5750 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005751 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005752 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5753 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005754 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005755 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 } finally {
5757 Binder.restoreCallingIdentity(identity);
5758 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005759 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005760 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005761 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5762 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005763 @Override
5764 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005765 enforceModifyPermission();
5766
5767 final long identity = Binder.clearCallingIdentity();
5768 try {
5769 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005770 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005771 } finally {
5772 Binder.restoreCallingIdentity(identity);
5773 }
5774 }
5775
5776 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005777 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005778 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005779 */
5780 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5781 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782
5783 final long identity = Binder.clearCallingIdentity();
5784 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005785 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005786 // may happen if the device does not support IMS.
5787 return null;
5788 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790 } finally {
5791 Binder.restoreCallingIdentity(identity);
5792 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005793 }
5794
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005795 /**
5796 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005797 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005798 */
5799 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5800 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801
5802 final long identity = Binder.clearCallingIdentity();
5803 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005804 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005805 // may happen if the device does not support IMS.
5806 return null;
5807 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005808 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809 } finally {
5810 Binder.restoreCallingIdentity(identity);
5811 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005812 }
5813
Brad Ebinger884c07b2018-02-15 16:17:40 -08005814 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005815 * Sets the ImsService Package Name that Telephony will bind to.
5816 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005817 * @param slotIndex the slot ID that the ImsService should bind for.
5818 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005819 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005820 * @param featureTypes An integer array of feature types associated with a packageName.
5821 * @param packageName The name of the package that the current configuration will be replaced
5822 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005823 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005824 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005825 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5826 int[] featureTypes, String packageName) {
5827 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5828 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5830 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005831 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 final long identity = Binder.clearCallingIdentity();
5834 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005835 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005836 // may happen if the device does not support IMS.
5837 return false;
5838 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005839 Map<Integer, String> featureConfig = new HashMap<>();
5840 for (int featureType : featureTypes) {
5841 featureConfig.put(featureType, packageName);
5842 }
5843 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5844 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005848 }
5849
5850 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005851 * Clears any carrier ImsService overrides for the slot index specified that were previously
5852 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5853 *
5854 * This should only be used for testing.
5855 *
5856 * @param slotIndex the slot ID that the ImsService should bind for.
5857 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5858 */
5859 @Override
5860 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5861 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5862 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5863 "clearCarrierImsServiceOverride");
5864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5865 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5866 "clearCarrierImsServiceOverride");
5867
5868 final long identity = Binder.clearCallingIdentity();
5869 try {
5870 if (mImsResolver == null) {
5871 // may happen if the device does not support IMS.
5872 return false;
5873 }
5874 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5875 } finally {
5876 Binder.restoreCallingIdentity(identity);
5877 }
5878 }
5879
5880 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005881 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005882 *
5883 * @param slotId The slot that the ImsService is associated with.
5884 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5885 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005886 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005887 * @return the package name of the ImsService configuration.
5888 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005889 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5890 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005891 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005892 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005893 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005894 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5895 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 final long identity = Binder.clearCallingIdentity();
5898 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005899 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005900 // may happen if the device does not support IMS.
5901 return "";
5902 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005903 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005904 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5905 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 } finally {
5907 Binder.restoreCallingIdentity(identity);
5908 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005909 }
5910
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005911 /**
5912 * Get the MmTelFeature state associated with the requested subscription id.
5913 * @param subId The subscription that the MmTelFeature is associated with.
5914 * @param callback A callback with an integer containing the
5915 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5916 */
5917 @Override
5918 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5919 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005920 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5921 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5922 "IMS not available on device.");
5923 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005924 final long token = Binder.clearCallingIdentity();
5925 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005926 int slotId = getSlotIndex(subId);
5927 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5928 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5929 + subId + "'");
5930 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5931 }
5932 verifyImsMmTelConfiguredOrThrow(slotId);
5933 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5934 try {
5935 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5936 } catch (RemoteException e) {
5937 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5938 + "Ignore");
5939 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005940 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005941 } catch (ImsException e) {
5942 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005943 } finally {
5944 Binder.restoreCallingIdentity(token);
5945 }
5946 }
5947
Daniel Brightbb5840b2021-01-12 15:48:18 -08005948 /**
5949 * Sets the ims registration state on all valid {@link Phone}s.
5950 */
5951 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005952 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005956 // NOTE: Before S, this method only set the default phone.
5957 for (final Phone phone : PhoneFactory.getPhones()) {
5958 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5959 phone.setImsRegistrationState(registered);
5960 }
5961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 } finally {
5963 Binder.restoreCallingIdentity(identity);
5964 }
Wink Saville36469e72014-06-11 15:17:00 -07005965 }
5966
5967 /**
Stuart Scott54788802015-03-30 13:18:01 -07005968 * Set the network selection mode to automatic.
5969 *
5970 */
5971 @Override
5972 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5974 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975
5976 final long identity = Binder.clearCallingIdentity();
5977 try {
shilufc958392020-01-20 11:36:01 -08005978 if (!isActiveSubscription(subId)) {
5979 return;
5980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005982 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5983 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 } finally {
5985 Binder.restoreCallingIdentity(identity);
5986 }
Stuart Scott54788802015-03-30 13:18:01 -07005987 }
5988
Jack Yud10cdd42020-09-28 20:28:01 -07005989 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005990 * Ask the radio to connect to the input network and change selection mode to manual.
5991 *
5992 * @param subId the id of the subscription.
5993 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5994 * the operator to attach to.
5995 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5996 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5997 * normal network selection next time.
5998 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005999 */
6000 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006001 public boolean setNetworkSelectionModeManual(
6002 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6004 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006005
6006 if (!isActiveSubscription(subId)) {
6007 return false;
6008 }
6009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 final long identity = Binder.clearCallingIdentity();
6011 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006012 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006014 if (DBG) {
6015 log("setNetworkSelectionModeManual: subId: " + subId
6016 + " operator: " + operatorInfo);
6017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6019 } finally {
6020 Binder.restoreCallingIdentity(identity);
6021 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006022 }
shilu84f6e8b2019-12-19 13:58:01 -08006023 /**
6024 * Get the manual network selection
6025 *
6026 * @param subId the id of the subscription.
6027 *
6028 * @return the previously saved user selected PLMN
6029 */
6030 @Override
6031 public String getManualNetworkSelectionPlmn(int subId) {
6032 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006033 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006034 mApp, subId, "getManualNetworkSelectionPlmn");
6035
6036 final long identity = Binder.clearCallingIdentity();
6037 try {
6038 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006039 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006040 }
6041
6042 final Phone phone = getPhone(subId);
6043 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006044 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006045 }
6046 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6047 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6048 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6049 } finally {
6050 Binder.restoreCallingIdentity(identity);
6051 }
6052 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006053
6054 /**
6055 * Scans for available networks.
6056 */
6057 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006058 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6059 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6061 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006062 LocationAccessPolicy.LocationPermissionResult locationResult =
6063 LocationAccessPolicy.checkLocationPermission(mApp,
6064 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6065 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006066 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006067 .setCallingPid(Binder.getCallingPid())
6068 .setCallingUid(Binder.getCallingUid())
6069 .setMethod("getCellNetworkScanResults")
6070 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006071 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6072 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006073 .build());
6074 switch (locationResult) {
6075 case DENIED_HARD:
6076 throw new SecurityException("Not allowed to access scan results -- location");
6077 case DENIED_SOFT:
6078 return null;
6079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080
Pengquan Menga1bb6272018-09-06 09:59:22 -07006081 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 try {
6083 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006084 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 } finally {
6087 Binder.restoreCallingIdentity(identity);
6088 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006089 }
6090
6091 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006092 * Get the call forwarding info, given the call forwarding reason.
6093 */
6094 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006095 public void getCallForwarding(int subId, int callForwardingReason,
6096 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006097 enforceReadPrivilegedPermission("getCallForwarding");
6098 long identity = Binder.clearCallingIdentity();
6099 try {
6100 if (DBG) {
6101 log("getCallForwarding: subId " + subId
6102 + " callForwardingReason" + callForwardingReason);
6103 }
Hall Liu27d24262020-09-18 19:04:59 -07006104
6105 Phone phone = getPhone(subId);
6106 if (phone == null) {
6107 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006108 callback.onError(
6109 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006110 } catch (RemoteException e) {
6111 // ignore
6112 }
6113 return;
6114 }
6115
6116 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6117 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6118 @Override
6119 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6120 try {
6121 callback.onCallForwardingInfoAvailable(info);
6122 } catch (RemoteException e) {
6123 // ignore
6124 }
6125 }
6126
6127 @Override
6128 public void onError(int error) {
6129 try {
6130 callback.onError(error);
6131 } catch (RemoteException e) {
6132 // ignore
6133 }
6134 }
6135 });
6136 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006137 } finally {
6138 Binder.restoreCallingIdentity(identity);
6139 }
6140 }
6141
6142 /**
6143 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6144 * reason, the number to forward, and the timeout before the forwarding is attempted.
6145 */
6146 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006147 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6148 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006149 enforceModifyPermission();
6150 long identity = Binder.clearCallingIdentity();
6151 try {
6152 if (DBG) {
6153 log("setCallForwarding: subId " + subId
6154 + " callForwardingInfo" + callForwardingInfo);
6155 }
Hall Liu27d24262020-09-18 19:04:59 -07006156
6157 Phone phone = getPhone(subId);
6158 if (phone == null) {
6159 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006160 callback.accept(
6161 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006162 } catch (RemoteException e) {
6163 // ignore
6164 }
6165 return;
6166 }
6167
6168 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6169 FunctionalUtils.ignoreRemoteException(callback::accept));
6170
6171 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006172 } finally {
6173 Binder.restoreCallingIdentity(identity);
6174 }
6175 }
6176
6177 /**
Hall Liu27d24262020-09-18 19:04:59 -07006178 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006179 */
6180 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006181 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006182 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006183 long identity = Binder.clearCallingIdentity();
6184 try {
Hall Liu27d24262020-09-18 19:04:59 -07006185 Phone phone = getPhone(subId);
6186 if (phone == null) {
6187 try {
6188 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6189 } catch (RemoteException e) {
6190 // ignore
6191 }
6192 return;
6193 }
SongFerngWang0e767992021-03-31 22:08:45 +08006194 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6195 PersistableBundle c = configManager.getConfigForSubId(subId);
6196 boolean requireUssd = c.getBoolean(
6197 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006198
Shuo Qian4a594052020-01-23 11:59:30 -08006199 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006200 if (requireUssd) {
6201 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6202 getSubscriptionCarrierId(subId));
6203 String newUssdCommand = "";
6204 try {
6205 newUssdCommand = carrierXmlParser.getFeature(
6206 CarrierXmlParser.FEATURE_CALL_WAITING)
6207 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6208 } catch (NullPointerException e) {
6209 loge("Failed to generate USSD number" + e);
6210 }
6211 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6212 mMainThreadHandler, callback, carrierXmlParser,
6213 CarrierXmlParser.SsEntry.SSAction.QUERY);
6214 final String ussdCommand = newUssdCommand;
6215 Executors.newSingleThreadExecutor().execute(() -> {
6216 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6217 });
6218 } else {
6219 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6220 callback::accept);
6221 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6222 }
Shuo Qian4a594052020-01-23 11:59:30 -08006223 } finally {
6224 Binder.restoreCallingIdentity(identity);
6225 }
6226 }
6227
6228 /**
Hall Liu27d24262020-09-18 19:04:59 -07006229 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006230 */
6231 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006232 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006233 enforceModifyPermission();
6234 long identity = Binder.clearCallingIdentity();
6235 try {
Hall Liu27d24262020-09-18 19:04:59 -07006236 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6237
6238 Phone phone = getPhone(subId);
6239 if (phone == null) {
6240 try {
6241 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6242 } catch (RemoteException e) {
6243 // ignore
6244 }
6245 return;
6246 }
6247
SongFerngWang0e767992021-03-31 22:08:45 +08006248 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6249 PersistableBundle c = configManager.getConfigForSubId(subId);
6250 boolean requireUssd = c.getBoolean(
6251 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006252
SongFerngWang0e767992021-03-31 22:08:45 +08006253 if (DBG) log("getCallWaitingStatus: subId " + subId);
6254 if (requireUssd) {
6255 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6256 getSubscriptionCarrierId(subId));
6257 CarrierXmlParser.SsEntry.SSAction ssAction =
6258 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6259 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6260 String newUssdCommand = "";
6261 try {
6262 newUssdCommand = carrierXmlParser.getFeature(
6263 CarrierXmlParser.FEATURE_CALL_WAITING)
6264 .makeCommand(ssAction, null);
6265 } catch (NullPointerException e) {
6266 loge("Failed to generate USSD number" + e);
6267 }
6268 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6269 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6270 final String ussdCommand = newUssdCommand;
6271 Executors.newSingleThreadExecutor().execute(() -> {
6272 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6273 });
6274 } else {
6275 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6276 FunctionalUtils.ignoreRemoteException(callback::accept));
6277
6278 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6279 }
Shuo Qian4a594052020-01-23 11:59:30 -08006280 } finally {
6281 Binder.restoreCallingIdentity(identity);
6282 }
6283 }
6284
6285 /**
yinxub1bed742017-04-17 11:45:04 -07006286 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006287 *
yinxub1bed742017-04-17 11:45:04 -07006288 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006289 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6290 * location related information which will be sent if the caller already possess
6291 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006292 * @param request contains the radio access networks with bands/channels to scan
6293 * @param messenger callback messenger for scan results or errors
6294 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006295 * @return the id of the requested scan which can be used to stop the scan.
6296 */
6297 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006298 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6299 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006300 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6302 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006303 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006304 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6305 if (!renounceFineLocationAccess) {
6306 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6307 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6308 .setCallingPackage(callingPackage)
6309 .setCallingFeatureId(callingFeatureId)
6310 .setCallingPid(Binder.getCallingPid())
6311 .setCallingUid(Binder.getCallingUid())
6312 .setMethod("requestNetworkScan")
6313 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6314 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6315 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6316 .build());
6317 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006318 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006319 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6320 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006321 if (e != null) {
6322 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6323 throw e;
6324 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006325 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006326 return TelephonyScanManager.INVALID_SCAN_ID;
6327 }
6328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 }
Hall Liu912dfd32019-04-25 14:02:26 -07006330 int callingUid = Binder.getCallingUid();
6331 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006332 final long identity = Binder.clearCallingIdentity();
6333 try {
6334 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006335 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006336 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006337 } finally {
6338 Binder.restoreCallingIdentity(identity);
6339 }
yinxu504e1392017-04-12 16:03:22 -07006340 }
6341
Hall Liub2ac8ef2019-02-28 15:56:23 -08006342 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006343 NetworkScanRequest request, int subId, String callingPackage) {
6344 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006345 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6346 boolean hasNetworkScanPermission =
6347 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6348 == PERMISSION_GRANTED;
6349
6350 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6351 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6352 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006353 }
6354
6355 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6356 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006357 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6358 return new SecurityException("Specific channels must not be"
6359 + " scanned without location access.");
6360 }
6361 }
6362 }
6363
Hall Liub2ac8ef2019-02-28 15:56:23 -08006364 return null;
6365 }
6366
yinxu504e1392017-04-12 16:03:22 -07006367 /**
6368 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006369 *
6370 * @param subId id of the subscription
6371 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006372 */
6373 @Override
6374 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6376 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377
Hall Liu912dfd32019-04-25 14:02:26 -07006378 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 final long identity = Binder.clearCallingIdentity();
6380 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006381 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
yinxu504e1392017-04-12 16:03:22 -07006385 }
6386
6387 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006388 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006389 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006390 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006391 */
6392 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006393 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006394 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006395 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006396 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397
6398 final long identity = Binder.clearCallingIdentity();
6399 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006400 if (DBG) log("getAllowedNetworkTypesBitmask");
6401 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6402 int networkTypesBitmask = (result != null ? result[0] : -1);
6403 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6404 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 } finally {
6406 Binder.restoreCallingIdentity(identity);
6407 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006408 }
6409
6410 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006411 * Get the allowed network types for certain reason.
6412 *
6413 * @param subId the id of the subscription.
6414 * @param reason the reason the allowed network type change is taking place
6415 * @return the allowed network types.
6416 */
6417 @Override
6418 public long getAllowedNetworkTypesForReason(int subId,
6419 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006420 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006421 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006422 final long identity = Binder.clearCallingIdentity();
6423 try {
6424 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6425 } finally {
6426 Binder.restoreCallingIdentity(identity);
6427 }
6428 }
6429
6430 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006431 * Enable/Disable E-UTRA-NR Dual Connectivity
6432 * @param subId subscription id of the sim card
6433 * @param nrDualConnectivityState expected NR dual connectivity state
6434 * This can be passed following states
6435 * <ol>
6436 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6437 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6438 * <li>Disable NR dual connectivity and force secondary cell to be released
6439 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6440 * </ol>
6441 * @return operation result.
6442 */
6443 @Override
6444 public int setNrDualConnectivityState(int subId,
6445 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6447 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006448 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006449 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6450 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6451 }
6452
Sooraj Sasindran37444802020-08-11 10:40:43 -07006453 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6454 final long identity = Binder.clearCallingIdentity();
6455 try {
6456 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6457 nrDualConnectivityState, subId,
6458 workSource);
6459 if (DBG) log("enableNRDualConnectivity result: " + result);
6460 return result;
6461 } finally {
6462 Binder.restoreCallingIdentity(identity);
6463 }
6464 }
6465
6466 /**
6467 * Is E-UTRA-NR Dual Connectivity enabled
6468 * @return true if dual connectivity is enabled else false
6469 */
6470 @Override
6471 public boolean isNrDualConnectivityEnabled(int subId) {
6472 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006473 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006474 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006475 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006476 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6477 return false;
6478 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006479 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6480 final long identity = Binder.clearCallingIdentity();
6481 try {
6482 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6483 null, subId, workSource);
6484 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6485 return isEnabled;
6486 } finally {
6487 Binder.restoreCallingIdentity(identity);
6488 }
6489 }
6490
6491 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006492 * Set the allowed network types of the device and
6493 * provide the reason triggering the allowed network change.
6494 *
6495 * @param subId the id of the subscription.
6496 * @param reason the reason the allowed network type change is taking place
6497 * @param allowedNetworkTypes the allowed network types.
6498 * @return true on success; false on any failure.
6499 */
6500 @Override
6501 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006502 @TelephonyManager.AllowedNetworkTypesReason int reason,
6503 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6505 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006506 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006507 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6508 return false;
6509 }
6510 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6511 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006512 return false;
6513 }
6514
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006515 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6516 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6517
6518
6519 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6520 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6521 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006522 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006523
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006524 final long identity = Binder.clearCallingIdentity();
6525 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006526 Boolean success = (Boolean) sendRequest(
6527 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6528 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6529
6530 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6531 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006532 } finally {
6533 Binder.restoreCallingIdentity(identity);
6534 }
6535 }
6536
6537 /**
Miaoa84611c2019-03-15 09:21:10 +08006538 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006539 *
Miaoa84611c2019-03-15 09:21:10 +08006540 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006541 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006542 * @hide
6543 */
6544 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006545 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006546 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006548 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 try {
Miaoa84611c2019-03-15 09:21:10 +08006550 if (phone != null) {
6551 return phone.hasMatchedTetherApnSetting();
6552 } else {
6553 return false;
6554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555 } finally {
6556 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006557 }
Junda Liu475951f2014-11-07 16:45:03 -08006558 }
6559
6560 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006561 * Get the user enabled state of Mobile Data.
6562 *
6563 * TODO: remove and use isUserDataEnabled.
6564 * This can't be removed now because some vendor codes
6565 * calls through ITelephony directly while they should
6566 * use TelephonyManager.
6567 *
6568 * @return true on enabled
6569 */
6570 @Override
6571 public boolean getDataEnabled(int subId) {
6572 return isUserDataEnabled(subId);
6573 }
6574
6575 /**
6576 * Get whether mobile data is enabled per user setting.
6577 *
6578 * There are other factors deciding whether mobile data is actually enabled, but they are
6579 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006580 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006581 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6582 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006583 *
6584 * @return {@code true} if data is enabled else {@code false}
6585 */
6586 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006587 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006588 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006589 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006590 try {
6591 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6592 functionName);
6593 } catch (Exception e) {
6594 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6595 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006596 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006598 mApp, subId, functionName);
6599
Robert Greenwalt646120a2014-05-23 11:54:03 -07006600 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601
6602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 int phoneId = mSubscriptionController.getPhoneId(subId);
6605 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6606 Phone phone = PhoneFactory.getPhone(phoneId);
6607 if (phone != null) {
6608 boolean retVal = phone.isUserDataEnabled();
6609 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6610 return retVal;
6611 } else {
6612 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6613 return false;
6614 }
6615 } finally {
6616 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006617 }
6618 }
6619
6620 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006621 * Checks if the device is capable of mobile data by considering whether whether the
6622 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6623 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006624 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006625 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006626 */
6627 @Override
6628 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006629 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006630 try {
6631 try {
6632 mApp.enforceCallingOrSelfPermission(
6633 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006634 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006635 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006636 try {
6637 mApp.enforceCallingOrSelfPermission(
6638 android.Manifest.permission.READ_PHONE_STATE,
6639 functionName);
6640 } catch (Exception e2) {
6641 mApp.enforceCallingOrSelfPermission(
6642 permission.READ_BASIC_PHONE_STATE, functionName);
6643 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006644 }
6645 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006646 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006648
6649 final long identity = Binder.clearCallingIdentity();
6650 try {
6651 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652 Phone phone = PhoneFactory.getPhone(phoneId);
6653 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006654 boolean retVal;
6655 if (phone.isUsingNewDataStack()) {
Sarah Chin2c094c52022-03-09 13:57:52 -08006656 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006657 } else {
6658 retVal = phone.getDataEnabledSettings().isDataEnabled();
6659 }
6660 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661 return retVal;
6662 } else {
6663 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6664 return false;
6665 }
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006668 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006669 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006670
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006671 /**
6672 * Check if data is enabled for a specific reason
6673 * @param subId Subscription index
6674 * @param reason the reason the data enable change is taking place
6675 * @return {@code true} if the overall data is enabled; {@code false} if not.
6676 */
6677 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006678 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006679 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006680 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006681 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006682 try {
6683 mApp.enforceCallingOrSelfPermission(
6684 android.Manifest.permission.ACCESS_NETWORK_STATE,
6685 functionName);
6686 } catch (Exception e) {
6687 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6688 functionName);
6689 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006690 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006691 try {
6692 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006693 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006694 } catch (Exception e2) {
6695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006696 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006697 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006698 }
6699
6700
6701 final long identity = Binder.clearCallingIdentity();
6702 try {
6703 int phoneId = mSubscriptionController.getPhoneId(subId);
6704 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006705 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006706 + " reason=" + reason);
6707 }
6708 Phone phone = PhoneFactory.getPhone(phoneId);
6709 if (phone != null) {
6710 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006711 if (phone.isUsingNewDataStack()) {
6712 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006713 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006714 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6715 retVal = phone.isUserDataEnabled();
6716 } else {
6717 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6718 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006719 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006720 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006721 return retVal;
6722 } else {
6723 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006724 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006725 + subId + " retVal=false");
6726 }
6727 return false;
6728 }
6729 } finally {
6730 Binder.restoreCallingIdentity(identity);
6731 }
6732 }
6733
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006734 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006735 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006736 // No permission needed; this only lets the caller inspect their own status.
6737 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006738 }
Junda Liu29340342014-07-10 15:23:27 -07006739
6740 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006741 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006742 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006743 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6744 }
6745
6746 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6747 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006748 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006749 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006750 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6751 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006752 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6753 if (cpt == null) {
6754 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006755 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6756 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006757 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006758 }
6759
6760 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006761 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006762 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006763 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006764 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006765 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006766 Phone phone = getPhone(subId);
6767 if (phone == null) {
6768 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6769 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6770 }
6771 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6772 if (cpt == null) {
6773 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006774 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6775 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006776 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006777 }
6778
6779 @Override
6780 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006781 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006782 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6783 }
6784
6785 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006786 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006787 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006788 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006789 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006790 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6791 Phone phone = PhoneFactory.getPhone(phoneId);
6792 if (phone == null) {
6793 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006794 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006795 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6796 if (cpt == null) {
6797 continue;
6798 }
6799 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006800 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6801 break;
6802 }
6803 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006804 return result;
Junda Liu29340342014-07-10 15:23:27 -07006805 }
Derek Tan89e89d42014-07-08 17:00:10 -07006806
6807 @Override
Junda Liue64de782015-04-16 17:19:16 -07006808 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006809 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006810 Phone phone = PhoneFactory.getPhone(phoneId);
6811 if (phone == null) {
6812 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006813 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006814 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6815 if (cpt == null) {
6816 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006817 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006818 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006819 }
6820
Amith Yamasani6e118872016-02-19 12:53:51 -08006821 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006822 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006823 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006824 Phone phone = PhoneFactory.getPhone(phoneId);
6825 if (phone == null) {
6826 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006827 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006828 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6829 if (cpt == null) {
6830 return Collections.emptyList();
6831 }
6832 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006833 }
6834
chen xuf7e9fe82019-05-09 19:31:02 -07006835 @Override
6836 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006837 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006838 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006839 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006840 try {
6841 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6842 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6843 }
6844 } finally {
6845 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006846 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006847 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006848 }
6849
Rambo Wang6812ffb2022-03-15 16:54:17 -07006850 @Override
6851 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6852 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6853
6854 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6855 if (phone == null) {
6856 return null;
6857 }
6858 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6859 if (cpt == null) {
6860 return null;
6861 }
6862 return cpt.getCarrierServicePackageName();
6863 }
6864
Wink Savilleb564aae2014-10-23 10:18:09 -07006865 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006866 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006867 UiccPort port = phone == null ? null : phone.getUiccPort();
6868 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006869 return null;
6870 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006871 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006872 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006873 return null;
6874 }
6875 return iccId;
6876 }
6877
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006878 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006879 public void setCallComposerStatus(int subId, int status) {
6880 enforceModifyPermission();
6881
6882 final long identity = Binder.clearCallingIdentity();
6883 try {
6884 Phone phone = getPhone(subId);
6885 if (phone != null) {
6886 Phone defaultPhone = phone.getImsPhone();
6887 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6888 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6889 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006890 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6891 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006892 }
6893 }
Shuo Qian284ae752020-12-22 19:10:14 -08006894 } catch (ImsException e) {
6895 throw new ServiceSpecificException(e.getCode());
6896 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006897 Binder.restoreCallingIdentity(identity);
6898 }
6899 }
6900
6901 @Override
6902 public int getCallComposerStatus(int subId) {
6903 enforceReadPrivilegedPermission("getCallComposerStatus");
6904
6905 final long identity = Binder.clearCallingIdentity();
6906 try {
6907 Phone phone = getPhone(subId);
6908 if (phone != null) {
6909 Phone defaultPhone = phone.getImsPhone();
6910 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6911 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6912 return imsPhone.getCallComposerStatus();
6913 }
6914 }
6915 } finally {
6916 Binder.restoreCallingIdentity(identity);
6917 }
6918 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6919 }
6920
6921 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006922 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6923 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006924 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006925 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927 final long identity = Binder.clearCallingIdentity();
6928 try {
6929 final String iccId = getIccId(subId);
6930 final Phone phone = getPhone(subId);
6931 if (phone == null) {
6932 return false;
6933 }
6934 final String subscriberId = phone.getSubscriberId();
6935
6936 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006937 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006938 + subscriberId + " to " + number);
6939 }
6940
6941 if (TextUtils.isEmpty(iccId)) {
6942 return false;
6943 }
6944
6945 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6946
6947 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6948 if (alphaTag == null) {
6949 editor.remove(alphaTagPrefKey);
6950 } else {
6951 editor.putString(alphaTagPrefKey, alphaTag);
6952 }
6953
6954 // Record both the line number and IMSI for this ICCID, since we need to
6955 // track all merged IMSIs based on line number
6956 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6957 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6958 if (number == null) {
6959 editor.remove(numberPrefKey);
6960 editor.remove(subscriberPrefKey);
6961 } else {
6962 editor.putString(numberPrefKey, number);
6963 editor.putString(subscriberPrefKey, subscriberId);
6964 }
6965
6966 editor.commit();
6967 return true;
6968 } finally {
6969 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006970 }
Derek Tan7226c842014-07-02 17:42:23 -07006971 }
6972
6973 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006974 public String getLine1NumberForDisplay(int subId, String callingPackage,
6975 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006976 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006977 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006978 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006979 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006980 return null;
6981 }
Derek Tan97ebb422014-09-05 16:55:38 -07006982
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006983 final long identity = Binder.clearCallingIdentity();
6984 try {
6985 String iccId = getIccId(subId);
6986 if (iccId != null) {
6987 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6988 if (DBG_MERGE) {
6989 log("getLine1NumberForDisplay returning "
6990 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6991 }
6992 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6995 return null;
6996 } finally {
6997 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006998 }
Derek Tan7226c842014-07-02 17:42:23 -07006999 }
7000
7001 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007002 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7003 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007005 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007006 return null;
7007 }
Derek Tan97ebb422014-09-05 16:55:38 -07007008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007009 final long identity = Binder.clearCallingIdentity();
7010 try {
7011 String iccId = getIccId(subId);
7012 if (iccId != null) {
7013 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7014 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7015 }
7016 return null;
7017 } finally {
7018 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007019 }
Derek Tan7226c842014-07-02 17:42:23 -07007020 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007021
7022 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007023 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7024 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007025 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7026 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007028 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007029 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007030 return null;
7031 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007032
Jordan Liub49b04b2019-05-06 14:45:15 -07007033 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7034 // the process, where TelephonyManager was instantiated.
7035 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007036 final long identity = Binder.clearCallingIdentity();
7037 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007038 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007039 final TelephonyManager tele = TelephonyManager.from(context);
7040 final SubscriptionManager sub = SubscriptionManager.from(context);
7041
7042 // Figure out what subscribers are currently active
7043 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044
Jordan Liub49b04b2019-05-06 14:45:15 -07007045 // Only consider subs which match the current subId
7046 // This logic can be simplified. See b/131189269 for progress.
7047 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007048 activeSubscriberIds.add(tele.getSubscriberId(subId));
7049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050
7051 // First pass, find a number override for an active subscriber
7052 String mergeNumber = null;
7053 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7054 for (String key : prefs.keySet()) {
7055 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7056 final String subscriberId = (String) prefs.get(key);
7057 if (activeSubscriberIds.contains(subscriberId)) {
7058 final String iccId = key.substring(
7059 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7060 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7061 mergeNumber = (String) prefs.get(numberKey);
7062 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007063 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007064 + " for active subscriber " + subscriberId);
7065 }
7066 if (!TextUtils.isEmpty(mergeNumber)) {
7067 break;
7068 }
7069 }
7070 }
7071 }
7072
7073 // Shortcut when no active merged subscribers
7074 if (TextUtils.isEmpty(mergeNumber)) {
7075 return null;
7076 }
7077
7078 // Second pass, find all subscribers under that line override
7079 final ArraySet<String> result = new ArraySet<>();
7080 for (String key : prefs.keySet()) {
7081 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7082 final String number = (String) prefs.get(key);
7083 if (mergeNumber.equals(number)) {
7084 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7085 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7086 final String subscriberId = (String) prefs.get(subscriberKey);
7087 if (!TextUtils.isEmpty(subscriberId)) {
7088 result.add(subscriberId);
7089 }
7090 }
7091 }
7092 }
7093
7094 final String[] resultArray = result.toArray(new String[result.size()]);
7095 Arrays.sort(resultArray);
7096 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007097 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007098 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7099 }
7100 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007101 } finally {
7102 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007103 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007104 }
7105
7106 @Override
zoey chen38003472019-12-13 17:16:31 +08007107 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7108 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007109
7110 final long identity = Binder.clearCallingIdentity();
7111 try {
7112 final TelephonyManager telephonyManager = mApp.getSystemService(
7113 TelephonyManager.class);
7114 String subscriberId = telephonyManager.getSubscriberId(subId);
7115 if (subscriberId == null) {
7116 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007117 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007118 + subId);
7119 }
7120 return null;
7121 }
7122
7123 final SubscriptionInfo info = SubscriptionController.getInstance()
7124 .getSubscriptionInfo(subId);
7125 final ParcelUuid groupUuid = info.getGroupUuid();
7126 // If it doesn't belong to any group, return just subscriberId of itself.
7127 if (groupUuid == null) {
7128 return new String[]{subscriberId};
7129 }
7130
7131 // Get all subscriberIds from the group.
7132 final List<String> mergedSubscriberIds = new ArrayList<>();
7133 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007134 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007135 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007136 for (SubscriptionInfo subInfo : groupInfos) {
7137 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7138 if (subscriberId != null) {
7139 mergedSubscriberIds.add(subscriberId);
7140 }
7141 }
7142
7143 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7144 } finally {
7145 Binder.restoreCallingIdentity(identity);
7146
7147 }
7148 }
7149
7150 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007151 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007152 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007153 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154
7155 final long identity = Binder.clearCallingIdentity();
7156 try {
7157 final Phone phone = getPhone(subId);
7158 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7159 } finally {
7160 Binder.restoreCallingIdentity(identity);
7161 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007162 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007163
7164 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007165 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007166 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7167 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007168 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7169 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170
7171 final long identity = Binder.clearCallingIdentity();
7172 try {
7173 final Phone phone = getPhone(subId);
7174 if (phone == null) {
7175 return false;
7176 }
7177 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7178 cdmaNonRoamingList);
7179 } finally {
7180 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007181 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007182 }
7183
7184 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007185 @Deprecated
7186 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7187 enforceModifyPermission();
7188
7189 int returnValue = 0;
7190 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007191 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007192 if(result.exception == null) {
7193 if (result.result != null) {
7194 byte[] responseData = (byte[])(result.result);
7195 if(responseData.length > oemResp.length) {
7196 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7197 responseData.length + "bytes. Buffer Size is " +
7198 oemResp.length + "bytes.");
7199 }
7200 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7201 returnValue = responseData.length;
7202 }
7203 } else {
7204 CommandException ex = (CommandException) result.exception;
7205 returnValue = ex.getCommandError().ordinal();
7206 if(returnValue > 0) returnValue *= -1;
7207 }
7208 } catch (RuntimeException e) {
7209 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7210 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7211 if(returnValue > 0) returnValue *= -1;
7212 }
7213
7214 return returnValue;
7215 }
7216
7217 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007218 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007219 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007220 try {
7221 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007222 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007223 mApp, phone.getSubId(), "getRadioAccessFamily");
7224 } catch (SecurityException e) {
7225 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7226 throw e;
7227 }
chen xub97461a2018-10-26 14:17:57 -07007228 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007229 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007230 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232 final long identity = Binder.clearCallingIdentity();
7233 try {
chen xub97461a2018-10-26 14:17:57 -07007234 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007235 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007236 mApp, phone.getSubId(), "getRadioAccessFamily");
7237 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007238 } finally {
7239 Binder.restoreCallingIdentity(identity);
7240 }
chen xub97461a2018-10-26 14:17:57 -07007241 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007242 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007243
7244 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007245 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007246 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007247 try {
7248 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7249 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007250 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007251 }
7252 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007253 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007254 }
7255 RoleManager rm = mApp.getSystemService(RoleManager.class);
7256 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7257 if (!dialerRoleHolders.contains(callingPackage)) {
7258 throw new SecurityException("App must be the dialer role holder to"
7259 + " upload a call composer pic");
7260 }
7261
7262 Executors.newSingleThreadExecutor().execute(() -> {
7263 ByteArrayOutputStream output = new ByteArrayOutputStream(
7264 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7265 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7266 boolean readUntilEnd = false;
7267 int totalBytesRead = 0;
7268 byte[] buffer = new byte[16 * 1024];
7269 while (true) {
7270 int numRead;
7271 try {
7272 numRead = input.read(buffer);
7273 } catch (IOException e) {
7274 try {
7275 fd.checkError();
7276 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7277 null);
7278 } catch (IOException e1) {
7279 // This means that the other side closed explicitly with an error. If this
7280 // happens, log and ignore.
7281 loge("Remote end of call composer picture pipe closed: " + e1);
7282 }
7283 break;
7284 }
7285 if (numRead == -1) {
7286 readUntilEnd = true;
7287 break;
7288 }
7289 totalBytesRead += numRead;
7290 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7291 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7292 try {
7293 input.close();
7294 } catch (IOException e) {
7295 // ignore
7296 }
7297 break;
7298 }
7299 output.write(buffer, 0, numRead);
7300 }
7301 // Generally, the remote end will close the file descriptors. The only case where we
7302 // close is above, where the picture size is too big.
7303
7304 try {
7305 fd.checkError();
7306 } catch (IOException e) {
7307 loge("Remote end for call composer closed with an error: " + e);
7308 return;
7309 }
7310
Hall Liuaa4211e2021-01-20 15:43:39 -08007311 if (!readUntilEnd) {
7312 loge("Did not finish reading entire image; aborting");
7313 return;
7314 }
Hall Liu82694d52020-12-11 18:22:04 -08007315
Hall Liuaa4211e2021-01-20 15:43:39 -08007316 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7317 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7318 new CallComposerPictureTransfer.Factory() {},
7319 imageData,
7320 (result) -> {
7321 if (result.first != null) {
7322 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7323 Bundle outputResult = new Bundle();
7324 outputResult.putParcelable(
7325 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7326 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7327 outputResult);
7328 } else {
7329 callback.send(result.second, null);
7330 }
7331 }
7332 );
Hall Liu82694d52020-12-11 18:22:04 -08007333 });
7334 }
7335
7336 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007337 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007338 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007339 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340
7341 final long identity = Binder.clearCallingIdentity();
7342 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007343 ImsManager.getInstance(defaultPhone.getContext(),
7344 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345 } finally {
7346 Binder.restoreCallingIdentity(identity);
7347 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007348 }
7349
7350 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007351 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007352 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007353 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7354 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007355 return false;
7356 }
Svet Ganovb320e182015-04-16 12:30:10 -07007357
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358 final long identity = Binder.clearCallingIdentity();
7359 try {
7360 // Check the user preference and the system-level IMS setting. Even if the user has
7361 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7362 // In the long run, we may instead need to check if there exists a connection service
7363 // which can support video calling.
7364 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007365 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 return imsManager.isVtEnabledByPlatform()
7367 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7368 && imsManager.isVtEnabledByUser();
7369 } finally {
7370 Binder.restoreCallingIdentity(identity);
7371 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007372 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007373
Andrew Leea1239f22015-03-02 17:44:07 -08007374 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007375 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7376 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007378 mApp, subId, callingPackage, callingFeatureId,
7379 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380 return false;
7381 }
7382
7383 final long identity = Binder.clearCallingIdentity();
7384 try {
7385 CarrierConfigManager configManager =
7386 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007387 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7389 } finally {
7390 Binder.restoreCallingIdentity(identity);
7391 }
Andrew Leea1239f22015-03-02 17:44:07 -08007392 }
7393
7394 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007395 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007397 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 return false;
7399 }
7400
7401 final long identity = Binder.clearCallingIdentity();
7402 try {
7403 CarrierConfigManager configManager =
7404 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007405 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7407 } finally {
7408 Binder.restoreCallingIdentity(identity);
7409 }
Andrew Leea1239f22015-03-02 17:44:07 -08007410 }
7411
Andrew Lee9431b832015-03-09 18:46:45 -07007412 @Override
7413 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007414 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007415 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007416 }
7417
7418 @Override
7419 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420 final long identity = Binder.clearCallingIdentity();
7421 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007422 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007423 } finally {
7424 Binder.restoreCallingIdentity(identity);
7425 }
Andrew Lee9431b832015-03-09 18:46:45 -07007426 }
7427
Hall Liuf6668912018-10-31 17:05:23 -07007428 /**
7429 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7430 * support for the feature and device firmware support.
7431 *
7432 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7433 */
7434 @Override
7435 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007437 final Phone phone = getPhone(subscriptionId);
7438 if (phone == null) {
7439 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7440 return false;
7441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007443 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7445 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007446 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 return isCarrierSupported && isDeviceSupported;
7448 } finally {
7449 Binder.restoreCallingIdentity(identity);
7450 }
Hall Liu98187582018-01-22 19:15:32 -08007451 }
7452
Hall Liuf6668912018-10-31 17:05:23 -07007453 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007454 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7455 * RTT setting, will return true if the device and carrier both support RTT.
7456 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007457 */
7458 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 final long identity = Binder.clearCallingIdentity();
7460 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007461 boolean isRttSupported = isRttSupported(subscriptionId);
7462 boolean isUserRttSettingOn = Settings.Secure.getInt(
7463 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7464 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7465 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7466 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 } finally {
7468 Binder.restoreCallingIdentity(identity);
7469 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007470 }
7471
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007472 @Deprecated
7473 @Override
7474 public String getDeviceId(String callingPackage) {
7475 return getDeviceIdWithFeature(callingPackage, null);
7476 }
7477
Sanket Padawe7310cc72015-01-14 09:53:20 -08007478 /**
7479 * Returns the unique device ID of phone, for example, the IMEI for
7480 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7481 *
7482 * <p>Requires Permission:
7483 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7484 */
7485 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007486 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007487 try {
7488 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7489 } catch (SecurityException se) {
7490 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7491 throw new SecurityException("Package " + callingPackage + " does not belong to "
7492 + Binder.getCallingUid());
7493 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007494 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007495 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007496 return null;
7497 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007498 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007499 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007500 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007501 return null;
7502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503
7504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 return phone.getDeviceId();
7507 } finally {
7508 Binder.restoreCallingIdentity(identity);
7509 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007510 }
7511
Ping Sunc67b7c22016-03-02 19:16:45 +08007512 /**
7513 * {@hide}
7514 * Returns the IMS Registration Status on a particular subid
7515 *
7516 * @param subId
7517 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007518 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007519 Phone phone = getPhone(subId);
7520 if (phone != null) {
7521 return phone.isImsRegistered();
7522 } else {
7523 return false;
7524 }
7525 }
7526
Santos Cordon7a1885b2015-02-03 11:15:19 -08007527 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007528 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007529 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007531 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007532 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7533 }
7534 final long identity = Binder.clearCallingIdentity();
7535 try {
7536 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7537 } finally {
7538 Binder.restoreCallingIdentity(identity);
7539 }
7540 }
7541
7542 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007543 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007544 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007545 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007546 mApp,
7547 subscriptionId,
7548 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007549 final long identity = Binder.clearCallingIdentity();
7550 try {
7551 Phone phone = getPhone(subscriptionId);
7552 if (phone == null) {
7553 return null;
7554 }
7555 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
7558 }
7559 }
7560
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007561 /**
7562 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007563 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007564 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 final long identity = Binder.clearCallingIdentity();
7566 try {
7567 Phone phone = getPhone(subId);
7568 if (phone != null) {
7569 return phone.isWifiCallingEnabled();
7570 } else {
7571 return false;
7572 }
7573 } finally {
7574 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007575 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007576 }
7577
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007578 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007579 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007580 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007581 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007582 final long identity = Binder.clearCallingIdentity();
7583 try {
7584 Phone phone = getPhone(subId);
7585 if (phone != null) {
7586 return phone.isVideoEnabled();
7587 } else {
7588 return false;
7589 }
7590 } finally {
7591 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007592 }
7593 }
7594
7595 /**
7596 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7597 * defined in {@link ImsRegistrationImplBase}.
7598 */
7599 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 final long identity = Binder.clearCallingIdentity();
7601 try {
7602 Phone phone = getPhone(subId);
7603 if (phone != null) {
7604 return phone.getImsRegistrationTech();
7605 } else {
7606 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7607 }
7608 } finally {
7609 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007610 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007611 }
7612
Stuart Scott8eef64f2015-04-08 15:13:54 -07007613 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007614 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007615 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007616 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7617 return;
7618 }
Kai Shif70f46f2021-03-03 13:59:46 -08007619 Phone defaultPhone = getDefaultPhone();
7620 if (defaultPhone != null) {
7621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7622 mApp, getDefaultPhone().getSubId(), "factoryReset");
7623 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007624 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007625
Svet Ganovcc087f82015-05-12 20:35:54 -07007626 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007627 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7628 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007629 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007630 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007631 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007632 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007633 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007634 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007635 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007636 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007637 // There has been issues when Sms raw table somehow stores orphan
7638 // fragments. They lead to garbled message when new fragments come
7639 // in and combined with those stale ones. In case this happens again,
7640 // user can reset all network settings which will clean up this table.
7641 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007642 // Clean up IMS settings as well here.
7643 int slotId = getSlotIndex(subId);
7644 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7645 ImsManager.getInstance(mApp, slotId).factoryReset();
7646 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007647
Kai Shif70f46f2021-03-03 13:59:46 -08007648 if (defaultPhone == null) {
7649 return;
7650 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007651 // Erase modem config if erase modem on network setting is enabled.
7652 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7653 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7654 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007655 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007656 }
Kai Shif70f46f2021-03-03 13:59:46 -08007657
7658 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007659 } finally {
7660 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007661 }
7662 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007663
SongFerngWangfd89b102021-05-27 22:44:54 +08007664 @VisibleForTesting
7665 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7666 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7667 return;
7668 }
7669 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7670 RILConstants.PREFERRED_NETWORK_MODE);
7671 SubscriptionManager.setSubscriptionProperty(subId,
7672 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7673 "user=" + defaultNetworkType);
7674 phone.loadAllowedNetworksFromSubscriptionDatabase();
7675 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7676 defaultNetworkType, null);
7677 }
7678
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007679 private void cleanUpSmsRawTable(Context context) {
7680 ContentResolver resolver = context.getContentResolver();
7681 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7682 resolver.delete(uri, null, null);
7683 }
7684
Narayan Kamath1c496c22015-04-16 14:40:19 +01007685 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007686 public String getSimLocaleForSubscriber(int subId) {
7687 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7688 final Phone phone = getPhone(subId);
7689 if (phone == null) {
7690 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007691 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 final long identity = Binder.clearCallingIdentity();
7694 try {
chen xu5d3637b2019-01-21 23:31:38 -08007695 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007696 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007697 if (info == null) {
7698 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7699 return null;
7700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 // Try and fetch the locale from the carrier properties or from the SIM language
7702 // preferences (EF-PL and EF-LI)...
7703 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007704 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007705 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7706 if (localeFromDefaultSim != null) {
7707 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7708 if (DBG) log("Using locale from subId: " + subId + " locale: "
7709 + localeFromDefaultSim);
7710 return localeFromDefaultSim.toLanguageTag();
7711 } else {
7712 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007713 }
7714 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716 // The SIM language preferences only store a language (e.g. fr = French), not an
7717 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7718 // the SIM and carrier preferences does not include a country we add the country
7719 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007720 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007721 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007722 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 return mccLocale.toLanguageTag();
7724 }
7725
7726 if (DBG) log("No locale found - returning null");
7727 return null;
7728 } finally {
7729 Binder.restoreCallingIdentity(identity);
7730 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007731 }
7732
7733 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007734 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007735 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007736 }
7737
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007738 /**
7739 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7740 */
7741 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007742 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007743 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007744 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007745
Gary Jian3aa9a762022-01-24 16:41:19 +08007746 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7747 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007748
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007749 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007750 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7751 * representing the state of the modem.
7752 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007753 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7754 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007755 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007756 */
7757 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007758 public void requestModemActivityInfo(ResultReceiver result) {
7759 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007760 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761
7762 final long identity = Binder.clearCallingIdentity();
7763 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007764 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007765 } finally {
7766 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007767 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007768 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007769
Siddharth Rayb8114062018-06-17 15:02:38 -07007770 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7771 // less than total activity duration.
7772 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7773 if (info == null) {
7774 return false;
7775 }
7776 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007777 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7778 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7779
Siddharth Rayb8114062018-06-17 15:02:38 -07007780 return (info.isValid()
7781 && (info.getSleepTimeMillis() <= activityDurationMs)
7782 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007783 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007784 && (totalTxTimeMs <= activityDurationMs));
7785 }
7786
Gary Jian3aa9a762022-01-24 16:41:19 +08007787 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7788 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7789 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7790 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7791
7792 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7793 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7794 }
7795
7796 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7797 mLastModemActivityInfo.setReceiveTimeMillis(
7798 rat,
7799 freq,
7800 info.getReceiveTimeMillis(rat, freq)
7801 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7802 }
7803
7804 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7805 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7806 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7807 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7808
7809 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7810 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7811 }
7812 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7813 mLastModemActivityInfo.setReceiveTimeMillis(
7814 rat,
7815 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7816 }
7817
7818 /**
7819 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7820 * @param info recent ModemActivityInfo
7821 */
7822 private void mergeModemActivityInfo(ModemActivityInfo info) {
7823 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7824 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7825 boolean matched;
7826 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7827 matched = false;
7828 int rat = info.getSpecificInfoRat(i);
7829 int freq = info.getSpecificInfoFrequencyRange(i);
7830 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7831 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7832 //if it already exists
7833 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7834 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7835 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7836 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7837 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7838 updateLastModemActivityInfo(info, rat, freq);
7839 matched = true;
7840 }
7841 } else {
7842 updateLastModemActivityInfo(info, rat);
7843 matched = true;
7844 }
7845 }
7846 }
7847
7848 if (!matched) {
7849 mDeltaSpecificInfo =
7850 new ActivityStatsTechSpecificInfo(
7851 rat,
7852 freq,
7853 info.getTransmitTimeMillis(rat, freq),
7854 (int) info.getReceiveTimeMillis(rat, freq));
7855 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7856 }
7857 }
7858 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7859 mLastModemActivitySpecificInfo =
7860 new ActivityStatsTechSpecificInfo[merged.size()];
7861 merged.toArray(mLastModemActivitySpecificInfo);
7862
7863 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7864 mLastModemActivityInfo.setSleepTimeMillis(
7865 info.getSleepTimeMillis()
7866 + mLastModemActivityInfo.getSleepTimeMillis());
7867 mLastModemActivityInfo.setIdleTimeMillis(
7868 info.getIdleTimeMillis()
7869 + mLastModemActivityInfo.getIdleTimeMillis());
7870 }
7871
Jack Yu85bd38a2015-11-09 11:34:32 -08007872 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007873 * Returns the service state information on specified subscription.
7874 */
7875 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007876 public ServiceState getServiceStateForSubscriber(int subId,
7877 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7878 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007880 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007881 return null;
7882 }
7883
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007884 boolean hasFinePermission = false;
7885 boolean hasCoarsePermission = false;
7886 if (!renounceFineLocationAccess) {
7887 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7888 LocationAccessPolicy.checkLocationPermission(mApp,
7889 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7890 .setCallingPackage(callingPackage)
7891 .setCallingFeatureId(callingFeatureId)
7892 .setCallingPid(Binder.getCallingPid())
7893 .setCallingUid(Binder.getCallingUid())
7894 .setMethod("getServiceStateForSubscriber")
7895 .setLogAsInfo(true)
7896 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7897 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7898 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7899 .build());
7900 hasFinePermission =
7901 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7902 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007903
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007904 if (!renounceCoarseLocationAccess) {
7905 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7906 LocationAccessPolicy.checkLocationPermission(mApp,
7907 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7908 .setCallingPackage(callingPackage)
7909 .setCallingFeatureId(callingFeatureId)
7910 .setCallingPid(Binder.getCallingPid())
7911 .setCallingUid(Binder.getCallingUid())
7912 .setMethod("getServiceStateForSubscriber")
7913 .setLogAsInfo(true)
7914 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7915 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7916 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7917 .build());
7918 hasCoarsePermission =
7919 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7920 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007921
Jack Yu479f40e2020-10-27 21:29:25 -07007922 final Phone phone = getPhone(subId);
7923 if (phone == null) {
7924 return null;
7925 }
7926
Jordan Liu0f2bc442020-11-18 16:47:37 -08007927 final long identity = Binder.clearCallingIdentity();
7928
Jack Yu479f40e2020-10-27 21:29:25 -07007929 boolean isCallingPackageDataService = phone.getDataServicePackages()
7930 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007932 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7933 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7934 Rlog.d(LOG_TAG,
7935 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7936 return null;
7937 }
7938
Hall Liuf19c44f2018-11-27 14:38:17 -08007939 ServiceState ss = phone.getServiceState();
7940
7941 // Scrub out the location info in ServiceState depending on what level of access
7942 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007943 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007944 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7945 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007946 } finally {
7947 Binder.restoreCallingIdentity(identity);
7948 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007949 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007950
7951 /**
7952 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7953 *
7954 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7955 * voicemail ringtone.
7956 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7957 * PhoneAccount.
7958 */
7959 @Override
7960 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961 final long identity = Binder.clearCallingIdentity();
7962 try {
7963 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7964 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007965 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007966 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7969 } finally {
7970 Binder.restoreCallingIdentity(identity);
7971 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007972 }
7973
7974 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007975 * Sets the per-account voicemail ringtone.
7976 *
7977 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7978 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7979 *
7980 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7981 * voicemail ringtone.
7982 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7983 * PhoneAccount.
7984 */
7985 @Override
7986 public void setVoicemailRingtoneUri(String callingPackage,
7987 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007988 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007989 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007990 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7991 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7993 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7994 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996
7997 final long identity = Binder.clearCallingIdentity();
7998 try {
7999 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8000 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008001 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008002 }
8003 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8004 } finally {
8005 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008006 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008007 }
8008
8009 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008010 * Returns whether vibration is set for voicemail notification in Phone settings.
8011 *
8012 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8013 * voicemail vibration setting.
8014 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8015 */
8016 @Override
8017 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018 final long identity = Binder.clearCallingIdentity();
8019 try {
8020 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8021 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008022 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008023 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008025 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8026 } finally {
8027 Binder.restoreCallingIdentity(identity);
8028 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008029 }
8030
Youhan Wange64578a2016-05-02 15:32:42 -07008031 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008032 * Sets the per-account voicemail vibration.
8033 *
8034 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8035 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8036 *
8037 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8038 * voicemail vibration setting.
8039 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8040 * specific PhoneAccount.
8041 */
8042 @Override
8043 public void setVoicemailVibrationEnabled(String callingPackage,
8044 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008045 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008046 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008047 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8048 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8050 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8051 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008052 }
8053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 final long identity = Binder.clearCallingIdentity();
8055 try {
8056 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8057 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008058 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008059 }
8060 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8061 } finally {
8062 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008063 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008064 }
8065
8066 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008067 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8068 *
8069 * @throws SecurityException if the caller does not have the required permission
8070 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008071 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008072 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008073 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008074 }
8075
8076 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008077 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8078 * permission.
8079 *
8080 * @throws SecurityException if the caller does not have the required permission
8081 */
8082 private void enforceSendSmsPermission() {
8083 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8084 }
8085
8086 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008087 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008088 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008089 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008090 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008091 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008092 final long identity = Binder.clearCallingIdentity();
8093 try {
8094 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008095 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008096 if (componentName == null) {
8097 throw new SecurityException(
8098 "Caller not current active visual voicemail package[null]");
8099 }
8100 String vvmPackage = componentName.getPackageName();
8101 if (!callingPackage.equals(vvmPackage)) {
8102 throw new SecurityException("Caller not current active visual voicemail package["
8103 + vvmPackage + "]");
8104 }
8105 } finally {
8106 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008107 }
8108 }
8109
8110 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008111 * Return the application ID for the app type.
8112 *
8113 * @param subId the subscription ID that this request applies to.
8114 * @param appType the uicc app type.
8115 * @return Application ID for specificied app type, or null if no uicc.
8116 */
8117 @Override
8118 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008119 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008120 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121
8122 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008123 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 if (phone == null) {
8125 return null;
8126 }
8127 String aid = null;
8128 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008129 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008130 .getApplicationByType(appType).getAid();
8131 } catch (Exception e) {
8132 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8133 }
8134 return aid;
8135 } finally {
8136 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008137 }
Youhan Wange64578a2016-05-02 15:32:42 -07008138 }
8139
Youhan Wang4001d252016-05-11 10:29:41 -07008140 /**
8141 * Return the Electronic Serial Number.
8142 *
8143 * @param subId the subscription ID that this request applies to.
8144 * @return ESN or null if error.
8145 */
8146 @Override
8147 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008148 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008149 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008150
8151 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008152 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 if (phone == null) {
8154 return null;
8155 }
8156 String esn = null;
8157 try {
8158 esn = phone.getEsn();
8159 } catch (Exception e) {
8160 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8161 }
8162 return esn;
8163 } finally {
8164 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008165 }
Youhan Wang4001d252016-05-11 10:29:41 -07008166 }
8167
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008168 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008169 * Return the Preferred Roaming List Version.
8170 *
8171 * @param subId the subscription ID that this request applies to.
8172 * @return PRLVersion or null if error.
8173 */
8174 @Override
8175 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008176 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008177 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008178
8179 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008180 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008181 if (phone == null) {
8182 return null;
8183 }
8184 String cdmaPrlVersion = null;
8185 try {
8186 cdmaPrlVersion = phone.getCdmaPrlVersion();
8187 } catch (Exception e) {
8188 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8189 }
8190 return cdmaPrlVersion;
8191 } finally {
8192 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008193 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008194 }
8195
8196 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008197 * Get snapshot of Telephony histograms
8198 * @return List of Telephony histograms
8199 * @hide
8200 */
8201 @Override
8202 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8204 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008205
8206 final long identity = Binder.clearCallingIdentity();
8207 try {
8208 return RIL.getTelephonyRILTimingHistograms();
8209 } finally {
8210 Binder.restoreCallingIdentity(identity);
8211 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008212 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008213
8214 /**
8215 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008216 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8217 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008218 * Require system privileges. In the future we may add this to carrier APIs.
8219 *
Michele Berionne482f8202018-11-27 18:57:59 -08008220 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008221 */
8222 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008223 @TelephonyManager.SetCarrierRestrictionResult
8224 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008225 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008226 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008227
Michele Berionne482f8202018-11-27 18:57:59 -08008228 if (carrierRestrictionRules == null) {
8229 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008230 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232 final long identity = Binder.clearCallingIdentity();
8233 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008234 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008235 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236 } finally {
8237 Binder.restoreCallingIdentity(identity);
8238 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008239 }
8240
8241 /**
8242 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008243 * Get the allowed carrier list and the excluded carrier list, including the priority between
8244 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008245 * Require system privileges. In the future we may add this to carrier APIs.
8246 *
Michele Berionne482f8202018-11-27 18:57:59 -08008247 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008248 */
8249 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008250 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008251 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008252 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008253
8254 final long identity = Binder.clearCallingIdentity();
8255 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008256 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8257 if (response instanceof CarrierRestrictionRules) {
8258 return (CarrierRestrictionRules) response;
8259 }
8260 // Response is an Exception of some kind,
8261 // which is signalled to the user as a NULL retval
8262 return null;
8263 } catch (Exception e) {
8264 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8265 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008266 } finally {
8267 Binder.restoreCallingIdentity(identity);
8268 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008269 }
8270
fionaxu59545b42016-05-25 15:53:37 -07008271 /**
fionaxu59545b42016-05-25 15:53:37 -07008272 * Action set from carrier signalling broadcast receivers to enable/disable radio
8273 * @param subId the subscription ID that this action applies to.
8274 * @param enabled control enable or disable radio.
8275 * {@hide}
8276 */
8277 @Override
8278 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8279 enforceModifyPermission();
8280 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281
8282 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008283 if (phone == null) {
8284 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8285 return;
8286 }
8287 try {
8288 phone.carrierActionSetRadioEnabled(enabled);
8289 } catch (Exception e) {
8290 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008291 } finally {
8292 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008293 }
8294 }
8295
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008296 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008297 * Enable or disable Voice over NR (VoNR)
8298 * @param subId the subscription ID that this action applies to.
8299 * @param enabled enable or disable VoNR.
8300 * @return operation result.
8301 */
8302 @Override
8303 public int setVoNrEnabled(int subId, boolean enabled) {
8304 enforceModifyPermission();
8305 final Phone phone = getPhone(subId);
8306
8307 final long identity = Binder.clearCallingIdentity();
8308 if (phone == null) {
8309 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8310 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8311 }
8312
8313 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8314 try {
8315 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8316 workSource);
8317 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008318
8319 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8320 if (DBG) {
8321 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8322 }
8323 SubscriptionManager.setSubscriptionProperty(
8324 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8325 (enabled ? "1" : "0"));
8326 }
8327
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008328 return result;
8329 } finally {
8330 Binder.restoreCallingIdentity(identity);
8331 }
8332 }
8333
8334 /**
8335 * Is voice over NR enabled
8336 * @return true if VoNR is enabled else false
8337 */
8338 @Override
8339 public boolean isVoNrEnabled(int subId) {
8340 enforceReadPrivilegedPermission("isVoNrEnabled");
8341 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8342 final long identity = Binder.clearCallingIdentity();
8343 try {
8344 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8345 null, subId, workSource);
8346 if (DBG) log("isVoNrEnabled: " + isEnabled);
8347 return isEnabled;
8348 } finally {
8349 Binder.restoreCallingIdentity(identity);
8350 }
8351 }
8352
8353 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008354 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8355 * network status based on which carrier apps could apply actions accordingly,
8356 * enable/disable default url handler for example.
8357 *
8358 * @param subId the subscription ID that this action applies to.
8359 * @param report control start/stop reporting the default network status.
8360 * {@hide}
8361 */
8362 @Override
8363 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8364 enforceModifyPermission();
8365 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008366
8367 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008368 if (phone == null) {
8369 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8370 return;
8371 }
8372 try {
8373 phone.carrierActionReportDefaultNetworkStatus(report);
8374 } catch (Exception e) {
8375 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376 } finally {
8377 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008378 }
8379 }
8380
8381 /**
fionaxud9622282017-07-17 17:51:30 -07008382 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8383 * @param subId the subscription ID that this action applies to.
8384 * {@hide}
8385 */
8386 @Override
8387 public void carrierActionResetAll(int subId) {
8388 enforceModifyPermission();
8389 final Phone phone = getPhone(subId);
8390 if (phone == null) {
8391 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8392 return;
8393 }
8394 try {
8395 phone.carrierActionResetAll();
8396 } catch (Exception e) {
8397 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8398 }
8399 }
8400
8401 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008402 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8403 * bug report is being generated.
8404 */
8405 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008406 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008407 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8408 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008409 writer.println("Permission Denial: can't dump Phone from pid="
8410 + Binder.getCallingPid()
8411 + ", uid=" + Binder.getCallingUid()
8412 + "without permission "
8413 + android.Manifest.permission.DUMP);
8414 return;
8415 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008416 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008417 }
Jack Yueb89b242016-06-22 13:27:47 -07008418
Brad Ebingerdac2f002018-04-03 15:17:52 -07008419 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008420 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8421 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8422 @NonNull String[] args) {
8423 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8424 this, in.getFileDescriptor(), out.getFileDescriptor(),
8425 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008426 }
8427
Jack Yueb89b242016-06-22 13:27:47 -07008428 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008429 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008430 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008431 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008432 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008433 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008434 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008435 */
8436 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008437 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008438 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008439 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8440 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8441 try {
8442 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008443 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008444 } catch (SecurityException se) {
8445 enforceModifyPermission();
8446 }
8447 } else {
8448 enforceModifyPermission();
8449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450
8451 final long identity = Binder.clearCallingIdentity();
8452 try {
8453 Phone phone = getPhone(subId);
8454 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008455 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8456 phone.carrierActionSetMeteredApnsEnabled(enabled);
8457 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008458 if (phone.isUsingNewDataStack()) {
Sarah Chinecc78c42022-03-31 21:16:48 -07008459 phone.getDataSettingsManager().setDataEnabled(
8460 reason, enabled, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08008461 } else {
8462 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8463 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008465 }
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008468 }
8469 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008470
8471 /**
8472 * Get Client request stats
8473 * @return List of Client Request Stats
8474 * @hide
8475 */
8476 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008477 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8478 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008479 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008480 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008481 return null;
8482 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008483 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008484
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008485 final long identity = Binder.clearCallingIdentity();
8486 try {
8487 if (phone != null) {
8488 return phone.getClientRequestStats();
8489 }
8490
8491 return null;
8492 } finally {
8493 Binder.restoreCallingIdentity(identity);
8494 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008495 }
8496
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008497 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008498 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008499 if (uid == Process.ROOT_UID && packageName == null) {
8500 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8501 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8502 // exception. ROOT_UID seems not to have a valid package name returned by
8503 // PackageManager, so just fake it here to avoid issues when running telephony shell
8504 // commands that plumb through the RIL as root, like so:
8505 // $ adb root
8506 // $ adb shell cmd phone ...
8507 packageName = "root";
8508 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008509 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008510 }
Jack Yueb4124c2017-02-16 15:32:43 -08008511
8512 /**
Grace Chen70990072017-03-24 17:21:30 -07008513 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008514 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008515 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008516 * @param state State of SIM (power down, power up, pass through)
8517 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8518 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8519 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008520 *
8521 **/
8522 @Override
Grace Chen70990072017-03-24 17:21:30 -07008523 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008524 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008525 Phone phone = PhoneFactory.getPhone(slotIndex);
8526
vagdeviaf9a5b92018-08-15 16:01:53 -07008527 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008532 phone.setSimPowerState(state, null, workSource);
8533 }
8534 } finally {
8535 Binder.restoreCallingIdentity(identity);
8536 }
8537 }
8538
8539 /**
8540 * Set SIM card power state.
8541 *
8542 * @param slotIndex SIM slot id.
8543 * @param state State of SIM (power down, power up, pass through)
8544 * @param callback callback to trigger after success or failure
8545 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8546 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8547 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8548 *
8549 **/
8550 @Override
8551 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8552 IIntegerConsumer callback) {
8553 enforceModifyPermission();
8554 Phone phone = PhoneFactory.getPhone(slotIndex);
8555
8556 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8557
8558 final long identity = Binder.clearCallingIdentity();
8559 try {
8560 if (phone != null) {
8561 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8562 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008563 }
8564 } finally {
8565 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008566 }
8567 }
Shuo Qiandd210312017-04-12 22:11:33 +00008568
Tyler Gunn65d45c22017-06-05 11:22:26 -07008569 private boolean isUssdApiAllowed(int subId) {
8570 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008571 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008572 if (configManager == null) {
8573 return false;
8574 }
8575 PersistableBundle pb = configManager.getConfigForSubId(subId);
8576 if (pb == null) {
8577 return false;
8578 }
8579 return pb.getBoolean(
8580 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8581 }
8582
Shuo Qiandd210312017-04-12 22:11:33 +00008583 /**
8584 * Check if phone is in emergency callback mode
8585 * @return true if phone is in emergency callback mode
8586 * @param subId sub id
8587 */
goneil9c5f4872017-12-05 14:07:56 -08008588 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008589 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008590 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008591 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008592
8593 final long identity = Binder.clearCallingIdentity();
8594 try {
8595 if (phone != null) {
8596 return phone.isInEcm();
8597 } else {
8598 return false;
8599 }
8600 } finally {
8601 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008602 }
8603 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008604
8605 /**
8606 * Get the current signal strength information for the given subscription.
8607 * Because this information is not updated when the device is in a low power state
8608 * it should not be relied-upon to be current.
8609 * @param subId Subscription index
8610 * @return the most recent cached signal strength info from the modem
8611 */
8612 @Override
8613 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008614 final long identity = Binder.clearCallingIdentity();
8615 try {
8616 Phone p = getPhone(subId);
8617 if (p == null) {
8618 return null;
8619 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008621 return p.getSignalStrength();
8622 } finally {
8623 Binder.restoreCallingIdentity(identity);
8624 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008625 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008626
Pengquan Meng77b7f132018-08-22 14:49:57 -07008627 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008628 * Get the current modem radio state for the given slot.
8629 * @param slotIndex slot index.
8630 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008631 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008632 * @return the current radio power state from the modem
8633 */
8634 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008635 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008636 Phone phone = PhoneFactory.getPhone(slotIndex);
8637 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8639 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008640 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8641 }
8642
8643 final long identity = Binder.clearCallingIdentity();
8644 try {
8645 return phone.getRadioPowerState();
8646 } finally {
8647 Binder.restoreCallingIdentity(identity);
8648 }
8649 }
8650 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8651 }
8652
8653 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008654 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8655 *
8656 * <p>Requires one of the following permissions:
8657 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008658 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008659 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8660 * privileges.
8661 *
8662 * @param subId subscription id
8663 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8664 * {@code false}.
8665 */
8666 @Override
8667 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008668 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008669 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008670 try {
8671 mApp.enforceCallingOrSelfPermission(
8672 android.Manifest.permission.ACCESS_NETWORK_STATE,
8673 functionName);
8674 } catch (Exception e) {
8675 mApp.enforceCallingOrSelfPermission(
8676 permission.READ_BASIC_PHONE_STATE, functionName);
8677 }
Shuo Qian093013d2020-08-13 15:42:55 -07008678 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008679 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008680 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008681 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008682
Pengquan Menga1bb6272018-09-06 09:59:22 -07008683 boolean isEnabled = false;
8684 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008685 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008686 Phone phone = getPhone(subId);
8687 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008688 } finally {
8689 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008690 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008691 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008692 }
8693
8694
8695 /**
8696 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8697 *
8698 * <p> Requires permission:
8699 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8700 * privileges.
8701 *
8702 * @param subId subscription id
8703 * @param isEnabled {@code true} means enable, {@code false} means disable.
8704 */
8705 @Override
8706 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8708 mApp, subId, "setDataRoamingEnabled");
8709
Pengquan Menga1bb6272018-09-06 09:59:22 -07008710 final long identity = Binder.clearCallingIdentity();
8711 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008712 Phone phone = getPhone(subId);
8713 if (phone != null) {
8714 phone.setDataRoamingEnabled(isEnabled);
8715 }
8716 } finally {
8717 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008718 }
8719 }
8720
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008721 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008722 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008723 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008724 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008725 mApp, subId, "isManualNetworkSelectionAllowed");
8726
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008727 boolean isAllowed = true;
8728 final long identity = Binder.clearCallingIdentity();
8729 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008730 Phone phone = getPhone(subId);
8731 if (phone != null) {
8732 isAllowed = phone.isCspPlmnEnabled();
8733 }
8734 } finally {
8735 Binder.restoreCallingIdentity(identity);
8736 }
8737 return isAllowed;
8738 }
8739
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008740 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8741 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008742 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008743 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008744 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008745 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8746 if (phone == null) {
8747 return false;
8748 }
8749 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8750 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8751 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008752 }
8753
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008754 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008755 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008756 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008757 mApp.getSystemService(AppOpsManager.class)
8758 .checkPackage(Binder.getCallingUid(), callingPackage);
8759
Jordan Liu1e142fc2019-04-22 15:10:43 -07008760 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008761 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008762 try {
8763 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008764 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008765 } catch (SecurityException e) {
8766 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8767 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008768 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008769 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008770 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008771 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008772 }
sandeepjsb6c87872021-09-27 15:34:44 +00008773 // checking compatibility, if calling app's target SDK is T and beyond.
8774 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8775 Binder.getCallingUid())) {
8776 isIccIdAccessRestricted = true;
8777 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008778 final long identity = Binder.clearCallingIdentity();
8779 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008780 UiccController uiccController = UiccController.getInstance();
8781 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008782 if (hasReadPermission) {
8783 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008784 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008785
8786 // Remove private info if the caller doesn't have access
8787 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8788 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008789 //setting the value after compatibility check
8790 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008791 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8792 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008793 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008794 if (card == null) {
8795 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008796 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008797 continue;
8798 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008799 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8800 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008801 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008802 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008803 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008804 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8805 for (UiccPortInfo portInfo : portInfos) {
8806 UiccPort port = uiccController.getUiccPortForSlot(
8807 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8808 if (port == null) {
8809 // assume no access if port is null
8810 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8811 continue;
8812 }
8813 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8814 uiccPortInfos.add(portInfo);
8815 } else {
8816 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8817 }
8818 }
8819 filteredInfos.add(new UiccCardInfo(
8820 cardInfo.isEuicc(),
8821 cardInfo.getCardId(),
8822 null,
8823 cardInfo.getPhysicalSlotIndex(),
8824 cardInfo.isRemovable(),
8825 cardInfo.isMultipleEnabledProfilesSupported(),
8826 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008827 }
8828 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008829 } finally {
8830 Binder.restoreCallingIdentity(identity);
8831 }
8832 }
8833
sandeepjsb6c87872021-09-27 15:34:44 +00008834 /**
8835 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8836 * generally private and require carrier privileges to view.
8837 *
8838 * @hide
8839 */
8840 @NonNull
8841 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8842 List<UiccPortInfo> portinfo = new ArrayList<>();
8843 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8844 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8845 }
8846 return new UiccCardInfo(
8847 cardInfo.isEuicc(),
8848 cardInfo.getCardId(),
8849 null,
8850 cardInfo.getPhysicalSlotIndex(),
8851 cardInfo.isRemovable(),
8852 cardInfo.isMultipleEnabledProfilesSupported(),
8853 portinfo
8854 );
8855 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008856
sandeepjsb6c87872021-09-27 15:34:44 +00008857 /**
8858 * @hide
8859 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8860 * These values are generally private and require carrier privileges to view.
8861 */
8862 @NonNull
8863 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8864 return new UiccPortInfo(
8865 UiccPortInfo.ICCID_REDACTED,
8866 portInfo.getPortIndex(),
8867 portInfo.getLogicalSlotIndex(),
8868 portInfo.isActive()
8869 );
8870 }
8871 @Override
8872 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008873 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008874 mApp.getSystemService(AppOpsManager.class)
8875 .checkPackage(Binder.getCallingUid(), callingPackage);
8876
sandeepjsb6c87872021-09-27 15:34:44 +00008877 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008878
Aman Guptaf3c90b32022-03-17 04:54:16 +00008879 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8880 // we are reading iccId which is PII data.
8881 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008882
8883 // checking compatibility, if calling app's target SDK is T and beyond.
8884 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8885 Binder.getCallingUid())) {
8886 isLogicalSlotAccessRestricted = true;
8887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008888 final long identity = Binder.clearCallingIdentity();
8889 try {
8890 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008891 if (slots == null || slots.length == 0) {
8892 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008893 return null;
8894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008895 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8896 for (int i = 0; i < slots.length; i++) {
8897 UiccSlot slot = slots[i];
8898 if (slot == null) {
8899 continue;
8900 }
8901
Jordan Liu7be7e652019-05-06 18:55:02 +00008902 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008903 UiccCard card = slot.getUiccCard();
8904 if (card != null) {
8905 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008906 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008907 cardId = slot.getEid();
8908 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008909 // If cardId is null, use iccId of default port as cardId.
8910 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008912 }
8913
Jordan Liu857451f2019-05-09 16:35:35 -07008914 if (cardId != null) {
8915 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8916 // if cardId is an EID, it's all digits so this is fine
8917 cardId = IccUtils.stripTrailingFs(cardId);
8918 }
8919
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008920 int cardState = 0;
8921 switch (slot.getCardState()) {
8922 case CARDSTATE_ABSENT:
8923 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8924 break;
8925 case CARDSTATE_PRESENT:
8926 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8927 break;
8928 case CARDSTATE_ERROR:
8929 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8930 break;
8931 case CARDSTATE_RESTRICTED:
8932 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8933 break;
8934 default:
8935 break;
8936
8937 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008938 List<UiccPortInfo> portInfos = new ArrayList<>();
8939 int[] portIndexes = slot.getPortList();
8940 for (int portIdx : portIndexes) {
8941 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00008942 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008943 portInfos.add(new UiccPortInfo(iccId, portIdx,
8944 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008946 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008947 slot.isEuicc(),
8948 cardId,
8949 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008950 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008951 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008952 //setting the value after compatibility check
8953 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008954 }
8955 return infos;
8956 } finally {
8957 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008958 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008959 }
8960
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008961 /* Returns null if doesn't have read permission or carrier privilege access. */
8962 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8963 boolean hasReadPermission) {
8964 String iccId = slot.getIccId(portIndex);
8965 if (hasReadPermission) { // if has read permission
8966 return iccId;
8967 } else {
8968 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8969 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8970 // if no read permission, checking carrier privilege access
8971 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8972 return iccId;
8973 }
8974 }
8975 }
8976 // No read permission or carrier privilege access.
8977 return UiccPortInfo.ICCID_REDACTED;
8978 }
8979
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008980 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008981 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008982 public boolean switchSlots(int[] physicalSlots) {
8983 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008984
8985 final long identity = Binder.clearCallingIdentity();
8986 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008987 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8988 for (int i = 0; i < physicalSlots.length; i++) {
8989 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8990 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8991 physicalSlots[i], i));
8992 }
8993 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008994 } finally {
8995 Binder.restoreCallingIdentity(identity);
8996 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008997 }
Jack Yu4c988042018-02-27 15:30:01 -08008998
8999 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009000 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9001 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9002 enforceModifyPermission();
9003
9004 final long identity = Binder.clearCallingIdentity();
9005 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009006 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009007 } finally {
9008 Binder.restoreCallingIdentity(identity);
9009 }
9010 }
9011
9012 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009013 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009014 final long identity = Binder.clearCallingIdentity();
9015 try {
9016 return UiccController.getInstance().getCardIdForDefaultEuicc();
9017 } finally {
9018 Binder.restoreCallingIdentity(identity);
9019 }
9020 }
9021
Pengquan Meng85728fb2018-03-12 16:31:21 -07009022 /**
goneil47ffb6e2018-04-06 15:40:58 -07009023 * A test API to reload the UICC profile.
9024 *
9025 * <p>Requires that the calling app has permission
9026 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9027 * @hide
9028 */
9029 @Override
9030 public void refreshUiccProfile(int subId) {
9031 enforceModifyPermission();
9032
9033 final long identity = Binder.clearCallingIdentity();
9034 try {
9035 Phone phone = getPhone(subId);
9036 if (phone == null) {
9037 return;
9038 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009039 UiccPort uiccPort = phone.getUiccPort();
9040 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009041 return;
9042 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009043 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009044 if (uiccProfile == null) {
9045 return;
9046 }
9047 uiccProfile.refresh();
9048 } finally {
9049 Binder.restoreCallingIdentity(identity);
9050 }
9051 }
9052
9053 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009054 * Returns false if the mobile data is disabled by default, otherwise return true.
9055 */
9056 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009057 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009058 }
9059
9060 /**
9061 * Returns true if the data roaming is enabled by default, i.e the system property
9062 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9063 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9064 */
9065 private boolean getDefaultDataRoamingEnabled(int subId) {
9066 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009067 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009068 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009069 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9070 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9071 return isDataRoamingEnabled;
9072 }
9073
9074 /**
9075 * Returns the default network type for the given {@code subId}, if the default network type is
9076 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9077 */
9078 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009079 List<Integer> list = TelephonyProperties.default_network();
9080 int phoneId = mSubscriptionController.getPhoneId(subId);
9081 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9082 return list.get(phoneId);
9083 }
9084 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009085 }
fionaxua13278b2018-03-21 00:08:13 -07009086
9087 @Override
9088 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009089 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009090 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009091
9092 final long identity = Binder.clearCallingIdentity();
9093 try {
9094 final Phone phone = getPhone(subId);
9095 if (phone == null) {
9096 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9097 return;
9098 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009099 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9100 if (cpt != null) {
9101 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9102 }
9103 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009104 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9105 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009106 if (carrierPrivilegeRules == null) {
9107 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9108 } else {
9109 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009111 } finally {
9112 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009113 }
fionaxua13278b2018-03-21 00:08:13 -07009114 }
9115
9116 @Override
9117 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009118 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009119
9120 final long identity = Binder.clearCallingIdentity();
9121 try {
9122 final Phone phone = getPhone(subId);
9123 if (phone == null) {
9124 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9125 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9126 }
9127 return phone.getCarrierIdListVersion();
9128 } finally {
9129 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009130 }
fionaxua13278b2018-03-21 00:08:13 -07009131 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009132
9133 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009134 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9135 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009137 mApp, subId, callingPackage, callingFeatureId,
9138 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009139 return -1;
9140 }
9141
9142 final long identity = Binder.clearCallingIdentity();
9143 try {
9144 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9145 } finally {
9146 Binder.restoreCallingIdentity(identity);
9147 }
9148 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009149
9150 @Override
9151 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009152 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009153 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009154 mApp, subId, "getCdmaRoamingMode");
9155
9156 final long identity = Binder.clearCallingIdentity();
9157 try {
9158 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9159 } finally {
9160 Binder.restoreCallingIdentity(identity);
9161 }
9162 }
9163
9164 @Override
9165 public boolean setCdmaRoamingMode(int subId, int mode) {
9166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9167 mApp, subId, "setCdmaRoamingMode");
9168
9169 final long identity = Binder.clearCallingIdentity();
9170 try {
9171 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9172 } finally {
9173 Binder.restoreCallingIdentity(identity);
9174 }
9175 }
9176
9177 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009178 public int getCdmaSubscriptionMode(int subId) {
9179 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009180 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009181 mApp, subId, "getCdmaSubscriptionMode");
9182
9183 final long identity = Binder.clearCallingIdentity();
9184 try {
9185 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9186 } finally {
9187 Binder.restoreCallingIdentity(identity);
9188 }
9189 }
9190
9191 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009192 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9194 mApp, subId, "setCdmaSubscriptionMode");
9195
9196 final long identity = Binder.clearCallingIdentity();
9197 try {
9198 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9199 } finally {
9200 Binder.restoreCallingIdentity(identity);
9201 }
9202 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009203
sqianc5eccab2018-10-19 18:46:41 -07009204 @Override
sqian8c685422019-02-22 15:55:18 -08009205 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009206 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009208 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9209 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009210 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9211 }
9212 final long identity = Binder.clearCallingIdentity();
9213 try {
sqian854d44b2018-12-12 16:48:18 -08009214 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9215 for (Phone phone: PhoneFactory.getPhones()) {
9216 if (phone.getEmergencyNumberTracker() != null
9217 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9218 emergencyNumberListInternal.put(
9219 phone.getSubId(),
9220 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9221 }
sqian11b7a0e2018-12-05 18:48:28 -08009222 }
sqian854d44b2018-12-12 16:48:18 -08009223 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009224 } finally {
9225 Binder.restoreCallingIdentity(identity);
9226 }
sqianc5eccab2018-10-19 18:46:41 -07009227 }
9228
9229 @Override
sqian8c685422019-02-22 15:55:18 -08009230 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009231 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009232 if (!exactMatch) {
9233 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009234 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009235 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009236 }
9237 final long identity = Binder.clearCallingIdentity();
9238 try {
sqian854d44b2018-12-12 16:48:18 -08009239 for (Phone phone: PhoneFactory.getPhones()) {
9240 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009241 && phone.getEmergencyNumberTracker()
9242 .isEmergencyNumber(number, exactMatch)) {
9243 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009244 }
sqian11b7a0e2018-12-05 18:48:28 -08009245 }
9246 return false;
9247 } finally {
9248 Binder.restoreCallingIdentity(identity);
9249 }
9250 }
9251
sqianf4ca7ed2019-01-15 18:32:07 -08009252 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009253 * Start emergency callback mode for GsmCdmaPhone for testing.
9254 */
9255 @Override
9256 public void startEmergencyCallbackMode() {
9257 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9258 "startEmergencyCallbackMode");
9259 enforceModifyPermission();
9260 final long identity = Binder.clearCallingIdentity();
9261 try {
9262 for (Phone phone : PhoneFactory.getPhones()) {
9263 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9264 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9265 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9266 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9267 gsmCdmaPhone.obtainMessage(
9268 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9269 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9270 }
9271 }
9272 } finally {
9273 Binder.restoreCallingIdentity(identity);
9274 }
9275 }
9276
9277 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009278 * Update emergency number list for test mode.
9279 */
9280 @Override
9281 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9282 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9283 "updateEmergencyNumberListTestMode");
9284
9285 final long identity = Binder.clearCallingIdentity();
9286 try {
9287 for (Phone phone: PhoneFactory.getPhones()) {
9288 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9289 if (tracker != null) {
9290 tracker.executeEmergencyNumberTestModeCommand(action, num);
9291 }
9292 }
9293 } finally {
9294 Binder.restoreCallingIdentity(identity);
9295 }
9296 }
9297
9298 /**
9299 * Get the full emergency number list for test mode.
9300 */
9301 @Override
9302 public List<String> getEmergencyNumberListTestMode() {
9303 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9304 "getEmergencyNumberListTestMode");
9305
9306 final long identity = Binder.clearCallingIdentity();
9307 try {
9308 Set<String> emergencyNumbers = new HashSet<>();
9309 for (Phone phone: PhoneFactory.getPhones()) {
9310 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9311 if (tracker != null) {
9312 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9313 emergencyNumbers.add(num.getNumber());
9314 }
9315 }
9316 }
9317 return new ArrayList<>(emergencyNumbers);
9318 } finally {
9319 Binder.restoreCallingIdentity(identity);
9320 }
9321 }
9322
chen xud6b45bd2018-10-30 22:27:10 -07009323 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009324 public int getEmergencyNumberDbVersion(int subId) {
9325 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9326
9327 final long identity = Binder.clearCallingIdentity();
9328 try {
9329 final Phone phone = getPhone(subId);
9330 if (phone == null) {
9331 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9332 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9333 }
9334 return phone.getEmergencyNumberDbVersion();
9335 } finally {
9336 Binder.restoreCallingIdentity(identity);
9337 }
9338 }
9339
9340 @Override
9341 public void notifyOtaEmergencyNumberDbInstalled() {
9342 enforceModifyPermission();
9343
9344 final long identity = Binder.clearCallingIdentity();
9345 try {
9346 for (Phone phone: PhoneFactory.getPhones()) {
9347 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9348 if (tracker != null) {
9349 tracker.updateOtaEmergencyNumberDatabase();
9350 }
9351 }
9352 } finally {
9353 Binder.restoreCallingIdentity(identity);
9354 }
9355 }
9356
9357 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009358 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009359 enforceActiveEmergencySessionPermission();
9360
9361 final long identity = Binder.clearCallingIdentity();
9362 try {
9363 for (Phone phone: PhoneFactory.getPhones()) {
9364 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9365 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009366 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9367 }
9368 }
9369 } finally {
9370 Binder.restoreCallingIdentity(identity);
9371 }
9372 }
9373
9374 @Override
9375 public void resetOtaEmergencyNumberDbFilePath() {
9376 enforceActiveEmergencySessionPermission();
9377
9378 final long identity = Binder.clearCallingIdentity();
9379 try {
9380 for (Phone phone: PhoneFactory.getPhones()) {
9381 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9382 if (tracker != null) {
9383 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009384 }
9385 }
9386 } finally {
9387 Binder.restoreCallingIdentity(identity);
9388 }
9389 }
9390
9391 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009392 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9393 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9394 Phone phone = getPhone(subId);
9395 if (phone == null) {
9396 return null;
9397 }
9398 final long identity = Binder.clearCallingIdentity();
9399 try {
9400 UiccProfile profile = UiccController.getInstance()
9401 .getUiccProfileForPhone(phone.getPhoneId());
9402 if (profile != null) {
9403 return profile.getCertsFromCarrierPrivilegeAccessRules();
9404 }
9405 } finally {
9406 Binder.restoreCallingIdentity(identity);
9407 }
9408 return null;
9409 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009410
9411 /**
9412 * Enable or disable a modem stack.
9413 */
9414 @Override
9415 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9416 enforceModifyPermission();
9417
9418 final long identity = Binder.clearCallingIdentity();
9419 try {
9420 Phone phone = PhoneFactory.getPhone(slotIndex);
9421 if (phone == null) {
9422 return false;
9423 } else {
9424 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9425 }
9426 } finally {
9427 Binder.restoreCallingIdentity(identity);
9428 }
9429 }
Michelecea4cf22018-12-21 15:00:11 -08009430
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009431 /**
9432 * Whether a modem stack is enabled or not.
9433 */
9434 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009435 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9436 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009437 Phone phone = PhoneFactory.getPhone(slotIndex);
9438 if (phone == null) return false;
9439
9440 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009441 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9442 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009443 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9444 }
9445
9446 final long identity = Binder.clearCallingIdentity();
9447 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009448 try {
9449 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9450 } catch (NoSuchElementException ex) {
9451 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9452 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009453 } finally {
9454 Binder.restoreCallingIdentity(identity);
9455 }
9456 }
9457
Michelecea4cf22018-12-21 15:00:11 -08009458 @Override
Michele0ea7d782019-03-19 14:58:42 -07009459 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009460 enforceModifyPermission();
9461
9462 final long identity = Binder.clearCallingIdentity();
9463 try {
9464 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009465 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009466 .commit();
9467 } finally {
9468 Binder.restoreCallingIdentity(identity);
9469 }
9470 }
9471
9472 @Override
Michele0ea7d782019-03-19 14:58:42 -07009473 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009474 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009476 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9477 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009478 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009479 }
Michelecea4cf22018-12-21 15:00:11 -08009480
9481 final long identity = Binder.clearCallingIdentity();
9482 try {
Michele0ea7d782019-03-19 14:58:42 -07009483 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009484 } finally {
9485 Binder.restoreCallingIdentity(identity);
9486 }
9487 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009488
Michele0ea7d782019-03-19 14:58:42 -07009489 @TelephonyManager.IsMultiSimSupportedResult
9490 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009491 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9492 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9493 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009494 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9495 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009496 }
9497 // Check if the hardware supports multisim functionality. If usage of multisim is not
9498 // supported by the modem, indicate that it is restricted.
9499 PhoneCapability staticCapability =
9500 mPhoneConfigurationManager.getStaticPhoneCapability();
9501 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009502 loge("isMultiSimSupportedInternal: no static configuration available");
9503 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009504 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009505 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009506 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9507 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009508 }
9509 // Check if support of multiple SIMs is restricted by carrier
9510 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009511 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009512 }
9513
Michele0ea7d782019-03-19 14:58:42 -07009514 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009515 }
9516
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009517 /**
9518 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009519 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9520 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9521 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009522 * @param numOfSims number of active sims we want to switch to
9523 */
9524 @Override
9525 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009526 if (numOfSims == 1) {
9527 enforceModifyPermission();
9528 } else {
9529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9530 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9531 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009532 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009533
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009534 try {
Michele30b57b22019-03-01 12:01:14 -08009535 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009536 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009537 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9538 return;
9539 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009540 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9541 } finally {
9542 Binder.restoreCallingIdentity(identity);
9543 }
9544 }
9545
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009546 @Override
9547 public boolean isApplicationOnUicc(int subId, int appType) {
9548 enforceReadPrivilegedPermission("isApplicationOnUicc");
9549 Phone phone = getPhone(subId);
9550 if (phone == null) {
9551 return false;
9552 }
9553 final long identity = Binder.clearCallingIdentity();
9554 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009555 UiccPort uiccPort = phone.getUiccPort();
9556 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009557 return false;
9558 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009559 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009560 if (uiccProfile == null) {
9561 return false;
9562 }
9563 if (TelephonyManager.APPTYPE_SIM <= appType
9564 && appType <= TelephonyManager.APPTYPE_ISIM) {
9565 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9566 }
9567 return false;
9568 } finally {
9569 Binder.restoreCallingIdentity(identity);
9570 }
9571 }
9572
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009573 /**
chen xub4baa772019-04-03 10:23:41 -07009574 * Get whether making changes to modem configurations will trigger reboot.
9575 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009576 */
9577 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009578 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9579 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009581 mApp, subId, callingPackage, callingFeatureId,
9582 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009583 return false;
9584 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009585 final long identity = Binder.clearCallingIdentity();
9586 try {
9587 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9588 } finally {
9589 Binder.restoreCallingIdentity(identity);
9590 }
9591 }
9592
Nathan Harold29f5f052019-02-15 13:41:57 -08009593 private void updateModemStateMetrics() {
9594 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9595 // TODO: check the state for each modem if the api is ready.
9596 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9597 }
9598
Pengquan Meng3889a572019-01-23 11:16:29 -08009599 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009600 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009601 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009602 // Verify that the callingPackage belongs to the calling UID
9603 mApp.getSystemService(AppOpsManager.class)
9604 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009605 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009606 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009607 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009608 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9609 if (slotInfos != null) {
9610 for (int i = 0; i < slotInfos.length; i++) {
9611 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9612 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9613 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9614 portInfo.getLogicalSlotIndex()));
9615 }
9616 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009617 }
9618 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009619 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009620 } finally {
9621 Binder.restoreCallingIdentity(identity);
9622 }
9623 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009624
9625 /**
9626 * Get the IRadio HAL Version
9627 */
9628 @Override
9629 public int getRadioHalVersion() {
9630 Phone phone = getDefaultPhone();
9631 if (phone == null) return -1;
9632 HalVersion hv = phone.getHalVersion();
9633 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9634 return hv.major * 100 + hv.minor;
9635 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009636
9637 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009638 * Get the current calling package name.
9639 * @return the current calling package name
9640 */
9641 @Override
9642 public String getCurrentPackageName() {
9643 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9644 }
9645
9646 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009647 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9648 * corresponding network requests on a subId.
9649 *
9650 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009651 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009652 * 2) APN is un-metered for this subscription, or
9653 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009654 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009655 *
9656 * @return whether data is allowed for a apn type.
9657 *
9658 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009659 */
9660 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009661 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009662 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9663 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009664
9665 // Now that all security checks passes, perform the operation as ourselves.
9666 final long identity = Binder.clearCallingIdentity();
9667 try {
9668 Phone phone = getPhone(subId);
9669 if (phone == null) return false;
9670
Jack Yu27422a52022-03-21 10:38:05 -07009671 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009672 boolean isDataEnabled;
9673 if (phone.isUsingNewDataStack()) {
Jack Yu27422a52022-03-21 10:38:05 -07009674 isMetered = phone.getDataNetworkController().getDataConfigManager()
9675 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9676 phone.getServiceState().getDataRoaming());
Jack Yu99e87332021-12-17 23:14:15 -08009677 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9678 } else {
Jack Yu27422a52022-03-21 10:38:05 -07009679 isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009680 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9681 }
9682 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009683 } finally {
9684 Binder.restoreCallingIdentity(identity);
9685 }
9686 }
9687
9688 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009689 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009690 enforceReadPrivilegedPermission("isApnMetered");
9691
9692 // Now that all security checks passes, perform the operation as ourselves.
9693 final long identity = Binder.clearCallingIdentity();
9694 try {
9695 Phone phone = getPhone(subId);
9696 if (phone == null) return true; // By default return true.
Jack Yu27422a52022-03-21 10:38:05 -07009697 if (phone.isUsingNewDataStack()) {
9698 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9699 DataUtils.apnTypeToNetworkCapability(apnType),
9700 phone.getServiceState().getDataRoaming());
9701 }
Malcolm Chene5ad5792019-04-18 13:51:02 -07009702
Jack Yu41407ee2019-05-13 16:54:09 -07009703 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009704 } finally {
9705 Binder.restoreCallingIdentity(identity);
9706 }
9707 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009708
9709 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009710 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9711 int subscriptionId, IBooleanConsumer resultCallback) {
9712 enforceModifyPermission();
9713 long token = Binder.clearCallingIdentity();
9714 try {
9715 Phone phone = getPhone(subscriptionId);
9716 if (phone == null) {
9717 try {
9718 if (resultCallback != null) {
9719 resultCallback.accept(false);
9720 }
9721 } catch (RemoteException e) {
9722 // ignore
9723 }
9724 return;
9725 }
9726 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9727 Pair.create(specifiers, (x) -> {
9728 try {
9729 if (resultCallback != null) {
9730 resultCallback.accept(x);
9731 }
9732 } catch (RemoteException e) {
9733 // ignore
9734 }
9735 });
9736 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9737 } finally {
9738 Binder.restoreCallingIdentity(token);
9739 }
9740 }
9741
9742 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009743 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9744 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009745 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009746 mApp, subId, "getSystemSelectionChannels");
9747 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9748 final long identity = Binder.clearCallingIdentity();
9749 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009750 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9751 if (result instanceof IllegalStateException) {
9752 throw (IllegalStateException) result;
9753 }
9754 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009755 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9756 return specifiers;
9757 } finally {
9758 Binder.restoreCallingIdentity(identity);
9759 }
9760 }
9761
9762 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009763 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009764 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009765 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009766 }
9767
9768 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009769 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9770 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009771 if (callingPackage == null) {
9772 callingPackage = getCurrentPackageName();
9773 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009774 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9775 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009776 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9777 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009778 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9779 }
9780 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9781 Intent intent = new Intent();
9782 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9783 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9784 // Bring up choose default SMS subscription dialog right now
9785 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9786 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9787 mApp.startActivity(intent);
9788 }
chen xud5ca2d52019-05-28 15:20:57 -07009789
9790 @Override
9791 public String getMmsUAProfUrl(int subId) {
9792 //TODO investigate if this API should require proper permission check in R b/133791609
9793 final long identity = Binder.clearCallingIdentity();
9794 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009795 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9796 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9797 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9798 return carrierUAProfUrl;
9799 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009800 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9801 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009802 } finally {
9803 Binder.restoreCallingIdentity(identity);
9804 }
9805 }
9806
9807 @Override
9808 public String getMmsUserAgent(int subId) {
9809 //TODO investigate if this API should require proper permission check in R b/133791609
9810 final long identity = Binder.clearCallingIdentity();
9811 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009812 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9813 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9814 if (!TextUtils.isEmpty(carrierUserAgent)) {
9815 return carrierUserAgent;
9816 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009817 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9818 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009819 } finally {
9820 Binder.restoreCallingIdentity(identity);
9821 }
9822 }
Jack Yub07d4972019-05-28 16:12:25 -07009823
9824 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009825 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9826 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009827
Jack Yub07d4972019-05-28 16:12:25 -07009828 final long identity = Binder.clearCallingIdentity();
9829 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009830 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009831 if (phone == null) return false;
9832
Hall Liua62f5da2020-09-25 10:42:19 -07009833 switch (policy) {
9834 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009835 if (phone.isUsingNewDataStack()) {
9836 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9837 } else {
9838 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9839 }
Hall Liua62f5da2020-09-25 10:42:19 -07009840 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009841 if (phone.isUsingNewDataStack()) {
9842 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9843 } else {
9844 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9845 }
Hall Liua62f5da2020-09-25 10:42:19 -07009846 default:
9847 throw new IllegalArgumentException(policy + " is not a valid policy");
9848 }
Jack Yub07d4972019-05-28 16:12:25 -07009849 } finally {
9850 Binder.restoreCallingIdentity(identity);
9851 }
9852 }
9853
9854 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009855 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009856 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009857 enforceModifyPermission();
9858
changbettyd5c246e2019-12-24 15:40:37 +08009859 final long identity = Binder.clearCallingIdentity();
9860 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009861 Phone phone = getPhone(subscriptionId);
9862 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009863
Hall Liua62f5da2020-09-25 10:42:19 -07009864 switch (policy) {
9865 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009866 if (phone.isUsingNewDataStack()) {
9867 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9868 } else {
9869 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9870 }
Hall Liua62f5da2020-09-25 10:42:19 -07009871 break;
9872 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009873 if (phone.isUsingNewDataStack()) {
9874 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9875 } else {
9876 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9877 }
Hall Liua62f5da2020-09-25 10:42:19 -07009878 break;
9879 default:
9880 throw new IllegalArgumentException(policy + " is not a valid policy");
9881 }
changbettyd5c246e2019-12-24 15:40:37 +08009882 } finally {
9883 Binder.restoreCallingIdentity(identity);
9884 }
9885 }
9886
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009887 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009888 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009889 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9890 * otherwise.
9891 */
9892 @Override
9893 public void setCepEnabled(boolean isCepEnabled) {
9894 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9895
9896 final long identity = Binder.clearCallingIdentity();
9897 try {
9898 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9899 for (Phone phone : PhoneFactory.getPhones()) {
9900 Phone defaultPhone = phone.getImsPhone();
9901 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9902 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9903 ImsPhoneCallTracker imsPhoneCallTracker =
9904 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9905 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9906 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9907 + imsPhone.getMsisdn());
9908 }
9909 }
9910 } finally {
9911 Binder.restoreCallingIdentity(identity);
9912 }
9913 }
allenwtsu46dcc572020-01-08 18:24:03 +08009914
9915 /**
9916 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9917 *
9918 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9919 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9920 * before being read.
9921 */
9922 @Override
9923 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9924 isCompressed) {
9925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9926 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9928 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9929 }
9930 if (!isImsAvailableOnDevice()) {
9931 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9932 "IMS not available on device.");
9933 }
9934
9935 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009936 try {
Hui Wang761a6682020-10-31 05:12:53 +00009937 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9938 } finally {
9939 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009940 }
9941 }
zoey chene02881a2019-12-30 16:11:23 +08009942
9943 @Override
9944 public boolean isIccLockEnabled(int subId) {
9945 enforceReadPrivilegedPermission("isIccLockEnabled");
9946
9947 // Now that all security checks passes, perform the operation as ourselves.
9948 final long identity = Binder.clearCallingIdentity();
9949 try {
9950 Phone phone = getPhone(subId);
9951 if (phone != null && phone.getIccCard() != null) {
9952 return phone.getIccCard().getIccLockEnabled();
9953 } else {
9954 return false;
9955 }
9956 } finally {
9957 Binder.restoreCallingIdentity(identity);
9958 }
9959 }
9960
9961 /**
9962 * Set the ICC pin lock enabled or disabled.
9963 *
9964 * @return an integer representing the status of IccLock enabled or disabled in the following
9965 * three cases:
9966 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9967 * successfully.
9968 * - Positive number and zero for remaining password attempts.
9969 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9970 *
9971 */
9972 @Override
9973 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9974 enforceModifyPermission();
9975
9976 Phone phone = getPhone(subId);
9977 if (phone == null) {
9978 return 0;
9979 }
9980 // Now that all security checks passes, perform the operation as ourselves.
9981 final long identity = Binder.clearCallingIdentity();
9982 try {
9983 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9984 new Pair<Boolean, String>(enabled, password), phone, null);
9985 return attemptsRemaining;
9986
9987 } catch (Exception e) {
9988 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9989 } finally {
9990 Binder.restoreCallingIdentity(identity);
9991 }
9992 return 0;
9993 }
9994
9995 /**
9996 * Change the ICC password used in ICC pin lock.
9997 *
9998 * @return an integer representing the status of IccLock changed in the following three cases:
9999 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10000 * - Positive number and zero for remaining password attempts.
10001 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10002 *
10003 */
10004 @Override
10005 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10006 enforceModifyPermission();
10007
10008 Phone phone = getPhone(subId);
10009 if (phone == null) {
10010 return 0;
10011 }
10012 // Now that all security checks passes, perform the operation as ourselves.
10013 final long identity = Binder.clearCallingIdentity();
10014 try {
10015 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10016 new Pair<String, String>(oldPassword, newPassword), phone, null);
10017 return attemptsRemaining;
10018
10019 } catch (Exception e) {
10020 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10021 } finally {
10022 Binder.restoreCallingIdentity(identity);
10023 }
10024 return 0;
10025 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010026
10027 /**
10028 * Request for receiving user activity notification
10029 */
10030 @Override
10031 public void requestUserActivityNotification() {
10032 if (!mNotifyUserActivity.get()
10033 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10034 mNotifyUserActivity.set(true);
10035 }
10036 }
10037
10038 /**
10039 * Called when userActivity is signalled in the power manager.
10040 * This is safe to call from any thread, with any window manager locks held or not.
10041 */
10042 @Override
10043 public void userActivity() {
10044 // ***************************************
10045 // * Inherited from PhoneWindowManager *
10046 // ***************************************
10047 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10048 // WITH ITS LOCKS HELD.
10049 //
10050 // This code must be VERY careful about the locks
10051 // it acquires.
10052 // In fact, the current code acquires way too many,
10053 // and probably has lurking deadlocks.
10054
10055 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10056 throw new SecurityException("Only the OS may call notifyUserActivity()");
10057 }
10058
10059 if (mNotifyUserActivity.getAndSet(false)) {
10060 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10061 USER_ACTIVITY_NOTIFICATION_DELAY);
10062 }
10063 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010064
10065 @Override
10066 public boolean canConnectTo5GInDsdsMode() {
10067 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10068 }
Jack Yud10cdd42020-09-28 20:28:01 -070010069
10070 @Override
10071 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10072 String callingFeatureId) {
10073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10074 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10075 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10076 }
10077
10078 Phone phone = getPhone(subId);
10079 if (phone == null) {
10080 throw new RuntimeException("phone is not available");
10081 }
10082 // Now that all security checks passes, perform the operation as ourselves.
10083 final long identity = Binder.clearCallingIdentity();
10084 try {
10085 return phone.getEquivalentHomePlmns();
10086 } finally {
10087 Binder.restoreCallingIdentity(identity);
10088 }
10089 }
Daniel Bright59e67312020-11-13 11:49:37 -080010090
10091 @Override
10092 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010093 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10094 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010095 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010096 if (radioInterfaceCapabilities == null) {
10097 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010098 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010099 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010100 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010101
Hui Wang641e81c2020-10-12 12:14:23 -070010102 @Override
10103 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10104 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010105 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10106 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10107 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10108 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10109 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010110 if (DBG) {
10111 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10112 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10113 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10114 }
10115
10116 if (!SubscriptionManager.isValidSubscriptionId(subId)
10117 || appType < TelephonyManager.APPTYPE_UNKNOWN
10118 || appType > TelephonyManager.APPTYPE_ISIM
10119 || nafUrl == null || securityProtocol == null || callback == null) {
10120 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10121 if (callback != null) {
10122 try {
10123 callback.onAuthenticationFailure(
10124 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10125 } catch (RemoteException exception) {
10126 log("Fail to notify onAuthenticationFailure due to " + exception);
10127 }
10128 return;
10129 }
10130 }
10131
10132 final long token = Binder.clearCallingIdentity();
10133 try {
10134 getGbaManager(subId).bootstrapAuthenticationRequest(
10135 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10136 forceBootStrapping, callback));
10137 } finally {
10138 Binder.restoreCallingIdentity(token);
10139 }
10140 }
10141
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010142 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010143 * Attempts to set the radio power state for all phones for thermal reason.
10144 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010145 * requested radio power state will actually be set. See {@link
10146 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10147 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010148 * @param enable {@code true} if trying to turn radio on.
10149 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10150 * false}.
10151 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010152 private boolean setRadioPowerForThermal(boolean enable) {
10153 boolean isPhoneAvailable = false;
10154 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10155 Phone phone = PhoneFactory.getPhone(i);
10156 if (phone != null) {
10157 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10158 isPhoneAvailable = true;
10159 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010160 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010161
10162 // return true if successfully informed the phone object about the thermal radio power
10163 // request.
10164 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010165 }
10166
10167 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010168 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010169 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10170 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10171 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10172 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10173 throw new IllegalArgumentException("modem does not support data throttling");
10174 }
10175
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010176 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10177 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010178 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010179 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10180 }
10181
Sarah Chinecc78c42022-03-31 21:16:48 -070010182 setDataEnabledForReason(
10183 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010184
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010185 if (isDataThrottlingSupported) {
10186 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010187 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010188 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10189 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10190 } else if (thermalMitigationResult
10191 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010192 log("Modem likely does not support data throttling on secondary carrier. Data " +
10193 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10194 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010195 }
10196 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010197 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010198
10199 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010200 }
10201
Jack Nudelman644b91a2021-03-12 14:09:48 -080010202 private static List<String> getThermalMitigationAllowlist(Context context) {
10203 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10204 for (String pckg : context.getResources()
10205 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10206 sThermalMitigationAllowlistedPackages.add(pckg);
10207 }
10208 }
10209
10210 return sThermalMitigationAllowlistedPackages;
10211 }
10212
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010213 private boolean isAnyPhoneInEmergencyState() {
10214 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10215 if (tm.isInEmergencyCall()) {
10216 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10217 return true;
10218 }
10219 for (Phone phone : PhoneFactory.getPhones()) {
10220 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10221 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10222 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10223 + phone.isInEcm());
10224 return true;
10225 }
10226 }
10227
10228 return false;
10229 }
10230
Jack Nudelman644b91a2021-03-12 14:09:48 -080010231 /**
10232 * Used by shell commands to add an authorized package name for thermal mitigation.
10233 * @param packageName name of package to be allowlisted
10234 * @param context
10235 */
10236 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10237 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10238 sThermalMitigationAllowlistedPackages.add(packageName);
10239 }
10240
10241 /**
10242 * Used by shell commands to remove an authorized package name for thermal mitigation.
10243 * @param packageName name of package to remove from allowlist
10244 * @param context
10245 */
10246 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10247 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10248 sThermalMitigationAllowlistedPackages.remove(packageName);
10249 }
10250
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010251 /**
10252 * Thermal mitigation request to control functionalities at modem.
10253 *
10254 * @param subId the id of the subscription.
10255 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010256 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010257 *
10258 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10259 */
10260 @Override
10261 @ThermalMitigationResult
10262 public int sendThermalMitigationRequest(
10263 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010264 ThermalMitigationRequest thermalMitigationRequest,
10265 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010266 enforceModifyPermission();
10267
Jack Nudelman644b91a2021-03-12 14:09:48 -080010268 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10269 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10270 .contains(callingPackage)) {
10271 throw new SecurityException("Calling package must be configured in the device config. "
10272 + "calling package: " + callingPackage);
10273 }
10274
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10276 final long identity = Binder.clearCallingIdentity();
10277
10278 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10279 try {
10280 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10281 switch (thermalMitigationAction) {
10282 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10283 thermalMitigationResult =
10284 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010285 thermalMitigationRequest.getDataThrottlingRequest(),
10286 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010287 break;
10288 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10289 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10290 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10291 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10292 }
10293
10294 // Ensure that radio is on. If not able to power on due to phone being
10295 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010296 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010297 thermalMitigationResult =
10298 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10299 break;
10300 }
10301
10302 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010303 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010304 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10305 break;
10306 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10307 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10308 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10309 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10310 }
10311
10312 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10313 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010314 Phone phone = getPhone(subId);
10315 if (phone == null) {
10316 thermalMitigationResult =
10317 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10318 break;
10319 }
10320
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010321 TelephonyConnectionService service =
10322 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010323 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010324 Log.e(LOG_TAG, "An emergency call is pending");
10325 thermalMitigationResult =
10326 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10327 break;
10328 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010329 thermalMitigationResult =
10330 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10331 break;
10332 }
10333 } else {
10334 thermalMitigationResult =
10335 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10336 break;
10337 }
10338
10339 // Turn radio off. If not able to power off due to phone being unavailable,
10340 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010341 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010342 thermalMitigationResult =
10343 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10344 break;
10345 }
10346 thermalMitigationResult =
10347 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10348 break;
10349 default:
10350 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10351 + "not exist. Requested action: " + thermalMitigationAction);
10352 }
10353 } catch (IllegalArgumentException e) {
10354 throw e;
10355 } catch (Exception e) {
10356 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10357 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10358 } finally {
10359 Binder.restoreCallingIdentity(identity);
10360 }
10361
10362 if (DBG) {
10363 log("thermalMitigationRequest returning with thermalMitigationResult: "
10364 + thermalMitigationResult);
10365 }
10366
10367 return thermalMitigationResult;
10368 }
Hui Wang641e81c2020-10-12 12:14:23 -070010369
10370 /**
10371 * Set the GbaService Package Name that Telephony will bind to.
10372 *
10373 * @param subId The sim that the GbaService is associated with.
10374 * @param packageName The name of the package to be replaced with.
10375 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10376 */
10377 @Override
10378 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10379 enforceModifyPermission();
10380
10381 final long identity = Binder.clearCallingIdentity();
10382 try {
10383 return getGbaManager(subId).overrideServicePackage(packageName);
10384 } finally {
10385 Binder.restoreCallingIdentity(identity);
10386 }
10387 }
10388
10389 /**
10390 * Return the package name of the currently bound GbaService.
10391 *
10392 * @param subId The sim that the GbaService is associated with.
10393 * @return the package name of the GbaService configuration, null if GBA is not supported.
10394 */
10395 @Override
10396 public String getBoundGbaService(int subId) {
10397 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10398
10399 final long identity = Binder.clearCallingIdentity();
10400 try {
10401 return getGbaManager(subId).getServicePackage();
10402 } finally {
10403 Binder.restoreCallingIdentity(identity);
10404 }
10405 }
10406
10407 /**
10408 * Set the release time for telephony to unbind GbaService.
10409 *
10410 * @param subId The sim that the GbaService is associated with.
10411 * @param interval The release time to unbind GbaService by millisecond.
10412 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10413 */
10414 @Override
10415 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10416 enforceModifyPermission();
10417
10418 final long identity = Binder.clearCallingIdentity();
10419 try {
10420 return getGbaManager(subId).overrideReleaseTime(interval);
10421 } finally {
10422 Binder.restoreCallingIdentity(identity);
10423 }
10424 }
10425
10426 /**
10427 * Return the release time for telephony to unbind GbaService.
10428 *
10429 * @param subId The sim that the GbaService is associated with.
10430 * @return The release time to unbind GbaService by millisecond.
10431 */
10432 @Override
10433 public int getGbaReleaseTime(int subId) {
10434 enforceReadPrivilegedPermission("getGbaReleaseTime");
10435
10436 final long identity = Binder.clearCallingIdentity();
10437 try {
10438 return getGbaManager(subId).getReleaseTime();
10439 } finally {
10440 Binder.restoreCallingIdentity(identity);
10441 }
10442 }
10443
10444 private GbaManager getGbaManager(int subId) {
10445 GbaManager instance = GbaManager.getInstance(subId);
10446 if (instance == null) {
10447 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10448 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10449 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10450 }
10451 return instance;
10452 }
Hui Wang761a6682020-10-31 05:12:53 +000010453
10454 /**
10455 * indicate whether the device and the carrier can support
10456 * RCS VoLTE single registration.
10457 */
10458 @Override
10459 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010460 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10461 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10462 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10463 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010464
10465 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10466 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10467 }
10468
10469 final long identity = Binder.clearCallingIdentity();
10470 try {
10471 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10472 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010473 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10474 if (isCapable != null) {
10475 return isCapable;
10476 }
Hui Wang761a6682020-10-31 05:12:53 +000010477 }
Hui Wang67af90e2021-06-04 16:57:15 -070010478 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10479 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010480 } finally {
10481 Binder.restoreCallingIdentity(identity);
10482 }
10483 }
10484
10485 /**
10486 * Register RCS provisioning callback.
10487 */
10488 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010489 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010490 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010491 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010492 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010493 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10494 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010495
10496 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10497 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10498 }
10499 if (!isImsAvailableOnDevice()) {
10500 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10501 "IMS not available on device.");
10502 }
10503
10504 final long identity = Binder.clearCallingIdentity();
10505 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010506 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010507 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010508 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10509 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010510 }
Hui Wang761a6682020-10-31 05:12:53 +000010511 } finally {
10512 Binder.restoreCallingIdentity(identity);
10513 }
10514 }
10515
10516 /**
10517 * Unregister RCS provisioning callback.
10518 */
10519 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010520 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010521 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010522 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010523 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010524 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10525 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010526
10527 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10528 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10529 }
10530 if (!isImsAvailableOnDevice()) {
10531 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10532 "IMS not available on device.");
10533 }
10534
10535 final long identity = Binder.clearCallingIdentity();
10536 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010537 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010538 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010539 } finally {
10540 Binder.restoreCallingIdentity(identity);
10541 }
10542 }
10543
10544 /**
10545 * trigger RCS reconfiguration.
10546 */
10547 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010548 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10549 "triggerRcsReconfiguration",
10550 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010551
10552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10553 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10554 }
10555 if (!isImsAvailableOnDevice()) {
10556 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10557 "IMS not available on device.");
10558 }
10559
10560 final long identity = Binder.clearCallingIdentity();
10561 try {
10562 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10563 } finally {
10564 Binder.restoreCallingIdentity(identity);
10565 }
10566 }
10567
10568 /**
10569 * Provide the client configuration parameters of the RCS application.
10570 */
10571 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010572 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10573 "setRcsClientConfiguration",
10574 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010575
10576 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10577 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10578 }
10579 if (!isImsAvailableOnDevice()) {
10580 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10581 "IMS not available on device.");
10582 }
10583
10584 final long identity = Binder.clearCallingIdentity();
10585
10586 try {
10587 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10588 if (configBinder == null) {
10589 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010590 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10591 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010592 } else {
10593 configBinder.setRcsClientConfiguration(rcc);
10594 }
joonhunshin3e154242021-09-17 06:33:39 +000010595
10596 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10597 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010598 } catch (RemoteException e) {
10599 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010600 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10601 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010602 } finally {
10603 Binder.restoreCallingIdentity(identity);
10604 }
10605 }
10606
10607 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010608 * Enables or disables the test mode for RCS VoLTE single registration.
10609 */
10610 @Override
10611 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10612 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10613 "setRcsSingleRegistrationTestModeEnabled");
10614
10615 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10616 }
10617
10618 /**
10619 * Gets the test mode for RCS VoLTE single registration.
10620 */
10621 @Override
10622 public boolean getRcsSingleRegistrationTestModeEnabled() {
10623 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10624 "getRcsSingleRegistrationTestModeEnabled");
10625
10626 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10627 }
10628
10629 /**
Hui Wang761a6682020-10-31 05:12:53 +000010630 * Overrides the config of RCS VoLTE single registration enabled for the device.
10631 */
10632 @Override
10633 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10634 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10635 "setDeviceSingleRegistrationEnabledOverride");
10636 enforceModifyPermission();
10637
10638 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10639 : Boolean.parseBoolean(enabledStr);
10640 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010641 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010642 }
10643
10644 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010645 * Sends a device to device communication message. Only usable via shell.
10646 * @param message message to send.
10647 * @param value message value.
10648 */
10649 @Override
10650 public void sendDeviceToDeviceMessage(int message, int value) {
10651 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010652 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010653 enforceModifyPermission();
10654
10655 final long identity = Binder.clearCallingIdentity();
10656 try {
10657 TelephonyConnectionService service =
10658 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10659 if (service == null) {
10660 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10661 return;
10662 }
10663 service.sendTestDeviceToDeviceMessage(message, value);
10664 } finally {
10665 Binder.restoreCallingIdentity(identity);
10666 }
10667 }
10668
Tyler Gunnbabbda02021-02-10 11:05:02 -080010669 /**
10670 * Sets the specified device to device transport active.
10671 * @param transport The transport to set active.
10672 */
10673 @Override
10674 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10675 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10676 "setActiveDeviceToDeviceTransport");
10677 enforceModifyPermission();
10678
10679 final long identity = Binder.clearCallingIdentity();
10680 try {
10681 TelephonyConnectionService service =
10682 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10683 if (service == null) {
10684 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10685 return;
10686 }
10687 service.setActiveDeviceToDeviceTransport(transport);
10688 } finally {
10689 Binder.restoreCallingIdentity(identity);
10690 }
10691 }
Tyler Gunn92479152021-01-20 16:30:10 -080010692
Tyler Gunnd4339262021-05-03 14:46:49 -070010693 @Override
10694 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10695 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10696 "setDeviceToDeviceForceEnabled");
10697
10698 final long identity = Binder.clearCallingIdentity();
10699 try {
10700 Arrays.stream(PhoneFactory.getPhones()).forEach(
10701 p -> {
10702 Phone thePhone = p.getImsPhone();
10703 if (thePhone != null && thePhone instanceof ImsPhone) {
10704 ImsPhone imsPhone = (ImsPhone) thePhone;
10705 CallTracker tracker = imsPhone.getCallTracker();
10706 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10707 ImsPhoneCallTracker imsPhoneCallTracker =
10708 (ImsPhoneCallTracker) tracker;
10709 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10710 }
10711 }
10712 }
10713 );
10714 } finally {
10715 Binder.restoreCallingIdentity(identity);
10716 }
10717 }
10718
Tyler Gunn92479152021-01-20 16:30:10 -080010719 /**
Hui Wang761a6682020-10-31 05:12:53 +000010720 * Gets the config of RCS VoLTE single registration enabled for the device.
10721 */
10722 @Override
10723 public boolean getDeviceSingleRegistrationEnabled() {
10724 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10725 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10726 }
10727
10728 /**
10729 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10730 */
10731 @Override
10732 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10733 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10734 "setCarrierSingleRegistrationEnabledOverride");
10735 enforceModifyPermission();
10736
10737 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10738 : Boolean.parseBoolean(enabledStr);
10739 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10740 subId, enabled);
10741 }
10742
10743 /**
10744 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10745 */
10746 @Override
10747 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10748 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10749 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10750 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010751
10752 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010753 * Overrides the ims feature validation result
10754 */
10755 @Override
10756 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10757 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10758 "setImsFeatureValidationOverride");
10759
10760 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10761 : Boolean.parseBoolean(enabledStr);
10762 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10763 subId, enabled);
10764 }
10765
10766 /**
10767 * Gets the ims feature validation override value
10768 */
10769 @Override
10770 public boolean getImsFeatureValidationOverride(int subId) {
10771 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10772 "getImsFeatureValidationOverride");
10773 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10774 }
10775
10776 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010777 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10778 * their mobile plan.
10779 */
10780 @Override
10781 public String getMobileProvisioningUrl() {
10782 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10783 final long identity = Binder.clearCallingIdentity();
10784 try {
10785 return getDefaultPhone().getMobileProvisioningUrl();
10786 } finally {
10787 Binder.restoreCallingIdentity(identity);
10788 }
10789 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010790
James.cf Linbcdf8b32021-01-14 16:44:13 +080010791 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010792 * Get the EAB contact from the EAB database.
10793 */
10794 @Override
10795 public String getContactFromEab(String contact) {
10796 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10797 enforceModifyPermission();
10798 final long identity = Binder.clearCallingIdentity();
10799 try {
10800 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10801 } finally {
10802 Binder.restoreCallingIdentity(identity);
10803 }
10804 }
10805
10806 /**
Calvin Pana1434322021-07-01 19:27:01 +080010807 * Get the EAB capability from the EAB database.
10808 */
10809 @Override
10810 public String getCapabilityFromEab(String contact) {
10811 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10812 enforceModifyPermission();
10813 final long identity = Binder.clearCallingIdentity();
10814 try {
10815 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10816 } finally {
10817 Binder.restoreCallingIdentity(identity);
10818 }
10819 }
10820
10821 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010822 * Remove the EAB contacts from the EAB database.
10823 */
10824 @Override
10825 public int removeContactFromEab(int subId, String contacts) {
10826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10827 enforceModifyPermission();
10828 final long identity = Binder.clearCallingIdentity();
10829 try {
10830 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10831 } finally {
10832 Binder.restoreCallingIdentity(identity);
10833 }
10834 }
10835
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010836 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010837 public boolean getDeviceUceEnabled() {
10838 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10839 final long identity = Binder.clearCallingIdentity();
10840 try {
10841 return mApp.getDeviceUceEnabled();
10842 } finally {
10843 Binder.restoreCallingIdentity(identity);
10844 }
10845 }
10846
10847 @Override
10848 public void setDeviceUceEnabled(boolean isEnabled) {
10849 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10850 final long identity = Binder.clearCallingIdentity();
10851 try {
10852 mApp.setDeviceUceEnabled(isEnabled);
10853 } finally {
10854 Binder.restoreCallingIdentity(identity);
10855 }
10856 }
10857
Brad Ebinger14d467f2021-02-12 06:18:28 +000010858 /**
10859 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10860 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10861 */
10862 // Used for SHELL command only right now.
10863 @Override
10864 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10865 List<String> featureTags) {
10866 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10867 "addUceRegistrationOverrideShell");
10868 final long identity = Binder.clearCallingIdentity();
10869 try {
10870 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10871 new ArraySet<>(featureTags));
10872 } catch (ImsException e) {
10873 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10874 } finally {
10875 Binder.restoreCallingIdentity(identity);
10876 }
10877 }
10878
10879 /**
10880 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10881 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10882 */
10883 // Used for SHELL command only right now.
10884 @Override
10885 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10886 List<String> featureTags) {
10887 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10888 "removeUceRegistrationOverrideShell");
10889 final long identity = Binder.clearCallingIdentity();
10890 try {
10891 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10892 new ArraySet<>(featureTags));
10893 } catch (ImsException e) {
10894 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10895 } finally {
10896 Binder.restoreCallingIdentity(identity);
10897 }
10898 }
10899
10900 /**
10901 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10902 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10903 */
10904 // Used for SHELL command only right now.
10905 @Override
10906 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10907 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10908 "clearUceRegistrationOverrideShell");
10909 final long identity = Binder.clearCallingIdentity();
10910 try {
10911 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10912 } catch (ImsException e) {
10913 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10914 } finally {
10915 Binder.restoreCallingIdentity(identity);
10916 }
10917 }
10918
10919 /**
10920 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10921 */
10922 // Used for SHELL command only right now.
10923 @Override
10924 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10925 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10926 "getLatestRcsContactUceCapabilityShell");
10927 final long identity = Binder.clearCallingIdentity();
10928 try {
10929 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10930 } catch (ImsException e) {
10931 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10932 } finally {
10933 Binder.restoreCallingIdentity(identity);
10934 }
10935 }
10936
10937 /**
10938 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10939 * device does not have an active PUBLISH.
10940 */
10941 // Used for SHELL command only right now.
10942 @Override
10943 public String getLastUcePidfXmlShell(int subId) {
10944 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10945 final long identity = Binder.clearCallingIdentity();
10946 try {
10947 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10948 } catch (ImsException e) {
10949 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10950 } finally {
10951 Binder.restoreCallingIdentity(identity);
10952 }
10953 }
10954
James.cf Line8713a42021-04-29 16:04:26 +080010955 /**
10956 * Remove UCE requests cannot be sent to the network status.
10957 */
10958 // Used for SHELL command only right now.
10959 @Override
10960 public boolean removeUceRequestDisallowedStatus(int subId) {
10961 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10962 final long identity = Binder.clearCallingIdentity();
10963 try {
10964 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10965 } catch (ImsException e) {
10966 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10967 } finally {
10968 Binder.restoreCallingIdentity(identity);
10969 }
10970 }
10971
James.cf Lin18bb9002021-05-25 01:37:38 +080010972 /**
10973 * Remove UCE requests cannot be sent to the network status.
10974 */
10975 // Used for SHELL command only.
10976 @Override
10977 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10978 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10979 final long identity = Binder.clearCallingIdentity();
10980 try {
10981 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10982 } catch (ImsException e) {
10983 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10984 } finally {
10985 Binder.restoreCallingIdentity(identity);
10986 }
10987 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010988
James.cf Lin4b784aa2021-01-31 03:25:15 +080010989 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010990 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10991 String callingPackage) {
10992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10993 mApp, subId, "setSignalStrengthUpdateRequest");
10994
10995 final int callingUid = Binder.getCallingUid();
10996 // Verify that tha callingPackage belongs to the calling UID
10997 mApp.getSystemService(AppOpsManager.class)
10998 .checkPackage(callingUid, callingPackage);
10999
Rambo Wang3607f502021-02-01 21:51:40 -080011000 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011001
11002 final long identity = Binder.clearCallingIdentity();
11003 try {
11004 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11005 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11006
11007 if (result instanceof IllegalStateException) {
11008 throw (IllegalStateException) result;
11009 }
11010 } finally {
11011 Binder.restoreCallingIdentity(identity);
11012 }
11013 }
11014
11015 @Override
11016 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11017 String callingPackage) {
11018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11019 mApp, subId, "clearSignalStrengthUpdateRequest");
11020
11021 final int callingUid = Binder.getCallingUid();
11022 // Verify that tha callingPackage belongs to the calling UID
11023 mApp.getSystemService(AppOpsManager.class)
11024 .checkPackage(callingUid, callingPackage);
11025
11026 final long identity = Binder.clearCallingIdentity();
11027 try {
11028 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11029 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11030
11031 if (result instanceof IllegalStateException) {
11032 throw (IllegalStateException) result;
11033 }
11034 } finally {
11035 Binder.restoreCallingIdentity(identity);
11036 }
11037 }
11038
Rambo Wang3607f502021-02-01 21:51:40 -080011039 private static void validateSignalStrengthUpdateRequest(Context context,
11040 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011041 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11042 // phone/system process do not have further restriction on request
11043 return;
11044 }
11045
11046 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011047 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011048 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011049 context.enforceCallingOrSelfPermission(
11050 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11051 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011052 }
11053
11054 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11055 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11056 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11057 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11058 || info.isEnabled()) {
11059 throw new IllegalArgumentException(
11060 "Only system can set hide fields in SignalThresholdInfo");
11061 }
11062
11063 // Thresholds length for each RAN need in range. This has been validated in
11064 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11065 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11066 final int[] thresholds = info.getThresholds();
11067 Objects.requireNonNull(thresholds);
11068 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11069 || thresholds.length
11070 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11071 throw new IllegalArgumentException(
11072 "thresholds length is out of range: " + thresholds.length);
11073 }
11074 }
11075 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011076
11077 /**
11078 * Gets the current phone capability.
11079 *
11080 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11081 * @return the PhoneCapability which describes the data connection capability of modem.
11082 * It's used to evaluate possible phone config change, for example from single
11083 * SIM device to multi-SIM device.
11084 */
11085 @Override
11086 public PhoneCapability getPhoneCapability() {
11087 enforceReadPrivilegedPermission("getPhoneCapability");
11088 final long identity = Binder.clearCallingIdentity();
11089 try {
11090 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11091 } finally {
11092 Binder.restoreCallingIdentity(identity);
11093 }
11094 }
Michele Berionne5e411512020-11-13 02:36:59 +000011095
11096 /**
11097 * Prepare TelephonyManager for an unattended reboot. The reboot is
11098 * required to be done shortly after the API is invoked.
11099 */
11100 @Override
11101 @TelephonyManager.PrepareUnattendedRebootResult
11102 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011103 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011104 enforceRebootPermission();
11105
11106 final long identity = Binder.clearCallingIdentity();
11107 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011108 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011109 } finally {
11110 Binder.restoreCallingIdentity(identity);
11111 }
11112 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011113
11114 /**
11115 * Request to get the current slicing configuration including URSP rules and
11116 * NSSAIs (configured, allowed and rejected).
11117 *
11118 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11119 */
11120 @Override
11121 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011122 TelephonyPermissions
11123 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11124 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011125
11126 final long identity = Binder.clearCallingIdentity();
11127 try {
11128 Phone phone = getDefaultPhone();
11129 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11130 } finally {
11131 Binder.restoreCallingIdentity(identity);
11132 }
11133 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011134
11135 /**
11136 * Register an IMS connection state callback
11137 */
11138 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011139 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11140 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011141 if (feature == ImsFeature.FEATURE_MMTEL) {
11142 // ImsMmTelManager
11143 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11144 TelephonyPermissions
11145 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11146 mApp, subId, "registerImsStateCallback");
11147 } else if (feature == ImsFeature.FEATURE_RCS) {
11148 // ImsRcsManager or SipDelegateManager
11149 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11150 Binder.getCallingUid(), "registerImsStateCallback",
11151 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11152 Manifest.permission.READ_PRECISE_PHONE_STATE,
11153 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11154 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11155 }
11156
11157 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11158 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11159 "IMS not available on device.");
11160 }
11161
11162 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11163 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11164 }
11165
11166 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11167 if (controller == null) {
11168 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11169 "IMS not available on device.");
11170 }
11171
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011172 if (callingPackage == null) {
11173 callingPackage = getCurrentPackageName();
11174 }
11175
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011176 final long token = Binder.clearCallingIdentity();
11177 try {
11178 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011179 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011180 } catch (ImsException e) {
11181 throw new ServiceSpecificException(e.getCode());
11182 } finally {
11183 Binder.restoreCallingIdentity(token);
11184 }
11185 }
11186
11187 /**
11188 * Unregister an IMS connection state callback
11189 */
11190 @Override
11191 public void unregisterImsStateCallback(IImsStateCallback cb) {
11192 final long token = Binder.clearCallingIdentity();
11193 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11194 if (controller == null) {
11195 return;
11196 }
11197 try {
11198 controller.unregisterImsStateCallback(cb);
11199 } finally {
11200 Binder.restoreCallingIdentity(token);
11201 }
11202 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011203
11204 /**
11205 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11206 *
11207 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11208 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11209 * SecurityException.
11210 * If there is current registered network this value will be same as the registered cell
11211 * identity. If the device goes out of service the previous cell identity is cached and
11212 * will be returned. If the cache age of the Cell identity is more than 24 hours
11213 * it will be cleared and null will be returned.
11214 *
11215 */
11216 @Override
11217 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11218 String callingFeatureId) {
11219 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11220 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11221 LocationAccessPolicy.checkLocationPermission(mApp,
11222 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11223 .setCallingPackage(callingPackage)
11224 .setCallingFeatureId(callingFeatureId)
11225 .setCallingPid(Binder.getCallingPid())
11226 .setCallingUid(Binder.getCallingUid())
11227 .setMethod("getLastKnownCellIdentity")
11228 .setLogAsInfo(true)
11229 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11230 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11231 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11232 .build());
11233
11234 boolean hasFinePermission =
11235 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11236 if (!hasFinePermission
11237 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11238 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011239 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011240 }
11241
11242 final long identity = Binder.clearCallingIdentity();
11243 try {
11244 Phone phone = getPhone(subId);
11245 if (phone == null) return null;
11246 ServiceStateTracker sst = phone.getServiceStateTracker();
11247 if (sst == null) return null;
11248 return sst.getLastKnownCellIdentity();
11249 } finally {
11250 Binder.restoreCallingIdentity(identity);
11251 }
11252 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011253
11254 @Override
11255 public boolean isUsingNewDataStack() {
11256 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11257 return getDefaultPhone().isUsingNewDataStack();
11258 }
jimsun3b9ccac2021-10-26 15:01:23 +080011259
11260 /**
11261 * Sets the modem service class Name that Telephony will bind to.
11262 *
11263 * @param serviceName The class name of the modem service.
11264 * @return true if the operation is succeed, otherwise false.
11265 */
11266 public boolean setModemService(String serviceName) {
11267 Log.d(LOG_TAG, "setModemService - " + serviceName);
11268 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11270 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11271 "setModemService");
11272 return mPhoneConfigurationManager.setModemService(serviceName);
11273 }
11274
11275 /**
11276 * Return the class name of the currently bounded modem service.
11277 *
11278 * @return the class name of the modem service.
11279 */
11280 public String getModemService() {
11281 String result;
11282 Log.d(LOG_TAG, "getModemService");
11283 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11284 TelephonyPermissions
11285 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11286 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11287 "getModemService");
11288 result = mPhoneConfigurationManager.getModemService();
11289 Log.d(LOG_TAG, "result = " + result);
11290 return result;
11291 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011292
11293 @Override
11294 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11295 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11296 mApp.enforceCallingOrSelfPermission(
11297 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11298 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11299
11300 final long identity = Binder.clearCallingIdentity();
11301 try {
11302 Phone phone = getPhone(subId);
11303 if (phone == null) return;
11304 phone.setVoiceServiceStateOverride(hasService);
11305 } finally {
11306 Binder.restoreCallingIdentity(identity);
11307 }
11308 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011309
11310 /**
11311 * set removable eSIM as default eUICC.
11312 *
11313 * @hide
11314 */
11315 @Override
11316 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11317 enforceModifyPermission();
11318 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11319
11320 final long identity = Binder.clearCallingIdentity();
11321 try {
11322 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11323 } finally {
11324 Binder.restoreCallingIdentity(identity);
11325 }
11326 }
11327
11328 /**
11329 * Returns whether the removable eSIM is default eUICC or not.
11330 *
11331 * @hide
11332 */
11333 @Override
11334 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11335 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11336 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11337
11338 final long identity = Binder.clearCallingIdentity();
11339 try {
11340 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11341 } finally {
11342 Binder.restoreCallingIdentity(identity);
11343 }
11344 }
11345
11346
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011347}